Circularity Metric using regionprops

23 visualizaciones (últimos 30 días)
Jason
Jason el 18 de En. de 2023
Comentada: Jason el 2 de Nov. de 2023
Hello, this is a related to an earlier question but Im after a different parameter so I have asked another question. Apologies if I should have contrinued on the previous question. Here goes!
I have an image of a bubble (the dark area in the 1st image) and not only do I want to estimate its diameter, but also its circularity. I have used I.A's suggestions as well as the fact that a common metric for circularity is Perimeter^2 / 4pi*Area = 1 for a circle.
However, I'd like to explore another metric that looks interesting. Its the difference betweent he largest and smallest circle
However for once I have no idea where to start! (sorry, I know we should attempt ourself first, but I am stuck on this one)
(note that sometimes inside the water drop (i.e. the dark area) there can be bright spots), these need to be ignored) - its the edge of the dark ara that I want to quantify
Thanks
  1 comentario
Jason
Jason el 18 de En. de 2023
Editada: Jason el 18 de En. de 2023
The last image is obtained by bwboundaries. Im guessing this could be used. I see the output B is the x,y locations of the perimeter - perhaps a centroid could be calculated and then some how the max and min distance from this centroid? This is what I've managed to do, not sure if its correct or the best way - it does look right
[B,L] = bwboundaries(bw2,'noholes');
disp('Boundaries')
B
BB=B{1} ;
X=BB(:,1); Y=BB(:,2);
figure
plot(X,Y,'k-','Linewidth',3);
%try and get centroids of these X,Y locations (of the perimeter)
hold on
plot(mean(X(:)),mean(Y(:)),'r+'); axis equal; grid on;
%hold off
%now calc distance of each point from the centroid
data=[];
cenX=mean(X(:)); cenY=mean(Y(:));
for i=1:length(BB)
X=BB(i,1); Y=BB(i,2);
data(i,1)=X; data(i,1)=Y;
R=sqrt((X-cenX)^2+(Y-cenY)^2)
data(i,3)=R;
end
R1=max(data(:,3))
R2=min(data(:,3))
viscircles([cenX, cenY], R1, 'Color', 'b','Linewidth',1);
viscircles([cenX, cenY], R2, 'Color', 'r','Linewidth',1); hold off;

Iniciar sesión para comentar.

Respuestas (1)

Supraja
Supraja el 2 de Jun. de 2023
I understand that you want to find the circularity of the image.
You can try the following code:
% Load the image and convert to grayscale
img = imread('myimage.jpg');
gray = rgb2gray(img);
% Apply a threshold
threshold = graythresh(gray);
bw = imbinarize(gray, threshold);
% Label and calculate properties of the connected regions
labeled = bwlabel(bw);
props = regionprops(labeled, 'Area', 'Perimeter');
% Calculate circularity and display the output
area = props.Area;
perimeter = props.Perimeter;
circularity = (perimeter^2)/(4*pi*area);
disp(['Circularity: ', num2str(circularity)]);
Hope this helps!
  1 comentario
Jason
Jason el 2 de Nov. de 2023
Thanks for your answer, but in my question I had put I dont want to use this as its not that sensitive "common metric for circularity is Perimeter^2 / 4pi*Area = 1 for a circle"

Iniciar sesión para comentar.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by