问题
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