MATLAB Answers

0

How to select the ROI of specific size over the image ?

Parag 님이 질문을 제출함. 28 May 2015
최근 활동 Meshooo 님이 댓글을 추가함. 29 May 2015
Hi
I want to select the ROI of 128 by 128 within the image attached. Using the imrect function we can draw the ROI but I wanted to select constant size of 128 by 128 can you please suggest some method where I can provide the size roi and it will get draw on image. Thank you

  댓글 수: 0

로그인 to comment.

답변 수: 2

Answer by Meshooo on 29 May 2015
Edited by Meshooo on 29 May 2015
 Accepted Answer

Let's say that your image is I. Then using the follow code you will get a 128x128 ROI on your image. You can move and drag the ROI using your mouse. Once it is located at the place you want just double click inside it.
You can also change the values of S to move the ROI.
S = [1 1 128 128]; %the size of your ROI starts at point X1, Y1
I = imread('cameraman.tif'); % your input image
figure, imshow(I);
h = imrect(gca, S);
addNewPositionCallback(h,@(p) title(mat2str(p,3)));
fcn = makeConstrainToRectFcn('imrect',get(gca,'XLim'),get(gca,'YLim'))
setPositionConstraintFcn(h,fcn)
position = wait(h);
I2 = imcrop(I,position);
imshow(I2); % the output image of your ROI
Hope that helps you.
Meshoo

  댓글 수: 2

Thank you so much it works. Can you please explain the use of @ I usually get hard time in understanding. Thanks
That part was not important. I just added it such that you can see the location of your ROI when you start moving it with your mouse. So for example if you start moving your ROI you will see a text appear above to your input image.
If you don't need that, then just use this smaller version of the code.
S = [1 1 128 128]; %the size of your ROI starts at point X1, Y1
I = imread('cameraman.tif'); % your input image
figure, imshow(I);
h = imrect(gca, S);
position = wait(h);
I2 = imcrop(I,position);
imshow(I2); % the output image of your ROI

로그인 to comment.


Answer by Image Analyst
on 28 May 2015

Either rectangle(), plot(), or line() can do that. Be sure you call "hold on" before you draw the box over the image or else the box will blow the image away.

  댓글 수: 0

로그인 to comment.



Translated by