function [greaterdims,lesserdims,eccentricities,distances]=vesicle_image_data(ves_measurements,assess_clusteriness)
%description: takes input array generated from manual analysis of EM images of vesicle aggregates performed in imageJ
%called by: command line
%calls hypotenuse_length
%notes:
%code confirmed date:

ves_diameters=ves_measurements(:,end) %each vesicle is manually measured with two diameters, a maximal one and one ~orthogonal to that -- with circular vesicles it is hard to tell which is longer
ves_diameters=reshape(ves_diameters,2,[])
num_vesicles=size(ves_diameters,2)

xy_data=ves_measurements(:,1:2)     %first column is x, second column is y, for each diameter line;  thus each pair of rows describes one vesicle

%determine for each vesicle which diameter is greatest
greaterdims=nan(1,num_vesicles);lesserdims=nan(1,num_vesicles);
for i=1:num_vesicles
    if ves_diameters(1,i)>=ves_diameters(2,i)
        greaterdims(i)=ves_diameters(1,i);
        lesserdims(i)=ves_diameters(2,i);
    elseif ves_diameters(1,i)<ves_diameters(2,i)
        greaterdims(i)=ves_diameters(2,i);
        lesserdims(i)=ves_diameters(1,i);
    end
end

%find eccentricities
eccentricities=greaterdims./lesserdims

if assess_clusteriness
    %find clusteriness
    %average the y values and the x values from the two measurement bars used on each vesicle to produce a single x and a single y value for each vesicle
    mean_ves_locations=[];
    for m=1:2:size(xy_data,1)
        x=(xy_data(m,1)+xy_data(m+1,1))/2;
        y=(xy_data(m,2)+xy_data(m+1,2))/2;
        mean_ves_locations=[mean_ves_locations;[x,y]]
    end

    %compute all intervesicle distances: from the first to all others, from the second to all others except the first (as that's already calculated),...
    %find the average intervesicle distance for that cluster of vesicles
    num_distances=sum([1:(num_vesicles-1)])
    distances=nan(1,num_distances);
    adder=(num_vesicles-1):-1:1;

    for j=1:num_vesicles-1
        vesA=mean_ves_locations(j,:);
        adds=sum(adder(1:(j-1)));
        for k=(j+1):num_vesicles
            vesB=mean_ves_locations(k,:);
            c=hypotenuse_length(vesB(1)-vesA(1),vesB(2)-vesA(2));
            distances(adds+k-j)=c
        end
    end
else
    distances=[];
end