问题描述
我需要在MATLAB中裁剪一个圆圈。
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.
我有一个向量ci,ci(1)是X坐标ci(2)是Y坐标和ci( 3)是圆的半径。
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.
推荐答案
这样做的一种方法是创建一个二进制掩码,其中包含圆圈内的一个和外面的零。然后,您可以使用此数组使用NaN遮罩圆外的所有内容,或者读取遮罩内图像的像素值。
One way to do this is to create a binary mask with ones inside the circle and zeros outside. You can then use this array to either mask everything outside the circle with NaNs, or to read the pixel values of the image inside the mask.
要创建圆形遮罩,一种简单的方法是创建以虹膜为中心的坐标数组,并设置距离阈值,如下所示:
To create a circle mask, an easy way is to create coordinate arrays centered on the iris, and threshold the distance, like this:
[xx,yy] = ndgrid((1:imageSize(1))-ci(1),(1:imageSize(2))-ci(2));
mask = (xx.^2 + yy.^2)<ci(3)^2;
这篇关于MATLAB:如何从图像中裁剪出圆圈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!