Effacer les filtres
Effacer les filtres

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

3 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

Matthew Eicholtz
Matthew Eicholtz le 3 Oct 2016
Modifié(e) : Matthew Eicholtz le 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
  3 commentaires
Xingwang Yong
Xingwang Yong le 30 Sep 2022
Modifié(e) : Xingwang Yong le 30 Sep 2022
@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...

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by