function [img,header,tailer]=readimg(filename,nx,ny,type,head,tail,skip)

if nargin<=2 
  ny=nx;
  type=['unsigned char'];
  head=0;
  tail=0;
  skip=0;
elseif nargin<=3 
  type=['unsigned char'];
  head=0;
  tail=0;
  skip=0;
elseif nargin<=4
  head=0;
  tail=0;
  skip=0;
elseif nargin<=5
  tail=0;
  skip=0;
elseif nargin<=6
  skip=0;
end

bsize=nx*ny;

img=zeros(nx,ny);
[img(:) header tailer]=readraw(filename,bsize,type,head,tail,skip);
img=img';
