Matlab:掩饰/创建一个知道其原点的圆形roi,具有一定的半径 [英] Matlab: mask/create a circular roi knowing its origin point with a certain radius
问题描述
只是一个简单的问题。我有一个图像,我已经提取了某个点(特征),我知道每个帧中该点的坐标。
Just a quick question. I've an image and I've extracted a certain point (feature), I know the coordinates of that point in every frame.
说x1和y1。
我需要一个圆形ROI表格,指向图像上我选择的半径。
I need a circular ROI form that point on the image with a radius that I chose.
我尝试了impoly和roipoly - 当我知道图像中的点时,不知道如何使用其中任何一个。
I tried impoly and roipoly - not sure how to use either of these when I know the point in the image.
谢谢
推荐答案
由于您知道ROI中心的坐标以及半径,您可以修改一下@Jonas提供的代码此处以非常有效的方式创建圆形蒙版。
Since you know the coordinates of the center of the ROI along with the radius, you can modify a bit the code provided by @Jonas here to create a circular mask in a quite efficient way.
示例:
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的外边缘以查看中心,请添加一个具有一定容差的逻辑条件对于较小圆的半径。这样的事情:
If you want to see only the outer edge of the ROI to see the center, add a logical condition with some tolerance for the radius of a smaller circle. Something like this:
mask = (xx.^2 + yy.^2)<radius^2 & (xx.^2 + yy.^2)>(radius-tol)^2;
如果 tol
为2,它看起来像这个:
With a tol
of 2 it looks like this:
这篇关于Matlab:掩饰/创建一个知道其原点的圆形roi,具有一定的半径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!