MATLAB Answers

Artem
0

The different results of functions getframe and imread

Asked by Artem
on 2 Dec 2011
Accepted Answer by Jan
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

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.

1 Answer

Answer by Jan
on 2 Dec 2011
 Accepted Answer

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.