Matlab: using avifile, addframe, getframe; the generated avi is contorted

巧了我就是萌 提交于 2019-12-13 16:29:14

问题


I'm training a machine learning algorithm, and wanted to make an avi to visualize the appearance of weights over time. I threw together something similar to:

aviobj = avifile( 'weights.avi' );
for jj = 1:whatever
  % do some training
  imagesc( ... ); % where '...' is stuff to reshape the weight matrix
  aviobj = addframe( aviobj, getframe );
end;
aviobj = close( aviobj );
implay( 'weights.avi' );

The problem is, the frames end up looking like this:

The numbers shouldn't have that orientation. This occurs with any avi I generate in matlab.

Any suggestions?

-Brian


回答1:


Finally had time to get back to this. The problem was due to the axes. When using something like image or imagesc, it tacks on an extra black border line on the bottom & left of the image. When you use getframe, it grabs only the image data plotted, sans the black lines. However, the frame itself is slightly larger than the image data.

The following solves it:

aviobj = avifile( 'weights.avi' );
fig = figure;
for jj = 1:whatever
  % do some training
  imagesc( ... ); % where '...' is stuff to reshape the weight matrix
  axis off;
  aviobj = addframe( aviobj, getframe( fig ) );
end;
aviobj = close( aviobj );
implay( 'weights.avi' );

Setting axis off fixes it.



来源:https://stackoverflow.com/questions/5835792/matlab-using-avifile-addframe-getframe-the-generated-avi-is-contorted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!