imscrollpanel

Scroll panel for interactive image navigation

Syntax

hpanel = imscrollpanel(hparent, himage)

Description

hpanel = imscrollpanel(hparent, himage) creates a scroll panel containing the target image (the image to be navigated). himage is a handle to the target image. hparent is a handle to the figure or uipanel that will contain the new scroll panel. The function returns hpanel, a handle to the scroll panel, which is a uipanel object.

A scroll panel makes an image scrollable. If the size or magnification makes an image too large to display in a figure on the screen, 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.

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.

API Functions

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 example.

api = iptgetapi(hpanel)

This table lists the scroll panel API functions, in the order they appear in the structure.

Function

Description

setMagnification

Sets the magnification of the target image in units of screen pixels per image pixel.

mag = api.setMagnification(new_mag)

where new_mag is a scalar magnification factor.

getMagnification

Returns the current magnification factor of the target image in units of screen pixels per image pixel.

mag = api.getMagnification()

Multiply mag by 100 to convert to percentage. For example if mag=2, the magnification is 200%.

setMagnificationAndCenter

Changes the magnification and makes the point cx,cy in the target image appear in the center of the scroll panel. This operation is equivalent to a simultaneous zoom and recenter.

api.setMagnificationAndCenter(mag,cx,cy)

findFitMag

Returns the magnification factor that would make the target image just fit in the scroll panel.

mag = api.findFitMag()

setVisibleLocation

Moves the target image so that the specified location is visible. Scrollbars update.

api.setVisibleLocation(xmin, ymin) 
api.setVisibleLocation([xmin ymin])

getVisibleLocation

Returns the location of the currently visible portion of the target image.

loc = api.getVisibleLocation()

where loc is a vector [xmin ymin].

getVisibleImageRect

Returns the current visible portion of the image.

r = api.getVisibleImageRect()

where r is a rectangle [xmin ymin width height].

addNewMagnificationCallback

Adds the function handle fcn to the list of new-magnification callback functions.

id = api.addNewMagnificationCallback(fcn)

Whenever the scroll panel magnification changes, each function in the list is called with the syntax:

fcn(mag)

where mag is a scalar magnification factor.

The return value, id, is used only with removeNewMagnificationCallback.

removeNewMagnificationCallback

Removes the corresponding function from the new-magnification callback list.

api.removeNewMagnificationCallback(id)

where id is the identifier returned by addNewMagnificationCallback.

addNewLocationCallback

Adds the function handle fcn to the list of new-location callback functions.

id = api.addNewLocationCallback(fcn)

Whenever the scroll panel location changes, each function in the list is called with the syntax:

fcn(loc)

where loc is [xmin ymin].

The return value, id, is used only with removeNewLocationCallback.

removeNewLocationCallback

Removes the corresponding function from the new-location callback list.

api.removeNewLocationCallback(id)

where id is the identifier returned by addNewLocationCallback.

replaceImage

api.replaceImage(...,PARAM1,VAL1,PARAM2,
VAL2,...)
replaces the image displayed in the scroll panel.

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 imshow, including 'Colormap', 'DisplayRange', and 'InitialMagnification'. In addition, you can use the 'PreserveView' parameter to preserve the current magnification and centering of the image during replacement. Specify the logical scalar True to preserve current centering and magnification. Parameter names can be abbreviated, and case does not matter.

Note

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 hpanel 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.

Examples

Create a scroll panel with a Magnification Box and an Overview tool.

  1. Create a scroll panel.

    hFig = figure('Toolbar','none',...
                  'Menubar','none');
    hIm = imshow('saturn.png');
    hSP = imscrollpanel(hFig,hIm);
    set(hSP,'Units','normalized',...
            'Position',[0 .1 1 .9])
  2. Add a Magnification Box and an Overview tool.

    hMagBox = immagbox(hFig,hIm);
    pos = get(hMagBox,'Position');
    set(hMagBox,'Position',[0 0 pos(3) pos(4)])
    imoverview(hIm)
  3. Get the scroll panel API to programmatically control the view.

    api = iptgetapi(hSP);
  4. Get the current magnification and position.

    mag = api.getMagnification();
    r = api.getVisibleImageRect();
  5. View the top left corner of the image.

    api.setVisibleLocation(0.5,0.5)
  6. Change the magnification to the value that just fits.

    api.setMagnification(api.findFitMag())
  7. Zoom in to 1600% on the dark spot.

    api.setMagnificationAndCenter(16,306,800)
Was this topic helpful?