How to crop automatically the interested region of an image?

1 vue (au cours des 30 derniers jours)
mah taj
mah taj le 21 Nov 2015
Commenté : Image Analyst le 28 Avr 2022
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.

Réponse acceptée

Image Analyst
Image Analyst le 21 Nov 2015
Modifié(e) : Image Analyst le 21 Nov 2015
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 commentaires
Image Analyst
Image Analyst le 22 Nov 2015
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.

Connectez-vous pour commenter.

Plus de réponses (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
  1 commentaire
Image Analyst
Image Analyst le 28 Avr 2022
Use drawpolygon() and save(). I'm sure there's an example in the documentation for it.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by