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

后端 未结 1 669
醉梦人生
醉梦人生 2020-12-10 15:09

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 fro

相关标签:
1条回答
  • 2020-12-10 15:46

    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;
    
    0 讨论(0)
提交回复
热议问题