# Circularity Metric using regionprops

조회 수: 18 (최근 30일)
Jason 2023년 1월 18일
댓글: Jason 2023년 11월 2일
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이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Jason 2023년 1월 18일
편집: Jason 2023년 1월 18일
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;

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

### 답변 (1개)

Supraja 2023년 6월 2일
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
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이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Jason 2023년 11월 2일
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"

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

### 카테고리

Help CenterFile Exchange에서 Region and Image Properties에 대해 자세히 알아보기

R2022b

### Community Treasure Hunt

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

Start Hunting!

Translated by