フィルターのクリア

getframe difference in 2014b.... bug?

3 ビュー (過去 30 日間)
Sven
Sven 2014 年 12 月 18 日
コメント済み: Sven 2015 年 3 月 11 日
The following code run in 2014a and 2014b produces remarkably different results. I think it's a bug.
figure('Position',[100 100 200 500],'Color','y');
I = imread('rice.png');
imagesc(I)
axis image
colormap(gray)
gf = getframe(gca);
figure, imshow(gf.cdata)
In 2014a it successfully captures ONLY the current axes:
In 2014b it grabs beyond the axes limits to the extent of the figure:
  • The figure "Color" parameter makes no difference - I just used yellow for clarity.
  • The axis image line does the damage. Without it both 2014a and 2014b capture only the axes extents (as they should).
Can anyone suggest a workaround that produces identical results in both 2014a and 2014b? I have code that runs on both systems and is expected to produce similar figures using getframe. I understand that there can be pixel border effects when using getframe, these minor differences are fine, but the results shown are major differences that I want to avoid.
And if someone can confirm that they get similar results I'll submit a bugfix request.
Thanks, Sven.
  2 件のコメント
matt dash
matt dash 2014 年 12 月 18 日
Confirmed that it does the same thing for me.
The problem seems to be that axis image changes the view without changing the axes position property, which is what getframe is using to calculate the extent of the screen capture. Because of this, it will also break any other getframe-like function that uses the axes position property. (There are several on the file exchange... usually i recommend them when someone has a property with getframe, but for your case something else will be needed.)
Sven
Sven 2015 年 3 月 11 日
Note also that this bug persists in 2015a.

サインインしてコメントする。

採用された回答

Kelly Kearney
Kelly Kearney 2014 年 12 月 18 日
I'll also confirm, but older versions of Matlab also responded to axis image without changing the axis's Position property, so that's not the underlying problem. Rather, it must be a change in whether getframe considers aspect ratio properties and modes in the same way.
You can get around the bug by giving getframe precise coordinates to capture; plotboxpos will give you those coordinates:
figure('Position',[100 100 200 500],'Color','y');
I = imread('rice.png');
imagesc(I)
axis image
colormap(gray)
drawnow;
gf = getframe(gca);
un = get(gca, 'units');
set(gca, 'units', 'pixels');
rec = plotboxpos(gca);
set(gca, 'units', un);
gf2 = getframe(gcf, rec);
figure, imshow(gf.cdata)
figure; imshow(gf2.cdata);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by