How to keep roi points visible when replotting
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Simon Allosserie
le 24 Fév 2022
Modifié(e) : Simon Allosserie
le 8 Mar 2022
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
0 commentaires
Réponse acceptée
DGM
le 24 Fév 2022
Modifié(e) : DGM
le 24 Fév 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 commentaires
DGM
le 24 Fév 2022
Modifié(e) : DGM
le 24 Fév 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.
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!