MATLAB Answers

The different results of functions getframe and imread

2 views (last 30 days)
Artem
Artem on 2 Dec 2011
Hi everybody
I have simple function:
=================================================
function getframe_inmread
for i = 1:200
for j = 1:300
latmap(i,j) = 10 + (j - 1) * 0.1;
lonmap(i,j) = 10 + (i - 1) * 0.1;
end;
end
A(1:200, 1:300) = 1;
A(50:100, 100:200) = 2;
f1 = figure;
axesm gortho
surfm(latmap,lonmap,A);
% ------------ version 1 - getframe
pos = get(gcf,'Position');
Bgf = getframe(gcf);
sgf = size(Bgf.cdata)
% ------------ version 2 - imread
fl_pic = 'tmp_frim';
% print('-f1', '-dpng',fl_pic);
print('-f1', '-dbmp',fl_pic);
close(f1);
% af = imread([fl_pic '.png']);
af = imread([fl_pic '.bmp']);
saf = size(af)
================================================
Obtain arrays (colors) of different dimension.
>>sgf =
420 560 3
>>saf =
901 1201 3
I need to getframe gave the same array as imread, because upon application of map I should take the second map of imread.
Any help on the topic would be greatly appreciated.
Thanks

  1 Comment

Jan
Jan on 2 Dec 2011
Please apply a proper code formatting as explained in the "Markup help" link. And please be so kind and explain, why the formatting of the code is so hard for beginners.

Sign in to comment.

Accepted Answer

Jan
Jan on 2 Dec 2011
The function getframe creates an exact pixel copy of the contents of the window. In opposite to this print performs some rescaling, e.g. if you export the figure contents with a different resolution. But even for -r0, the original screen resolution, the output is not exact. E.g. UICONTROLs are rendered differently and embedded as raster images.
In consequence IMREAD(PRINT) and GETFRAME will not produce the 100% equal results.

  0 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by