Scroll panel for interactive image navigation
imscrollpanel function to add a scroll panel to an
image. If the size or magnification makes an image too large to display in a figure on the
screen, then the scroll panel displays a portion of the image at 100% magnification (one
screen pixel represents one image pixel). The scroll panel adds horizontal and vertical scroll
bars to enable navigation around the image.
Display an image in a figure. The example suppresses the standard toolbar and menubar in the figure window because these do not work with the scroll panel.
hFig = figure('Toolbar','none',... 'Menubar','none'); hIm = imshow('saturn.png');
Create a scroll panel to contain the image.
hSP = imscrollpanel(hFig,hIm); set(hSP,'Units','normalized','Position',[0 .1 1 .9])
Add a Magnification Box and an Overview tool to the figure.
hMagBox = immagbox(hFig,hIm); pos = get(hMagBox,'Position'); set(hMagBox,'Position',[0 0 pos(3) pos(4)]) imoverview(hIm)
Get the scroll panel API so that you can control the view programmatically.
api = iptgetapi(hSP);
Get the current magnification and position.
mag = api.getMagnification() r = api.getVisibleImageRect()
mag = 1 r = 125.0072 201.5646 716.0000 709.0000
Use the scroll panel object API function
view the top left corner of the image.
Change the magnification of the image so that the image fits entirely in the scroll panel. In the following figure, note that the scroll bars are no longer visible.
Zoom in to 1600% on the dark spot.
hparent— Handle to figure or uipanel object
Handle to a figure or uipanel object that contains the scroll panel, specified as a handle.
himage— Handle to target image
Handle to target image, specified as a handle.
hpanel— Handle to scroll panel
Handle to scroll panel, returned as a handle. A scroll panel is a type of uipanel object.
A scroll panel contains a structure of function handles, called an API. You can use the
functions in this API to manipulate the scroll panel. To retrieve this structure, use the
iptgetapi function, as in the following
api = iptgetapi(hpanel)
This table lists the scroll panel API functions, in the order they appear in the structure.
Set the magnification of the target image in units of screen pixels per image pixel.
mag = api.setMagnification(new_mag)
Return the current magnification factor of the target image in units of screen pixels per image pixel.
mag = api.getMagnification()
Change the magnification and make the point with
Return the magnification factor that would make the target image just fit in the scroll panel.
mag = api.findFitMag()
Move the target image so that the specified location is visible, and update the scroll bars.
api.setVisibleLocation(xmin, ymin) api.setVisibleLocation([xmin ymin])
Return the location of the currently visible portion of the target image.
loc = api.getVisibleLocation()
Return the current visible portion of the image.
r = api.getVisibleImageRect()
Add the function handle
id = api.addNewMagnificationCallback(fcn)
Whenever the scroll panel magnification changes, each function in the list is called with the syntax:
The return value,
Remove the corresponding function from the new-magnification callback list.
Add the function handle
id = api.addNewLocationCallback(fcn)
Whenever the scroll panel location changes, each function in the list is called with the syntax:
The return value,
Remove the corresponding function from the new-location callback list.
api.replaceImage(I) api.replaceImage(BW) api.replaceImage(RGB) api.replaceImage(I,MAP) api.replaceImage(filename)
By default, the new image data is displayed centered, at 100% magnification. The image handle is unchanged.
The parameters you can
specify include many of the parameters supported by
imscrollpanel changes the object hierarchy of the target image.
Instead of the familiar figure→axes→image object hierarchy,
imscrollpanel inserts several uipanel and uicontrol objects between
the figure and the axes object.
Scrollbar navigation as provided by
imscrollpanel is incompatible
with the default MATLAB® figure navigation buttons (pan, zoom in, zoom out). The corresponding menu
items and toolbar buttons should be removed in a custom GUI that includes a scrollable
uipanel created by
When you run
imscrollpanel, it appears to take over the entire
figure because, by default, an uipanel object has
'Units' set to
'Position' set to
[0 0 1
1]. If you want to see other children of
using your new scroll panel, you must manually set the