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

조회 수: 4 (최근 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