How to display a zoomed image in GUIDE

조회 수: 1 (최근 30일)
Philip
Philip 2011년 2월 28일
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!

채택된 답변

Matt Tearle
Matt Tearle 2011년 2월 28일
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
Matt Tearle
Matt Tearle 2011년 2월 28일
@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 2011년 2월 28일
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

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Paulo Silva
Paulo Silva 2011년 2월 28일
The documentation for the zoom function is very good, nice examples and you can take advantage of blog

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by