Build App to Display Pixel Information
This example shows how to create a simple app that provides information about pixels and features in an image using modular pixel information tools.
First, define a function that builds the app. This example uses a function called my_pixinfo_tool
, which is attached at the end of the example.
After you define the function that builds the app, test the app. Read an image into the workspace.
I = imread('pears.png');
Display the image with pixel information tools in the app.
my_pixinfo_tool(I)
App Creation Function
The my_pixinfo_tool
function accepts an image as an argument and displays the image in a figure window with a Pixel Information tool, Display Range tool, Distance tool, and Pixel Region tool. Note that the function suppresses the toolbar and menu bar in the figure window because scrollable navigation is incompatible with standard MATLAB™ figure window navigation tools.
function my_pixinfo_tool(im) % Create figure, setting up properties fig = figure('Toolbar','none', ... 'Menubar','none', ... 'Name','My Pixel Info Tool', ... 'NumberTitle','off', ... 'IntegerHandle','off'); % Create axes and reposition the axes % to accommodate the Pixel Region tool panel ax = axes('Units','normalized', ... 'Position',[0 .5 1 .5]); % Display image in the axes img = imshow(im); % Add Distance tool, specifying axes as parent distool = imdistline(ax); % Add Pixel Information tool, specifying image as parent pixinfo = impixelinfo(img); % Add Display Range tool, specifying image as parent drange = imdisplayrange(img); % Add Pixel Region tool panel, specifying figure as parent % and image as target pixreg = impixelregionpanel(fig,img); % Reposition the Pixel Region tool to fit in the figure % window, leaving room for the Pixel Information and % Display Range tools set(pixreg, 'units','normalized','position',[0 .08 1 .4]) end
See Also
imdistline
| impixelinfo
| imdisplayrange
| impixelregionpanel