Fixed pixel order problem for non-square images.  Had (nx,ny) instead of necessary (ny,nx) row-major ordering.