matlab - 使用drawfreehand绘制感兴趣区域后如何裁剪图像?
问题描述
我有一张图像,我想根据 ROI 裁剪它。 https://imgur.com/rsoCXsf
我使用 drawfreehand 函数来绘制感兴趣区域(ROI)。我想裁剪 ROI 下的区域并将其保存在不同的文件中。
I = imread('Intensity1.jpg');
imshow(I);
h = drawfreehand; % now pick ROI
BW = createMask(h); % get BW mask for that ROI
pos = images.roi.Freehand(); % get position for that ROI
% define bounding box
x1 = round(min(pos(:,2)));
y1 = round(min(pos(:,1)));
x2 = round(max(pos(:,2)));
y2 = round(max(pos(:,1)));
I2 = I.*uint8(BW); % apply mask to image
I2 = I2(x1:x2,y1:y2);
figure;
subplot(1,2,1);
imshow(I);
subplot(1,2,2);
imshow(I2);
I3 = imcrop(I2);
imshow(I3)
显示以下错误消息。
类 'images.roi.Freehand' 的方法、属性或字段 'roi' 无法识别。
fh4 错误(第 6 行) pos = images.roi.Freehand(); % 获得该投资回报率的位置
解决方案
请注意,如果提出这样的问题,最好将图像文件的加载替换为每个人都可以使用的功能
ROI 的坐标存储在由Position
返回的对象的属性中drawfreehand
:
imagesc(peaks(128))
h = drawfreehand;
pos = h.Position
更新:这是使用您的图像的完整示例:
I = imread('https://i.imgur.com/rsoCXsf.jpg');
f = figure();
imshow(I);
roi = drawfreehand();
mask = uint8(roi.createMask());
I2 = I .* mask; % apply mask
f2 = figure();
subplot(1,2,1);
image(I2);
% get BB
pos = roi.Position;
x1 = round(min(pos(:,2)));
y1 = round(min(pos(:,1)));
x2 = round(max(pos(:,2)));
y2 = round(max(pos(:,1)));
Icropped = I2(x1:x2, y1:y2, :);
subplot(1,2,2);
image(Icropped);
推荐阅读
- html - Vue.js - 从模态获取数据并保存到数组
- r - R中的循环和ggplots以及数据框的列
- python - 替换熊猫数据帧上的第二组正则表达式匹配
- android - 如何集成 D-Pad 焦点导航?
- python - 尝试使用发送消息 API 端点时出现 405 错误
- c# - 在运行时编译期间收到“您必须添加对程序集 'netstandard' 的引用”错误
- javascript - Route.connect() 需要一个回调函数,但得到一个 [object Object]
- react-native - 嵌套时不显示 React Navigation v5 BottomTabNavigator
- installation - Beagle bone IP 地址未打开
- javascript - 与 Django 反应:内部服务器错误 500