我有一张图像,我想裁剪一个点周围的圆形感兴趣区域。我在 MATLAB 中做了以下操作:
vessel=imread('vessel.jpg');
imshow( vessel)
t = 0:pi/20:2*pi;
xc=230; % point around which I want to extract/crop image
yc=79;
r=20; %Radium of circular region of interest
xcc = r*cos(t)+xc;
ycc = r*sin(t)+yc;
roimaskcc = poly2mask(double(xcc),double(ycc), size(vessel,1),size(vessel,2));
pr_gccc = find(roimaskcc);
roimean_cc= mean(vessel(pr_gccc));
figure, imshow(roimaskcc)
roimaskcc 是正确的,但是当我执行以下操作时,它会给出 nX1 矩阵,但不会给出掩模下的感兴趣区域:
vessel_undermask=vessel(roimaskcc==1);
有人可以吗?帮助提取兴趣点 (xc, yc) 周围的圆形兴趣区域。
谢谢
你正在做的是从中提取一切vessel
那是在面具之外。由于不存在循环矩阵这样的东西,Matlab的解决方案是输出一个vector掩码内的所有值。
虽然这在技术上是正确的,但该向量可能很难使用。另一种解决方案是保留数据矩阵为正方形,并将掩码之外的所有内容设置为NaN
:
% make a copy
vessel_undermask = vessel;
% NaN everything outside the mask (in R, G and B layers)
vessel_undermask(repmat(~roimaskcc,[1,1,3])) = NaN;
imshow(vessel_undermask)
这应该会给你一个更容易使用的矩阵。
注意
vessel_undermask(~isnan(vessel_undermask)) == vessel(roimaskcc)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)