How to access zoomed image on axes GUI

I was working on some application in matlab guide. I'm using toolbar in my GUI with inbuilt zoom in and zoom out features that it provides. So what I have done is that I have loaded an image on an axis. And now after zooming it, I want the access the zoomed image, not the entire image. I have tried getimage(), but what it does is that it gives me the entire image loaded on the axis. Someone please help me out.

 Accepted Answer

In the other post I told you to use getframe() and gave you code. Here is the demo again.
close all;
im=imread('cameraman.tif');
subplot(1,2,1);
imshow(im);
subplot(1,2,2);
imshow(im);
size(im)
zoom(8);
zoomedImage = getframe(); % Get zoomed portion that is visible.
size(zoomedImage.cdata)
figure; % Bring up separate figure.
imshow(zoomedImage.cdata);
Do you see how in the second figure it is only the zoomed, visible portion of the image from figure 1 that was captured and is being displayed?
Your post is ambiguous. On the one hand you say you want to capture only the zoomed portion, yet on the other hand you say you want "the entire image loaded on the axis" which would include the entire image even the parts that were zoomed out of the display window and not visible. Of course you already have the entire image - you sent it into the axes with imshow(), though what's displayed may be different if you added text, lines, or other annotation. Please clarify exactly what you want because it's not clear to me.

7 Comments

Thanks, it worked
Naman Bansal
Naman Bansal on 28 Jul 2014
Edited: Naman Bansal on 28 Jul 2014
Hey if I'm trying to read a grey-scale image using getframe, it's creating problems. It is reading it as RGB image. Now what should I do for that. Also can I get the position of that frame i.e. which portion of the image that frame is capturing. Also the size of the image that is in that frame is also getting increased.
Call rgb2gray after you get it. The size is probably the size of the image as displayed on your screen, which makes sense. Why would you expect otherwise if it were zoomed?
Naman Bansal
Naman Bansal on 28 Jul 2014
Edited: Naman Bansal on 28 Jul 2014
That's beat the purpose of it. Here's what I did.
I loaded a 100*100 image on axis using image() command.
After that I zoomed, into it.
Now I want to perform some operation on it by pressing a push button. So when I do that, here's what I get
As you'll see in the bottom left side. The size of the image from the frame is 301*301*3. So what getframe() is capturing the frame as it is shown on my screen not according to its size. But that's not how I want it.
But that's not how it should be or rather that's not the way how I want it to be. I just to take the portion of the image after zooming(say 30*30) and do some operation on it. Also I tried converting it to gray scale image in separate code. So there is also some problem. Pixel values are not the same everywhere. I tried the difference between the two. Even though the difference is very small (in my case it was coming out to be -1) but that's not it should be. Please help
And also can I access the position of the zoomed image like it starts from 10*10 pixel in the initial image.
That's not how you do ROI processing. You don't just zoom and expect to process the visible area. You need to crop it out with imcrop, or use imrect() or rbbox() or some other way to indicate what the ROI is.
Hey I understood what you are saying. So now let me reformulate my problem. So I have two images loaded in two axis. Now what I want is to allow the user to zoom in both of them as he wants (I'll have to link those axis). Then he'll be selecting a ROI(rectangle) in one of them.(I want the same operation to be performed on the two ROI's selected from two images loaded in two axis). So what my problem is I have no idea now where to start, what functions to use. I tried the method that I was asking you earlier but that's of no use. So can you just help me get started. It will be a great help.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!