Main Content

Create Pixel Region Tool

This example shows how to create a Pixel Region tool in a separate figure window and embedded in an existing figure window.

Create Pixel Region Tool in Separate 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.

himage = imshow('pout.tif');

To create the Pixel Region tool in a separate window, use the impixelregion function.

hpixreg = impixelregion(himage);

Figure contains an axes object. The hidden axes object contains 12 objects of type line, patch, image.

Figure Pixel Region (Figure 1) contains an axes object and other objects of type uipanel, uitoolbar, uimenu. The hidden axes object contains 75 objects of type line, image, text.

Embed Pixel Region Tool in Existing Figure

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);

Figure contains 2 axes objects and another object of type uipanel. Hidden axes object 1 contains 137 objects of type line, image, text. Hidden axes object 2 contains 12 objects of type line, patch, image.

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]);

Figure contains 2 axes objects and another object of type uipanel. Hidden axes object 1 contains 65 objects of type line, image, text. Hidden axes object 2 contains 12 objects of type line, patch, image.

See Also

|

Related Topics