% --------------------------------------------------------------------------- % Function grload() % -- Xenios Papademetris papad@noodle.med.yale.edu 5th Sep 1995 % % -- used to load images stored in the simple format (.grl) used for the % -- EE445a course, this has an unsigned short magic number (29571) % -- and the width and height of the image in 4-byte integers % -- followed by the actual data in unsigned char format % -- Changed 28th Jan 1997 to test for big-endian / little endian formats % --------------------------------------------------------------------------- function outimage=grload(filename) % --------------------------------------------------------------------------- % Step 1 -- Check for right number of parameters % -- and check for valid filename % --------------------------------------------------------------------------- if nargin ~= 1 error('Requires one input argument eg grload(filename)'); elseif nargin == 1 & isstr(filename) if (isempty(findstr(filename,'.'))==1) filename=[filename,'.grl']; end end % --------------------------------------------------------------------------- % Step 2 -- Open filename % -- Check for valid file % --------------------------------------------------------------------------- handle=fopen(filename,'r'); if handle == -1 ff=['grload::cannot open file ' , filename]; error (ff); end magic=fread(handle,1,'ushort'); if (magic~=29571 & magic ~=33651) ff=['grload::file ' , filename,' is not a grl file']; error (ff); end % --------------------------------------------------------------------------- % Step 3 -- Read width and height % --------------------------------------------------------------------------- %width=fread(handle,1,'int32') %height=fread(handle,1,'int32') w1=fread(handle,1,'uchar'); w2=fread(handle,1,'uchar'); w3=fread(handle,1,'uchar'); w4=fread(handle,1,'uchar'); width=w1*2^24+w2*2^16+w3*2^8+w4; if (width>4096) width=w4*2^24+w3*2^16+w2*2^8+w1; end h1=fread(handle,1,'uchar'); h2=fread(handle,1,'uchar'); h3=fread(handle,1,'uchar'); h4=fread(handle,1,'uchar'); height=h1*2^24+h2*2^16+h3*2^8+h4; if (height>4096) height=h4*2^24+h3*2^16+h2*2^8+h1; end % --------------------------------------------------------------------------- % Step 4 -- Read actual Image % --------------------------------------------------------------------------- outimage=fread(handle,[height,width],'uchar'); outimage=outimage'/max(max(outimage)); % --------------------------------------------------------------------------- % Step 5 -- Close file % --------------------------------------------------------------------------- fclose(handle); % ---------------------------------------------------------------------------