crop circle region from image

5 views (last 30 days)
khaleed james
khaleed james on 1 Mar 2016
Commented: Gustavo Deza on 6 Dec 2019
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 Comment
AKHILA P
AKHILA P on 2 Sep 2018
how you do the pupil region detection? please help me i am also doing iris recognition

Sign in to comment.

Answers (1)

KSSV
KSSV on 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 Comments
Sruthi Radhakrishnan
Sruthi Radhakrishnan on 29 Jun 2018
Thank you for the code, But how to eliminate the white background in the image ?
Gustavo Deza
Gustavo Deza on 6 Dec 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)."

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!