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

血红的双手。 提交于 2019-12-17 19:44:03

问题


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.


回答1:


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;


来源:https://stackoverflow.com/questions/4651778/matlab-how-do-i-crop-out-a-circle-from-an-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!