How to find whether a ROI handle exist, if the ROI is not visible in the figure axes?
8 views (last 30 days)
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 on 3 Oct 2016
Edited: Matthew Eicholtz on 3 Oct 2016
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