Matlab: mask/create 一个已知其原点具有一定半径的圆形roi

Matlab: mask/create a circular roi knowing its origin point with a certain radius

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

说 x1 和 y1。

我需要一个圆形的 ROI 形式,它以我选择的半径指向图像。

我尝试了 impoly 和 roipoly - 当我知道图像中的点时不确定如何使用它们。

谢谢

由于您知道 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)

输出:

编辑

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

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

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