Matlab: using avifile, addframe, getframe; the gen

2019-07-16 03:01发布

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: enter image description here

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

Any suggestions?

-Brian

1条回答
放荡不羁爱自由
2楼-- · 2019-07-16 03:54

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.

查看更多
登录 后发表回答