imrect not visible after updating an image

1 view (last 30 days)
Refer to the script below:
f = figure;
im = image(rand(200, 100, 3));
roi = imrect(gca, [5, 10, 40, 30]);
title('ROI visible');
image(rand(200, 100, 3));
title('ROI not visible, how to make it visible again?');
At this point, roi still exists but is no longer visible. You can still run get(roi), for instance. How to make it visible again?

Accepted Answer

Walter Roberson
Walter Roberson on 14 Jul 2017
uistack(roi, 'top')
Donald Liu
Donald Liu on 15 Jul 2017
This worked, with a minor change: old_warning_state = warning('off', 'MATLAB:structOnObject');

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 14 Jul 2017
You can get the coordinates and then use plot() to plot the box whenever you want. See this demo:
im = image(rand(200, 100, 3));
axis on;
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);
title('ROI visible');
% Update image
hold off;
grayImage = imread('moon.tif'); % Note, this is a different size.
hold on;
axis on;
plot(xCoords, yCoords, 'linewidth', 2); % Plots with original units and size.
title('ROI visible on updated image');

Sign in to comment.


Community Treasure Hunt

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

Start Hunting!