My confusion with region of interest

1.8k views Asked by At

I was looking into the region of interest tutorial set here and there are a few things that escape my understanding.

The example given to create a binary mask for setting the ROI is

img = imread('pout.tif');
h_im = imshow(img);
e = imellipse(gca,[55 10 120 120]);
BW = createMask(e,h_im);

I understand that an ellipse imellipse is used to create the ROI object. So following its own page here I read more about it but no where on that page does it explain what gca is? all it says is that it is an hparent and specifies the HG parent of the ellipse. I do not understand this can some one please elaborate. Can I use something else in place of gca? and what is gca?

Also in this line the imshow function is assigned to h_im and then further used. When I did this with my installation with a sample image I got this value h_im = 1.740099 so h_im is a double value.

This is further used here BW = createMask(e,h_im); I understand that these are the parameters meaning:

BW = createMask(h,h_im) returns a mask the same size as the image h_im with 1s inside the ROI object h and 0s outside. This syntax is required when the axes that contain the ROI hold more than one image.

so is 1.740099 the size of the image? In which units is this measured?

Also when I wrote the last line in my Matlab I got the following error:

>> BW = createMask(h,h_im);
??? Invalid or deleted object.

Error in ==> imroi>imroi.parseInputsForCreateMask at 78
            h_ax = ancestor(obj.h_group,'axes');

Error in ==> imroi>imroi.createMask at 264
            [obj,h_im] = parseInputsForCreateMask(varargin{:});

Why am I getting this error?

Thank you

1

There are 1 answers

0
nkjt On BEST ANSWER

gca is a function which returns the handle to the current axes. Similarly, h_im is a handle to the image object created by imshow. You can read more about working with handles from Mathworks here.

The number you see when examining handles is not related to the properties (size, etc) of the image - the value might have to do with type of object, but basically they're identifiers used by Matlab to keep track of open graphics objects. So when you call imellipse you're passing in a handle to the axes where the ellipse will appear, and returning another handle in e.

e = imellipse(gca,[55 10 120 120]);

Alternatively in place of gca you could use another handle pointing to a different axes. For example, if you had:

a1 = subplot(1,2,1), h1 = imshow(img1)
a2 = subplot(1,2,2), h2 = imshow(img2)

Then you could use either a1 or a2 in place of gca depending on which image you wanted to create the roi in.

If you close the figure containing the image and your ellipse, those handles will be deleted - which is how you got the error 'Invalid or deleted object'. Once you've used createMask and returned the mask you want, the figure can be closed.