Hi Tushar
1. acquiring image
A=imread('001.jpg');
h1=figure(1);imshow(A)
ax=gca
2.
even the object of interest has low illumination, so the binarization threshold set low, at 12 only:
A1=A(:,:,1);
A1(A1>10)=255;A1(A1<12)=0;
figure;imshow(A1)
3.-
Getting boundaries of all the objects
[B,L]=bwboundaries(A1);
perim=[];
for k=1:1:size(B,1)
perim=[perim size(B{k,:},1)];
end
4.-
Capturing the object of interest, because it has by far the longest perimeter:
B1_cell=B(find(perim==max(perim)),:);
B1=B1_cell{:};
hold(ax,'all');
plot(ax,B1(:,2),B1(:,1),'r','LineWidth',2)
5.-
the length of the perimeter, in pixels
Obj_perim_length=size(B1,1)
6.- now for the area
xp=B1(:,2);
yp=B1(:,1);
D=zeros(size(A1));
for k=1:1:numel(xp)
D(yp(k),xp(k))=1;
end
D2=imfill(D,'holes')
figure;imshow(D2)
obj_area =
5.207962500000000e+04
obj_area/(size(A1,1)*size(A1,2)) =
0.259624444156414
the area is of 52k pixels, about a quarter of the input image rectangle, if one can accurately get a scale of the window, then translation from pixels to mm, cm, microns, whatever .. is straight forward.
f you find this answer useful would you please be so kind to consider marking my answer as Accepted Answer?
To any other reader, if you find this answer useful please consider clicking on the thumbs-up vote link
thanks in advance for time and attention
John BG
.
.
.
.
additional comments:
What I tried but either time consuming or more complex than the above solution:
1. inpolygon with all points of the initial image against the found perimeter:
[in,on]=inpolygon(yq,xq,B1(:,2),B1(:,1));
in1=find(in>0);
for k=1:1:length(in)
plot(ax,xq(in1(k)),yq(in1(k)),'b*');
end
2. Define an alphashape and then apply command area
shp1=alphaShape(B1(:,2),B1(:,1))
figure;plot(shp1)
area_obj1=area(shp1)
area_obj1/(size(A1,1)*size(A1,2))
too sketchy without filtering first, that it's been already done above
3.
A2=del2(double(A1));figure;imshow(A2)
Laplacian gets the correct perimeter, but along with many other 'false' perimeters, thus requiring filtering before applying del2.