%
% The image is in the current directory in the file lena.bin.
% It is 256x256, one byte per pixel.
%

fid = fopen('lena.bin','r');
[x,nbytes] = fread(fid,[256,256],'uchar');

%
% x now holds the image, nbytes gives the number of bytes read 
%           - should be 65536
% use this to detect if the file is not complete or the image is of the 
% wrong size.

nbytes

%
% Matlab reads the image in 'transposed' order with rows and columns reversed.
% Fix this.

x = x';

%
% Display the image
%
colormap(gray(256));
image(x);
axis('image');

%
% save the image in the file lena2.ps in postscript format that can be 
% printed by itself
print -dps lena2.ps

%
% save image in the file lena3.eps in encapsulated postscript format that 
% is good for including in other documents but can't be printed by itself
print -deps lena3.eps

%
% save image in jpeg format.  Can also save as tiff... 
%   type 'help print' for more info
%
print -djpeg lena4.jpg
