2

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

Amro
  • 123,847
  • 25
  • 243
  • 454
Brian Vandenberg
  • 4,011
  • 2
  • 37
  • 53
  • how are you generating your frames? It looks like each row is being circularly shifted by the row index. – abcd Apr 29 '11 at 18:38
  • I'm generating the frames with `imagesc`. The parameter is just a (reshaped) weight matrix. However, your comment gave me an idea. The picture I've posted here I chose for the sake of giving something indisputably messed up, whereas the weight visualization someone might've considered normal. The weights are similarly skewed, but there's a single black line that cuts from top right to bottom left. I bet it's adding an extra column of pixels to the output frames. – Brian Vandenberg Apr 29 '11 at 20:44

1 Answers1

3

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.

Brian Vandenberg
  • 4,011
  • 2
  • 37
  • 53