This example shows how to create a Pixel Region tool in a separate figure window and embedded in an existing figure window.
Read an image into the workspace.
I = imread("pout.tif");
Display the image in a figure window. Return a handle to the target image,
himage = imshow('pout.tif');
To create the Pixel Region tool in a separate window, use the
hpixreg = impixelregion(himage);
Create a new figure window and return a handle to the figure.
fig = figure;
Create an axes and display the target image in the axes.
ax = axes; img = imshow(I);
To create the Pixel Region tool in the same figure as the target image, use the
impixelregionpanel function. Specify the target image's parent figure,
fig, as the parent of the Pixel Region tool.
pixregionobj = impixelregionpanel(fig,img);
The Pixel Region tool overlaps and hides the original image. To see both the image and the tool, shift their positions so that they do not overlap.
set(ax,'Units','normalized','Position',[0 .5 1 .5]); set(pixregionobj,'Units','normalized','Position',[0 .04 1 .4]);