%Read and display image I=imread('pillsetc.png'); imshow(I); %Convert to grayscale I=rgb2gray(I); %Find Otsu threshold lev=graythresh(I); bw=im2bw(I,lev); %Flood fill all holes bw = imfill(bw,'holes'); imshow(bw); %Label 8-connected regions [L,num]=bwlabel(bw,8); imagesc(L); colormap hsv %Find region centroids, bounding rectangle image and eccentricity s=regionprops(L,'Centroid','Image','Eccentricity'); %Create a list of eccentricity ecc=cat(1,s.Eccentricity); %Though regionprops knows how to measure area in pixels, we do it the silly way ar=zeros(1,num); for i=1:num ar(i)=nnz(s(i).Image) end