Main Content


Magnification box for image displayed in scroll panel


Use the immagbox function to add a magnification box to the same figure as an image contained in a scroll panel. A magnification box is an editable text box that contains the current magnification of the target image. When you enter a new value in the magnification box, the magnification of the target image changes. When the magnification of the target image changes for any reason, the magnification box updates the magnification value.

Magnification box in the bottom left corner of the figure window, showing a magnification value of 80%.


hBox = immagbox(hParent,hImage) creates a magnification box for image hImage. The image must be displayed in a scroll panel. The magnification box hBox is added to the figure or panel hParent.


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="Pears");
hIm = imshow("pears.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 to the figure. Set the position of the magnification box to the lower left corner of the figure.

hMagBox = immagbox(hFig,hIm);
pos = get(hMagBox,"Position");
set(hMagBox,Position=[0 0 pos(3) pos(4)])

Get the scroll panel API so that you can control the view programmatically.

apiSP = iptgetapi(hSP);

Set the magnification of the image to 200% by using the scroll panel API function setMagnification. Notice how the magnification box updates.


Input Arguments

collapse all

Parent of the magnification box, specified as a Figure or Panel object.

Image, specified as an Image object. The image must be displayed in a scroll panel created by imscrollpanel.

Output Arguments

collapse all

Magnification box, returned as a Panel object.

More About

collapse all

Magnification Box API Structure

A magnification box contains a structure of function handles, called an API. You can use the functions in this API to manipulate the magnification box. To retrieve this structure, use the iptgetapi function, as in the following example.

api = iptgetapi(hbox)

This table lists the magnification box 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)

new_mag is a scalar magnification factor.

Version History

Introduced before R2006a