使用预定义的ROI Matlab进行图像裁剪 [英] Image Cropping using Predefined ROI Matlab

查看:636
本文介绍了使用预定义的ROI Matlab进行图像裁剪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我正在尝试做的是使用预定义的ROI来裁剪和成像到多个新图像。

Basically what I'm trying to do is using predefined ROI's to crop and image into multiple new images.

更长的是我有一张大脑地图,它的部分定义。使用它我使用imfreehand或roipoly在MATLAB中定义了许多ROI。从那里我已经染色了这些部分的幻灯片。我想使用我从地图中定义的ROI将真实大脑的图像裁剪成许多新图像。

Longer is that I have a map of brain, with sections of it defined. using that I define many ROI's from it in MATLAB using imfreehand or roipoly. From there I have stained slides of these sections. I want to use the ROI's that I defined from the map to crop the image of the real brain into many new images.

只是找不到使用ROI的东西裁剪区域,而不仅仅是一些矩形。

Just having trouble finding something that uses the ROI's as the cropping area and not just some rectangle.

如果我需要解释一下,请告诉我。

If I need to explain a bit more let me know.

推荐答案

我想你想要的简单例子 imfreehand

Simple example of what I think you want using imfreehand:

I = imread('pout.tif');
imshow(I);
h = imfreehand; % now pick ROI

BW = createMask(h); % get BW mask for that ROI
pos = getPosition(h); % 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);

如果您已经以某种方式保存了ROI,并且不想运行 imfreehand 再次,您真正需要的是计算 BW (一个掩码,其中包含ROI中的一个和其他地方的零)和边界框(在ROI周围紧缩)。

If you have the ROI's already saved in some way, and don't want to run imfreehand again, all you really need is to calculate BW (a mask with ones within the ROI and zeros elsewhere) and the bounding box (to crop tight around the ROI).

这篇关于使用预定义的ROI Matlab进行图像裁剪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆