How to get a uniform circle?

조회 수: 6 (최근 30일)
Christine Ak
Christine Ak 2013년 12월 25일
댓글: Image Analyst 2013년 12월 26일
Hi I have the following Image of a circle I want to make its edges uniform can any body help ??

채택된 답변

Youssef  Khmou
Youssef Khmou 2013년 12월 25일
편집: Youssef Khmou 2013년 12월 25일
hi,
i tired to write a fast code, try it and see :
I=imread('dcircle.png'); % that image with deformed circle.
X=rgb2gray(I);
N=size(X);
% finding an approximation of the center
% you take where you want start counting
xc=100;
n=0; % number of black pixels vertically descending
for y=1:N(2)
if X(xc,y)>0.70;
n=n+1;
end
end
% the center is then given by :
r=n/4;
yc=N(2)/2;
Y=zeros(N(1),N(2));
for x=1:N(1)
for y=1:N(2)
rt=sqrt(((x-xc)^2)+((y-yc)^2));
if rt>=r
Y(x,y)=1;
end
end
end
figure,subplot(1,2,1), imshow(X),title(' initial');
subplot(1,2,2), imshow(Y), title(' adjusted');
  댓글 수: 2
Christine Ak
Christine Ak 2013년 12월 26일
Thank U Soo Much ,, it was helpful :D
Image Analyst
Image Analyst 2013년 12월 26일
In the FAQ, the vectorized approach to drawing a circle is shown: http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3F. You might want to use that, or at least learn how to do it.

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

추가 답변 (1개)

Image Analyst
Image Analyst 2013년 12월 25일
편집: Image Analyst 2013년 12월 25일
Get the area and the Equivalent Circular Diameter of the black spot with regionprops. Then use the FAQ or rectangle() to draw a perfect circle.
binaryImage = grayImage < 128;
measurements = regionprops(binaryImage, 'Centroid', 'EquivDiameter');
centroid = [measurements.Centroid]
diameter = measurements.EquivDiameter
% Draw circle in the overlay.
rectangle('Position',[centroid(1)-diameter/2,centroid(2)-diameter/2,diameter, diameter],...
'Curvature',[1,1],'LineWIdth', 2, 'EdgeColor', 'r');
Attached is the full blown demo. Let me know of any difficulties.

Community Treasure Hunt

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

Start Hunting!

Translated by