crop circle region from image
Afficher commentaires plus anciens

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 commentaire
AKHILA P
le 2 Sep 2018
how you do the pupil region detection? please help me i am also doing iris recognition
Réponses (1)
KSSV
le 8 Jan 2018
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 commentaires
KSSV
le 8 Jan 2018
Then how do you think, I got the attached image?
Matthew Burges
le 9 Jan 2018
how to do this without selecting the center and radius, meaning matlab should do this step on its own.
Sruthi Radhakrishnan
le 29 Juin 2018
Thank you for the code, But how to eliminate the white background in the image ?
Gustavo Deza
le 6 Déc 2019
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)."
Catégories
En savoir plus sur Image Segmentation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!