File Exchange

image thumbnail

Real-time Magnifying Glass: An Interactive Animation Example

version (244 KB) by Mingjing Zhang
A real-time mouse-following magnifying glass of several different shapes


Updated 03 Mar 2012

View License

This program demonstrates how to implement a not-so-simple real time magnifying glass.

How to use:
just type:



magnifier(mask, FPS)

mask is the shape of the magnifying glass which takes one of the following values:

"circle" - unsmoothed circular window
"aacircle" - smoothed circular window (default)
"gaussian" - guassian window
other string value - rectangular window

FPS defines how many time the position of the magnifying glass should be updated per second. By default, its value is 20.


The picture used in this program was taken from the A-li comic book series drawn by Xu Han (aka "Hans").

The Chinese text on the top left corner reads:
"On the Friday morning, A-li (roughly equivalent to 'foxy' in English) hung himself on the clothes rope, in an attempt to pull his ears longer...

-It was said that he fell in love with the rabbit."

Cite As

Mingjing Zhang (2020). Real-time Magnifying Glass: An Interactive Animation Example (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (4)

Very handy tool. A few bug fixes and improvements to pass along:

1. First, anyone trying to use this tool will receive a number of errors and warnings concerning non-integer indexing at line #127. Easy fix, just need some rounding like this:

%Line 127:
round(mag_x_cropped(1):mag_x_cropped(2)-mag_pos(1)+PreMagRadius+1),:) = ...

2. As the code is written, you cannot use it to view grayscale images. However, by making a few changes at lines 70, 73, 74, and 127, you can process grayscale images:

%Line 70:
img_hdl = imshow(img_rgb);

%Line 73:
mag_img_hdl = imshow([],'Parent',MainAxesHdl);

%Line 74:
mag_img = img_rgb(1:PreMagRadius*2+1,1:PreMagRadius*2+1);

%Line 127:
round(mag_x_cropped(1):mag_x_cropped(2)-mag_pos(1)+PreMagRadius+1)) = ...
round(mag_x_cropped(1):mag_x_cropped(2))); I love your submissions!

very nice~



MATLAB Release Compatibility
Created with R2011a
Compatible with any release
Platform Compatibility
Windows macOS Linux