I = imread('test.jpg');
I = rgb2gray(I);
I = im2bw(I);
se1 = strel('disk',5);
I1 = imerode(I,se1);
I2 = imdilate(I1,se1);
I3 = ones(size(I2))-I2;
L = bwlabel(I3);
STATS = regionprops(L,'BoundingBox');
imshow(I2);hold on;
for i = 1:size(STATS,1)
rectangle('Position',STATS(i).BoundingBox,'EdgeColor','g');
end
str1 = sprintf('W=%4.1f,H=%4.1f',STATS(1).BoundingBox(3),STATS(1).BoundingBox(4));
str2 = sprintf('D=%4.1f',STATS(2).BoundingBox(3));
text(10,10,str1);
text(290,280,str2);