Main Content

imscrollpanel

Scroll panel for interactive image navigation

Description

Use the 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.

hPanel = imscrollpanel(hParent,hImage) creates a scroll panel hPanel that enables scrolling image hImage. The scroll panel is added to the parent figure or panel hParent.

example

Examples

collapse all

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",Name="Saturn");
hIm = imshow("saturn.png");

Figure Saturn contains an axes object. The hidden axes object contains an object of type image.

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

Figure Saturn contains an axes object and other objects of type uipanel, uicontrol. The hidden axes object contains an object of type image.

imoverview(hIm)

Figure Overview (Saturn) contains an axes object and other objects of type uipanel, uitoolbar, uimenu. The hidden axes object contains 8 objects of type line, patch, image.

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()
mag = 
1
r = api.getVisibleImageRect()
r = 1×4

  218.0000  383.0500  765.0000  734.9000

Use the scroll panel object API function setVisibleLocation to view the top left corner of the image.

api.setVisibleLocation(0.5,0.5)

Figure Saturn contains an axes object and other objects of type uipanel, uicontrol. The hidden axes object contains an object of type image.

Figure Overview (Saturn) contains an axes object and other objects of type uipanel, uitoolbar, uimenu. The hidden axes object contains 8 objects of type line, patch, 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.

api.setMagnification(api.findFitMag())

Figure Saturn contains an axes object and other objects of type uipanel, uicontrol. The hidden axes object contains an object of type image.

Figure Overview (Saturn) contains an axes object and other objects of type uipanel, uitoolbar, uimenu. The hidden axes object contains 8 objects of type line, patch, image.

Zoom in to 1600% on the dark spot.

api.setMagnificationAndCenter(16,306,800)

Figure Saturn contains an axes object and other objects of type uipanel, uicontrol. The hidden axes object contains an object of type image.

Figure Overview (Saturn) contains an axes object and other objects of type uipanel, uitoolbar, uimenu. The hidden axes object contains 8 objects of type line, patch, image.

Input Arguments

collapse all

Parent of the scroll panel, specified as a Figure or Panel object.

Image, specified as an Image object.

Output Arguments

collapse all

Scroll panel, returned as a Panel object.

More About

collapse all

Tips

  • 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 imscrollpanel.

  • When you run imscrollpanel, it appears to take over the entire figure because, by default, an uipanel object has 'Units' set to 'normalized' and 'Position' set to [0 0 1 1]. If you want to see other children of hparent while using your new scroll panel, you must manually set the 'Position' property of hpanel.

Version History

Introduced before R2006a