How to keep roi points visible when replotting

12 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

DGM
DGM il 24 Feb 2022
Modificato: DGM il 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 Commenti
DGM
DGM il 24 Feb 2022
Modificato: DGM il 24 Feb 2022
Well, you could a couple other things. If you set hold on, the roi object wouldn't get deleted, but if you're swapping back and forth, you'll keep stacking more and more image objects in the axes. You would have to keep track of those handles and delete them.
image = imread('cameraman.tif');
deltaE = flipud(image);
ax = gca;
i = 1;
himg = 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);
hold on
%changing the displayed image
value = "Delta E";
switch value
case "Decor"
delete(himg)
himg = imshow(image, 'Parent', ax);
case "Delta E"
delete(himg)
himg = imshow(deltaE, 'Parent', ax); colormap(ax, jet); caxis(ax, [0 max(deltaE(:))]); colorbar(ax);
end
Alternatively, you might simply put both image objects in the axes at the same time and then swap their stacking order. That way everything stays in place.
image = imread('cameraman.tif');
deltaE = flipud(image);
ax = gca;
i = 1;
himg1 = imshow(deltaE, 'Parent', ax); hold on
himg2 = 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 = "Decor";
switch value
case "Decor"
uistack(himg1,'bottom');
colormap(ax, gray);
caxis(ax, [0 max(image(:))]);
colorbar(ax,'off');
case "Delta E"
uistack(himg2,'bottom');
colormap(ax, jet);
caxis(ax, [0 max(deltaE(:))]);
colorbar(ax,'on');
end
The first option might be better if you are always changing the image content. The latter option might be more efficient if you're more often only swapping the view without necessarily changing the image data.
Now that I think about it, these do seem simpler, so I guess that makes me wrong.
Simon Allosserie
Simon Allosserie il 8 Mar 2022
Modificato: Simon Allosserie il 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!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Display Image in Help Center e File Exchange

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by