# How do I quantify this image based on area and perimeter?

조회 수: 37(최근 30일)
tgohsu 2018년 4월 7일
댓글: Md. Faiyaz Jamil 2021년 12월 7일
So I have this image: And I would like to quantify it by area and perimeter. The large object is the particle of interest, everything else is an artifact and can be disregarded. How would I go about doing this?
Thanks for your time.

댓글을 달려면 로그인하십시오.

### 채택된 답변

John BG 2018년 4월 7일
Hi Tushar
1. acquiring image
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=imbinarize(A,10);
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) % perimeter length in pixels
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
% figure;imshow(D);axd=gca;
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
.
.
.
.
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:
% too time consuming, it almost crashes MATLAB twice
[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
% alphasape awkwardly defines the shapes along the perimeter
% leaving almost all inside hollow, therefore the resulting area is almost that of a thin perimeter strip, not of the whole inside
shp1=alphaShape(B1(:,2),B1(:,1))
figure;plot(shp1)
area_obj1=area(shp1)
area_obj1/(size(A1,1)*size(A1,2))
% hold all
% for k = 1:length(B)
% boundary = B{k};
% plot(boundary(:,2), boundary(:,1),'r', 'LineWidth', 2)
% end
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.
##### 댓글 수: 1표시숨기기 없음
Md. Faiyaz Jamil 2021년 12월 7일
How did you get the object area 5.207962500000000e+04??

댓글을 달려면 로그인하십시오.

### 추가 답변(1개)

tgohsu 2018년 4월 8일
편집: tgohsu 2018년 4월 8일
John
Thanks for taking the time to do this.
##### 댓글 수: 1표시숨기기 없음
John BG 2018년 4월 8일
for my friend Tushar, any time, happy to help.

댓글을 달려면 로그인하십시오.

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!