MATLAB: Hi, I am using Matlab version 7.9.0(R2009b). I need to select a rectangular region of interest for the tif image. I tried imrect but the rectangular appeared on an empty coordinat system, not in the tif image. Could you please help me on this

Image Processing Toolboxroi

mathworks

Best Answer

Try this:
txtInfo = sprintf('Draw a box over the image by clicking and dragging over the image.\nDouble click inside the box to finish drawing.');
text(10, 40, txtInfo, 'color', 'r', 'FontSize', 24);
% Prompt user to draw a region on the image.
msgboxw(txtInfo);
hBox = imrect;
roiPosition = wait(hBox);
roiPosition % Echo coordinates to the command window.
% Erase all previous lines.
if ~enlargeForDrawing
axes(handleToImage);
% ClearLinesFromAxes(handles);
end
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);