File Exchange

image thumbnail

Real-time Magnifying Glass: An Interactive Animation Example

version 1.0 (244 KB) by

A real-time mouse-following magnifying glass of several different shapes

1 Download


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

Comments and Ratings (4)

David Martin

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~


Lili (view profile)


MATLAB Release
MATLAB 7.12 (R2011a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video