How to keep roi points visible when replotting

조회 수: 11 (최근 30일)
Simon Allosserie
Simon Allosserie 2022년 2월 24일
편집: Simon Allosserie 2022년 3월 8일
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

채택된 답변

DGM
DGM 2022년 2월 24일
편집: DGM 2022년 2월 24일
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
DGM
DGM 2022년 2월 24일
편집: DGM 2022년 2월 24일
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 2022년 3월 8일
편집: Simon Allosserie 2022년 3월 8일
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!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Display Image에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by