MATLAB: how do I crop out a circle from an image

Leo*_*eis 8 matlab crop image-processing

I need to crop a circle in MATLAB.

I need to perform iris segmentation, and I´ve identified the center point and the radius of the iris, and I need to cut it off from the image.

I have a vector ci that ci(1) is X-coordinate ci(2) is Y-coordinate and ci(3) is the radius of the circle.

Jon*_*nas 10

一种方法是创建一个二进制掩码,其中包含圆圈内的一个和外部的零.然后,您可以使用此数组使用NaN屏蔽圆外的所有内容,或者读取蒙版内图像的像素值.

要创建圆形蒙版,一种简单的方法是创建以光圈为中心的坐标数组,并对距离进行阈值处理,如下所示:

[xx,yy] = ndgrid((1:imageSize(1))-ci(1),(1:imageSize(2))-ci(2));
mask = (xx.^2 + yy.^2)<ci(3)^2;
Run Code Online (Sandbox Code Playgroud)