FIX: in the last fwrite should be the transpose of the image array