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

4 vues (au cours des 30 derniers jours)
tgohsu
tgohsu le 7 Avr 2018
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.

Réponse acceptée

John BG
John BG le 7 Avr 2018
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=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
.
.
.
.
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:
% 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 commentaire
Md. Faiyaz Jamil
Md. Faiyaz Jamil le 7 Déc 2021
How did you get the object area 5.207962500000000e+04??

Connectez-vous pour commenter.

Plus de réponses (1)

tgohsu
tgohsu le 8 Avr 2018
Modifié(e) : tgohsu le 8 Avr 2018
John
Thanks for taking the time to do this.
  1 commentaire
John BG
John BG le 8 Avr 2018
for my friend Tushar, any time, happy to help.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Image Segmentation and Analysis dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by