crop circle region from image

5 次查看(过去 30 天)
khaleed james
khaleed james 2016-3-1
hi, im currently doing a iris recognition. im now in a segmentation process. ive already detect the the pupil region but how can i remove the background and leave only the pupil region?
  1 个评论
AKHILA P
AKHILA P 2018-9-2
how you do the pupil region detection? please help me i am also doing iris recognition

请先登录,再进行评论。

回答(1 个)

KSSV
KSSV 2018-1-8
This code shall work for you. When prompted/ figure opens, you need two click twice.
1. First click, click at the center of the circle, where you want to draw a circle.
2. Second click, click at any point which is at a distance of radius of circle you wanted to draw.
I = imread('Capture111.jpg');
[nx,ny,d] = size(I) ;
[X,Y] = meshgrid(1:ny,1:nx) ;
imshow(I) ;
hold on
[px,py] = getpts ; % click at the center and approximate Radius
r = sqrt(diff(px).^2+diff(py).^2) ;
th = linspace(0,2*pi) ;
xc = px(1)+r*cos(th) ;
yc = py(1)+r*sin(th) ;
plot(xc,yc,'r') ;
% Keep only points lying inside circle
idx = inpolygon(X(:),Y(:),xc',yc) ;
for i = 1:d
I1 = I(:,:,i) ;
I1(~idx) = 255 ;
I(:,:,i) = I1 ;
end
figure
imshow(I)
I am attaching the result, I got on running the above code:
  4 个评论
Sruthi Radhakrishnan
Thank you for the code, But how to eliminate the white background in the image ?
Gustavo Deza
Gustavo Deza 2019-12-6
If I multiple circle I want to extract, and have a variable with the values of the centers and radii, how can I make a loop to extract all the circles?
for i_1 = 1:size(centers)
px = centers(i_1,1);
py = centers(i_1,2);
r = radii(i_1) ;
th = linspace(0,2*pi) ;
xc = px(i_1)+r(i_1)*cos(th) ;
yc = py(i_1)+r(i_1)*sin(th) ;
%plot(xc,yc,'r') ;
% Keep only points lying inside circle
idx = inpolygon(X(:),Y(:),xc',yc) ;
for j = 1:d
I1 = f_gray(:,:,j) ;
I1(~idx) = 255 ;
I(:,:,j) = I1 ;
end
end
I get this error: "Index exceeds the number of array elements (1)."

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by