Clear Filters
Clear Filters

Screen grab of figure axes.

2 views (last 30 days)
Nuno Benavente
Nuno Benavente on 25 Apr 2012
I'm developing a GUI that deals with image processing. When I want to view results with greater detail I have the 2 output images popup in a new figure, side by side, each within its own imscrollpanel and then a immagbox and imoverviewpanel. I can zoom in/out and pan in either subplot and the other syncs nicely. But now I'd like to take a snapshot of the area I'm seeing and I'm trying
frame = getframe(h);
image = frame2im(frame);
but it's not working as expected. if I do figure, imshow(image);
I get gibberish. getframe behavior seems erratic and often It captures not only the intented axes but also a lot more around it or only to one side of it... I am using opengl hardware and opengl renderer. I'm forced to do this because I need transparency and correct rendering in large images...
Anyone else having this problem or have any suggestions? Thanks in advance.

Answers (2)

Jan
Jan on 26 Apr 2012
I had some success by adding a pause(0.02) before getframe(). This seems to allow some syncronizations of the underlying Java objects. drawnow was not sufficient, because it fails sometimes to update the display fast enough.
  2 Comments
Nuno Benavente
Nuno Benavente on 26 Apr 2012
Thank you Jan.
I don't think this is my problem... I don't try to capture the frame imediately after the rendering of the images, it's always after several seconds, if not minutes.
Meanwhile I've been experimenting with only one axes and scrollpanel and I think I got the problem:
even though the imscrollpanel doesn't ocupy the whole window, because I set it's size and position to be smaller and on the left side or whatever, it seems that, when playing with the zoom ratio, if the resulting displayed image becomes larger than the imscrollpanel box itself, it's like the image is in a layer below but the hidden areas below the imscrollpanel are still visible to getframe.
In other words... imscrollpanel is screwing this up. anything displayed out of its axis will be captured also if the zoomed image is enough to fill a rectangle that would overlap those outer areas.
Jan
Jan on 26 Apr 2012
Does this mean that you have tried the PAUSE command and it does not help? I had success with PAUSE(0.02) even for objects which have been drawn minutes before.

Sign in to comment.


Image Analyst
Image Analyst on 26 Apr 2012
  1 Comment
Nuno Benavente
Nuno Benavente on 26 Apr 2012
Thanks,
That function is awesome, I'll probably make good use of it soon.
However it didn't work perfectly in my case, still capturing more than it should.
However I managed to solve my problem by adding a push button to the figure. When I press it a new figure pops up and reproduces only the scrollpanel of the image I want to capture. its position is the same as the original one. I still get an image which in most cases captures too much but then I crop through the values of api.getVisibleRect -> [xmin, ymin, width, height]
I have to multiply width and height by the zoomFactor and my final image is:
rect = api.getVisibleImageRect();
zoom = api.getMagnification();
frame = getframe(ax1);
crop = frame2im(frame);
crop = crop(1:rect(4)*zoom, 1:rect(3)*zoom, :);
I know my explanation was is a mess but it worked like a charm! :D

Sign in to comment.

Categories

Find more on Visual Exploration 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!