How to display a zoomed image in GUIDE

3 views (last 30 days)
Hello,
Can anyone please advise me how I can display a zoomed/magnified image in GUIDE? Ideally, I would like to display the full image in one axes and the zoomed image (say 150%) in another axes, with x,y, pixel coordinates at the center of the displayed zoomed image...
Thanks for your help as always!

Accepted Answer

Matt Tearle
Matt Tearle on 28 Feb 2011
I assume you've set the two axes to be the same size, and you've loaded the image, so you can get its dimensions (m-by-n, say). A simple zoom can be achieved by selecting a scaled-down number of pixels. Something like this:
zoomfactor = 10;
zoomx = round(n/(2*zoomfactor));
zoomy = round(m/(2*zoomfactor));
zx = -zoomx:zoomx;
zy = -zoomy:zoomy;
xcoords = x0 + zx;
ycoords = y0 + zy;
imzoom = im(ycoords,xcoords,:);
where x0 and y0 are the center pixels. The only problem with this is if the center of the zoom is too near the edge of the image. In which case, a slightly more complex bit of code will fix that, replacing everything beyond the border with black:
xcoords = min(max(1,x0+zx),n);
ycoords = min(max(1,y0+zy),m);
imzoom = im(ycoords,xcoords,:);
imzoom(:,x0+zx<1,:)=0;
imzoom(y0+zy<1,:,:)=0;
imzoom(:,x0+zx>n,:)=0;
imzoom(y0+zy>m,:,:)=0;
image(imzoom)
  5 Comments
Matt Tearle
Matt Tearle on 28 Feb 2011
@Philip: no worries. You'll find that Paulo and I are a bit insane. We go way overboard with these questions, mainly for our own amusement. (Well, I assume. In my case, that's true. I guess I shouldn't speak for Paulo!)
@Paulo: have you heard of dropbox? I find it very useful for this kind of thing -- I can work on multiple computers and still have access to my files. https://www.dropbox.com
Paulo Silva
Paulo Silva on 28 Feb 2011
I'm also insane, there's so much I have to do and I found myself here waiting for interesting challenges to appear.
Yes dropbox is familiar to me but when working with other computers I often use one thumb drive, now there's only one laptop but the m files get always some name like untitled1111.m or other avaiable name that I can't find them anymore, also there are multiple folders, it's my problem, I only give proper names to the files when it's official matter lol

Sign in to comment.

More Answers (1)

Paulo Silva
Paulo Silva on 28 Feb 2011
The documentation for the zoom function is very good, nice examples and you can take advantage of blog

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!