How to select the ROI of specific size over the image ?
Show older comments
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
Accepted Answer
More Answers (2)
Image Analyst
on 28 May 2015
0 votes
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.
Jonas Thomalla
on 11 Nov 2020
With the newer roi-commands it also can look like this:
height = 128;
width = height;
imshow(image)
roi = images.roi.Rectangle(gca,'Position',[1,1,width,height],'FixedAspectRatio',true,'InteractionsAllowed','translate');
roi = customWait(roi);
function oROI = customWait(hROI)
%from function customWait https://www.mathworks.com/help/images/use-wait-function-after-drawing-roi-example.html
% Listen for mouse clicks on the ROI
l = addlistener(hROI,'ROIClicked',@clickCallback);
% Block program execution
uiwait;
% Remove listener
delete(l);
% Return the current roi
oROI = hROI;
end
function clickCallback(~,evt)
if strcmp(evt.SelectionType,'double')
uiresume;
end
end
Hope this helps anyone because I was searching for a solution for a few days.
Categories
Find more on ROI-Based Processing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!