Matlab:掩饰/创建一个知道其原点与一定半径的圆形roi

时间:2015-07-13 12:31:20

标签: matlab image-processing

只是一个简单的问题。我有一个图像,我已经提取了某个点(特征),我知道每个帧中该点的坐标。

说x1和y1。

我需要一个圆形ROI表单,指向图像上我选择的半径。

我尝试了impoly和roipoly - 当我知道图像中的点时,不确定如何使用其中任何一个。

由于

1 个答案:

答案 0 :(得分:6)

由于您知道ROI中心的坐标以及半径,因此您可以修改@Jonas here提供的代码,以非常有效的方式创建圆形蒙版。

示例:

clc;clear

Im = imread('coins.png');

[rNum,cNum,~] = size(Im);

%// Define coordinates and radius
x1 = 60;
y1 = 100;
radius = 40;

%// Generate grid with binary mask representing the circle. Credit to Jonas for original code.
[xx,yy] = ndgrid((1:rNum)-y1,(1:cNum)-x1);
mask = (xx.^2 + yy.^2)<radius^2;

%// Mask the original image
Im(mask) = uint8(0);

imshow(Im)

输出:

enter image description here

修改

如果您只想查看ROI的外边缘以查看中心,请添加一个逻辑条件,对较小圆的半径有一定的容差。像这样:

mask = (xx.^2 + yy.^2)<radius^2 & (xx.^2 + yy.^2)>(radius-tol)^2;

tol为2时,它看起来像这样:

enter image description here