Image Processing Toolbox User's Guide Previous page   Next Page

Making Connections for Interactivity

When you create a modular tool and associate it with a target image, the tool automatically makes the necessary connections to the target image to do its job.

For example, the Pixel Information tool sets up a connection to the target image so that it can display the location and value of the pixel currently under the cursor. The Overview tool sets up a two-way connection to the target image:

The modular tools accomplish this interactivity by using callback properties of the graphics objects. For example, the figure object supports a WindowButtonMotionFcn callback that executes whenever the mouse button is depressed.

In addition, some of the modular tools also support an application programmer interface (API). This API is a set of functions that let you get information about the tool as it operates and set up callbacks to get notification of events.

For example, the Magnification box supports a single API function: setMagnification. You can use this API function to set the magnification value displayed in the Magnification box. The Magnification box automatically notifies the scroll panel to change the magnification of the image based on the value. The scroll panel also supports an extensive set of API functions; see the imscrollpanel reference page for more information.

Example: Building an Image Comparison Tool

To illustrate how to use callbacks to make the connections required for interactions between tools, this example uses the Scroll Panel API to build a simple image comparison GUI. This custom tool displays two images side by side in scroll panels that are synchronized in location and magnification. The custom tool also includes an Overview tool and a Magnification box.

The tool sets up a complex interaction between the scroll panels with just a few calls to Scroll Panel API functions. In the code, the tool specifies a callback function to execute every time the magnification changes. The function specified is the setMagnification API function of the other scroll panel. Thus, whenever the magnification changes in one of the scroll panels, the other scroll panel changes its magnification to match. The tool sets up a similar connection for position changes.

The following figure is a sequence diagram that shows the interaction between the two scroll panels set up by the comparison tool for both changes in magnification and location.

Scroll Panel Connections in Custom Image Comparison Tool

To use the image comparison tool, pass it two images as arguments.

The tool opens a figure window, displaying the two images side by side, in separate scroll panels. The custom compare tool also includes an Overview tool and a Magnification box. When you move the detail rectangle in the Overview tool or change the magnification in one image, both images respond.

Custom Image Comparison Tool with Synchronized Scroll Panels


Previous page  Adding Navigation Aids to a GUI Creating Your Own Modular Tools Next page

© 1994-2005 The MathWorks, Inc.