How to find whether a ROI handle exist, if the ROI is not visible in the figure axes?

3 次查看(过去 30 天)
I have a grayscale image in a GUI axes. I have to draw a ROI in the image using imellipse(). Now if I want to check whether ROI exist, isvalid() command works fine.
But if I draw a ROI and then make changes in the Image (eg: assign new values to some pixels and display the updated image in GUI axes) then isvalid command always returns false no matter the ROI exist or not.
Is there any way to check whether the handle of a ROI exist even if the ROI is not visible in current figure axes.

采纳的回答

Matthew Eicholtz
Matthew Eicholtz 2016-10-3
编辑:Matthew Eicholtz 2016-10-3
What do you mean by "display the updated image in GUI axes"? If you mean that you make a call to imshow or imagesc, then chances are you overwriting the current figure axes with the new image. In this case, the imellipse handle is no longer valid, not just "hidden" under the axes.
I suggest storing the Image to a variable, then updating the CData property of the Image, which will not clear the imellipse object.
Here is an example:
I = imread('peppers.png'); %sample image
J = rgb2gray(I); %sample modification to the image
h = imshow(I); %h is an Image object
e = imellipse(); %draw the ellipse on the figure
isvalid(e) %should return true
h.CData = J; %change the image in the figure without clearing the axes
isvalid(e) %should still return true
  3 个评论
Xingwang Yong
Xingwang Yong 2022-9-30
编辑:Xingwang Yong 2022-9-30
@Matthew Eicholtz I have a similar question. Can I access ROI object without saving the output of imecllipse()?
I = imread('pout.tif'); %sample image
h = imshow(I); %h is an Image object
imellipse(); %draw the ellipse on the figure
J = I;
J(1,1) = 1; %sample modification to the image
h.CData = J; %change the image in the figure without clearing the axes
% how to get the ROI object? then calculate something based on mask...

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by