Domanda

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

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.

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.

È stato utile?

Soluzione

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);

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).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top