




0001 function img = readBMP( fn ) 0002 f = fopen(fn,'r'); 0003 d = fread(f,'uint8=>uint8'); 0004 fclose(f); 0005 if char(d(1)) ~= 'B' || char(d(2)) ~= 'M' 0006 error 'BMP format markers are missing - probably not a BMP file'; 0007 end 0008 % Obtain width and height 0009 w = (256.^[0:3]) * double(d(23:26)); 0010 h = (256.^[0:3]) * double(d(19:22)); 0011 n = w*h*3; 0012 img = permute(reshape(d(end-n+1:end),[3 1280 1024]),[3 2 1]); 0013 % % Obtain data offset 0014 % ofs = (256.^[0:3]) * double(d(11:14)); 0015 % img = reshape( d(ofs+(1:w*h)), [h,w] ).';