How to crop automatically the interested region of an image?

1 次查看(过去 30 天)
hi. i need to automatically crop the interested region of the image. The images are the scanned MRI images. i want to segmentation prostate and i need to remove other organs .i want to use level set method . plz help me to solve this project.

采纳的回答

Image Analyst
Image Analyst 2015-11-21
编辑:Image Analyst 2015-11-21
We have no idea what in that thing you want to segment out. So go here, find an algorithm, and code it up. If you still have questions, read this then come back.
Also see my Image Segmentation Tutorial where I "automatically" crop out things: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
  3 个评论
Image Analyst
Image Analyst 2015-11-22
If you want a box, you can use imrect() or rbbox(). Here is code for rbbox():
k = waitforbuttonpress;
point1 = get(gca,'CurrentPoint'); % button down detected
finalRect = rbbox; % return figure units
point2 = get(gca,'CurrentPoint'); % button up detected
point1 = point1(1,1:2); % extract x and y
point2 = point2(1,1:2);
p1 = min(point1,point2); % calculate locations
offset = abs(point1-point2); % and dimensions
% Find the coordinates of the box.
xCoords = [p1(1) p1(1)+offset(1) p1(1)+offset(1) p1(1) p1(1)];
yCoords = [p1(2) p1(2) p1(2)+offset(2) p1(2)+offset(2) p1(2)];
x1 = round(xCoords(1));
x2 = round(xCoords(2));
y1 = round(yCoords(5));
y2 = round(yCoords(3));
hold on
axis manual
plot(xCoords, yCoords, 'b-'); % redraw in dataspace units
% Display the cropped image.
croppedImage = grayImage(y1:y2,x1:x2);
imshow(croppedImage);
axis on;
title('Region that you defined', 'FontSize', fontSize);
And here's the snippet for imrect():
hBox = imrect;
roiPosition = wait(hBox);
roiPosition % Echo coordinates to the command window.
xCoords = [roiPosition(1), roiPosition(1)+roiPosition(3), roiPosition(1)+roiPosition(3), roiPosition(1), roiPosition(1)];
yCoords = [roiPosition(2), roiPosition(2), roiPosition(2)+roiPosition(4), roiPosition(2)+roiPosition(4), roiPosition(2)];
% Plot the mask as an outline over the image.
hold on;
plot(xCoords, yCoords, 'linewidth', 2);
Both will let you draw a box that you can then use in imcrop(). You manually draw the box for both. If you need an irregular shaped region, I think even a human would have difficulty deciding the exact rows and columns to draw the box so it would be difficult to have the computer do it. For that you'll have to look at some of those papers in the link I gave you.

请先登录,再进行评论。

更多回答(1 个)

Khalladi Sofiane abdelkrim
Hi , i have a folder of images containing the same road but different frames i want to extract just a specified Region of interest in forme of polygon and save it in another file . How i can implémenté that please ?
Thanks

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by