How to keep roi points visible when replotting

4 views (last 30 days)
I have a GUI where I plot an image using imshow. There are 2 color versions of this image.
By clicking on the image, the user can select data points to export the color code of the selected pixel. The selected location is indicated on the image using the drawpoint function.
Using a dropdown menu, they can switch between the 2 color version. The only problem I have there, is that the drawpoints disappear. Is there any way to keep them visible, like placing the imshow in the backgrond and not overwriting the drawpoints?
imshow(image, 'Parent', ax);
%selecting data points and visualising them on the image
roi = drawpoint(ax);
x(i) = roi.Position(1);
y(i) = roi.Position(2);
%changing the displayed image
value = app.DropDownVisual.Value;
switch value
case "Decor"
cla(ax,'reset')
imshow(image, 'Parent', ax);
case "Delta E"
imshow(deltaE, 'Parent', ax); colormap(ax, jet); caxis(ax, [0 max(deltaE(:))]); colorbar(ax);
end

Accepted Answer

DGM
DGM on 24 Feb 2022
Edited: DGM on 24 Feb 2022
Whenever you draw a new image with imshow(), and definitely when you clear the axes, the roi object gets deleted. You'll have to recreate it. Off the top of my head, I don't know of a simpler way around it.
image = imread('cameraman.tif');
deltaE = flipud(image);
ax = gca;
i = 1;
imshow(image, 'Parent', ax);
%selecting data points and visualising them on the image
roi = drawpoint(ax);
x(i) = roi.Position(1);
y(i) = roi.Position(2);
%changing the displayed image
value = "Delta E";
switch value
case "Decor"
imshow(image, 'Parent', ax);
roi = images.roi.Point(ax);
roi.Position = [x(i) y(i)];
case "Delta E"
imshow(deltaE, 'Parent', ax); colormap(ax, jet); caxis(ax, [0 max(deltaE(:))]); colorbar(ax);
roi = images.roi.Point(ax);
roi.Position = [x(i) y(i)];
end
  3 Comments
Simon Allosserie
Simon Allosserie on 8 Mar 2022
Edited: Simon Allosserie on 8 Mar 2022
I really like the uistack solution, but it doesn't work apparently in Apps, only in standalone figures. So for me it isn't applicable unfortunately.
However, your first alternative with delete(img) works perfectly fine! The colorbar is still in view but I'll take this as a necessary pain.
Thanks!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by