SlideShare une entreprise Scribd logo
1  sur  7
function [X,map,out3]=bmpread(filename);

%BMPREAD Read a BMP (Microsoft Windows Bitmap) file from disk.

%      [X,MAP]=BMPREAD('filename') reads the file 'filename' and

%      returns the indexed image X and associated colormap

%      MAP. If no extension is given for the filename, the

%      extension '.bmp' is assumed.

%      [R,G,B]=BMPREAD('filename') reads the 24-bit BMP file

%      from the file 'filename'.

%      BPP=BMPREAD('filename') returns the number of bits per

%      pixel in the BMP file.

%

%      BMPREAD does not read 1-bit or compressed BMP files.

%

%      See also: BMPWRITE, GIFREAD, HDFREAD, PCXREAD, TIFFREAD,

%                XWDREAD.



%      Mounil Patel 3/10/94

%      Revised Steve Eddins February 9, 1995

%      Copyright (c) 1994 by The MathWorks, Inc.

%      $Revision: 1.14 $    $Date: 1996/06/14 12:39:07 $




if (nargin~=1)

       error('Requires a filename as an argument.');

end;



if (isstr(filename)~=1)

       error('Requires a string filename as an argument.');

end;



if (isempty(findstr(filename,'.'))==1)

       filename=[filename,'.bmp'];
end;



fid=fopen(filename,'rb','l');

if (fid==-1)

       error(['Error opening ',filename,' for input.']);

end;



bfType=fread(fid,2,'uchar');

if (bfType~=[66;77])

       fclose(fid);

       error('Not a BMP file.');

end;



bfSize=fread(fid,1,'uint');

bfReserved1=fread(fid,1,'ushort');

bfReserved2=fread(fid,1,'ushort');

bfOffBytes=fread(fid,1,'uint');



biSize=fread(fid,1,'uint');

if (biSize~=40)

       fclose(fid);

       error('Not a MS Windows Device Independent Bitmap BMP file.');

end;



biWidth=fread(fid,1,'uint');

biHeight=fread(fid,1,'uint');

biPlanes=fread(fid,1,'ushort');

biBitCount=fread(fid,1,'ushort');

if (biBitCount == 1)

  error('BMPREAD does not read 1-bit BMP files.');

end

biCompression=fread(fid,1,'uint');
if biCompression~=0

        error('Can''t load compressed format bitmaps.');

end;

biSizeImage=fread(fid,1,'uint');

biXPels=fread(fid,1,'uint');

biYPels=fread(fid,1,'uint');

biClrUsed=fread(fid,1,'uint');

biClrImportant=fread(fid,1,'uint');



if (nargout <= 1)

  X = biBitCount;

  map = [];

  fclose(fid);

  return;

end



if ((nargout == 2) & (biBitCount == 24))

  error('Three output arguments required for 24-bit BMP file.');

end



if ((nargout == 3) & (biBitCount < 24))

  error('Only two arguments needed for 4- and 8-bit BMP files.');

end



if (biBitCount == 24)

  if (rem(biWidth,4)~=0)

      XSize=biWidth+(4-rem(biWidth,4));

  else

      XSize=biWidth;

  end

  YSize=biHeight;

  Size=XSize*YSize;
fseek(fid, bfOffBytes, 'bof');

  X=fread(fid,Size*3,'uchar');

  out3 = rot90(reshape(X(1:3:length(X)), XSize, YSize)) * (1/255);

  map = rot90(reshape(X(2:3:length(X)), XSize, YSize)) * (1/255);

  X = rot90(reshape(X(3:3:length(X)), XSize, YSize)) * (1/255);

  if (rem(biWidth,4)~=0)

      X=X(:,1:biWidth);

      map = map(:,1:biWidth);

      out3 = out3(:,1:biWidth);

  end;



  fclose(fid);

  return;

end



if (biClrUsed==0)

       nColors=2.^biBitCount;

else

       nColors=biClrUsed;

end;



% load color map now

if (biClrUsed>256)

       map=[];      % 24-bit images have no colormap

else

       map=fread(fid,4*nColors,'uchar');

       map=reshape(map,4,nColors);

       map=map';

       map=map(:,1:3);

       map=fliplr(map);

end;
map=map./255;



% read in 8-bit image data

if (biBitCount==8)

       if (rem(biWidth,4)~=0)

              XSize=biWidth+(4-rem(biWidth,4));

       else

              XSize=biWidth;

       end

       YSize=biHeight;

       Size=XSize*YSize;



       fseek(fid, bfOffBytes, 'bof');

       X=fread(fid,Size,'uchar');

       X=reshape(X,XSize,YSize);

       X=rot90(X);

       X=X+1;

       if (rem(biWidth,4)~=0)

              X=X(:,1:biWidth);

       end;

end;



if (biBitCount==4)

       XSize=ceil(biWidth/2);

       if (rem(XSize,4)~=0)

              XSize=XSize+rem(XSize,4);

       end;

       YSize=biHeight;

       Size=XSize*YSize;

       fseek(fid, bfOffBytes, 'bof');

       X=fread(fid,Size,'uchar');
X=reshape(X,XSize,YSize);

       X=X';

       loX=X;



       index=loX>127;

       loX(index)=loX(index)-128;

       index=loX>63;

       loX(index)=loX(index)-64;

       index=loX>31;

       loX(index)=loX(index)-32;

       index=loX>15;

       loX(index)=loX(index)-16;



       X=X-loX;

       X=X./16;

       [m,n]=size(X);

       X(:,1:2:(n*2))=X;

       X(:,2:2:(n*2))=loX;

       X=flipud(X);

       X=X+1;

end;



cmax=max(max(X));

map=map(1:cmax,:);



fclose(fid);
X=reshape(X,XSize,YSize);

       X=X';

       loX=X;



       index=loX>127;

       loX(index)=loX(index)-128;

       index=loX>63;

       loX(index)=loX(index)-64;

       index=loX>31;

       loX(index)=loX(index)-32;

       index=loX>15;

       loX(index)=loX(index)-16;



       X=X-loX;

       X=X./16;

       [m,n]=size(X);

       X(:,1:2:(n*2))=X;

       X(:,2:2:(n*2))=loX;

       X=flipud(X);

       X=X+1;

end;



cmax=max(max(X));

map=map(1:cmax,:);



fclose(fid);

Contenu connexe

Tendances

Assignment3 solution 3rd_edition
Assignment3 solution 3rd_editionAssignment3 solution 3rd_edition
Assignment3 solution 3rd_edition
Mysore
 

Tendances (15)

Assignment3 solution 3rd_edition
Assignment3 solution 3rd_editionAssignment3 solution 3rd_edition
Assignment3 solution 3rd_edition
 
Geohex at Off4g2009
Geohex at Off4g2009Geohex at Off4g2009
Geohex at Off4g2009
 
imager package in R and examples..
imager package in R and examples..imager package in R and examples..
imager package in R and examples..
 
Basic Calculus in R.
Basic Calculus in R. Basic Calculus in R.
Basic Calculus in R.
 
Mosaic plot in R.
Mosaic plot in R.Mosaic plot in R.
Mosaic plot in R.
 
Mate tarea - 3º
Mate   tarea - 3ºMate   tarea - 3º
Mate tarea - 3º
 
Mate tarea - 2º
Mate   tarea - 2ºMate   tarea - 2º
Mate tarea - 2º
 
Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.
 
Hw #2
Hw #2Hw #2
Hw #2
 
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...
 
Rkf
RkfRkf
Rkf
 
8.1 algebra
8.1 algebra8.1 algebra
8.1 algebra
 
Gate level minimization (1st update)
Gate level minimization (1st update)Gate level minimization (1st update)
Gate level minimization (1st update)
 
Calc 7.3b
Calc 7.3bCalc 7.3b
Calc 7.3b
 
Interpolation graph c++
Interpolation graph c++Interpolation graph c++
Interpolation graph c++
 

En vedette

Sexual maturation
Sexual maturationSexual maturation
Sexual maturation
Daniel_OF
 

En vedette (15)

Kajian bahan ajar 1
Kajian bahan ajar 1Kajian bahan ajar 1
Kajian bahan ajar 1
 
ppcHIT Introduction
ppcHIT IntroductionppcHIT Introduction
ppcHIT Introduction
 
Kajian bahan ajar 1
Kajian bahan ajar 1Kajian bahan ajar 1
Kajian bahan ajar 1
 
Images of Life
Images of LifeImages of Life
Images of Life
 
2n1grup3
2n1grup32n1grup3
2n1grup3
 
Handout guru
Handout guruHandout guru
Handout guru
 
Graffiti en america
Graffiti en americaGraffiti en america
Graffiti en america
 
Istilah, pengertian & cakupan ideologi
Istilah, pengertian & cakupan ideologiIstilah, pengertian & cakupan ideologi
Istilah, pengertian & cakupan ideologi
 
Sexual maturation
Sexual maturationSexual maturation
Sexual maturation
 
Solr
SolrSolr
Solr
 
Panduan pelayanan-kerohanian-baru
Panduan pelayanan-kerohanian-baruPanduan pelayanan-kerohanian-baru
Panduan pelayanan-kerohanian-baru
 
Why are Good Theorys Good- Review
Why are Good Theorys Good- ReviewWhy are Good Theorys Good- Review
Why are Good Theorys Good- Review
 
Ppt komunikasi
Ppt komunikasiPpt komunikasi
Ppt komunikasi
 
Om 3 år, driver alle med Inbound markedsføring og salg? [Inbound Marketing]
Om 3 år, driver alle med Inbound markedsføring og salg? [Inbound Marketing]Om 3 år, driver alle med Inbound markedsføring og salg? [Inbound Marketing]
Om 3 år, driver alle med Inbound markedsføring og salg? [Inbound Marketing]
 
Om 3 år, driver alle med Inbound markedsføring og salg? [Inbound Marketing]
Om 3 år, driver alle med Inbound markedsføring og salg? [Inbound Marketing]Om 3 år, driver alle med Inbound markedsføring og salg? [Inbound Marketing]
Om 3 år, driver alle med Inbound markedsføring og salg? [Inbound Marketing]
 

Similaire à Bmpread

Company_X_Data_Analyst_Challenge
Company_X_Data_Analyst_ChallengeCompany_X_Data_Analyst_Challenge
Company_X_Data_Analyst_Challenge
Mark Yashar
 
Following are the changes mentioned in bold in order to obtain the r.pdf
Following are the changes mentioned in bold in order to obtain the r.pdfFollowing are the changes mentioned in bold in order to obtain the r.pdf
Following are the changes mentioned in bold in order to obtain the r.pdf
anithareadymade
 
Ee 3122 numerical methods and statistics sessional credit
Ee 3122 numerical methods and statistics sessional  creditEe 3122 numerical methods and statistics sessional  credit
Ee 3122 numerical methods and statistics sessional credit
Raihan Bin-Mofidul
 
Ans#define WM_CAP_START 0x0400 #define WM_CAP_DRIVER_CONNECT (W.pdf
Ans#define WM_CAP_START 0x0400 #define WM_CAP_DRIVER_CONNECT (W.pdfAns#define WM_CAP_START 0x0400 #define WM_CAP_DRIVER_CONNECT (W.pdf
Ans#define WM_CAP_START 0x0400 #define WM_CAP_DRIVER_CONNECT (W.pdf
aryan9007
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2go
Moriyoshi Koizumi
 
Cg my own programs
Cg my own programsCg my own programs
Cg my own programs
Amit Kapoor
 

Similaire à Bmpread (20)

Creating masterpieces with raphael
Creating masterpieces with raphaelCreating masterpieces with raphael
Creating masterpieces with raphael
 
Company_X_Data_Analyst_Challenge
Company_X_Data_Analyst_ChallengeCompany_X_Data_Analyst_Challenge
Company_X_Data_Analyst_Challenge
 
Cquestions
Cquestions Cquestions
Cquestions
 
Following are the changes mentioned in bold in order to obtain the r.pdf
Following are the changes mentioned in bold in order to obtain the r.pdfFollowing are the changes mentioned in bold in order to obtain the r.pdf
Following are the changes mentioned in bold in order to obtain the r.pdf
 
Computer hw1
Computer hw1Computer hw1
Computer hw1
 
Ee 3122 numerical methods and statistics sessional credit
Ee 3122 numerical methods and statistics sessional  creditEe 3122 numerical methods and statistics sessional  credit
Ee 3122 numerical methods and statistics sessional credit
 
Ans#define WM_CAP_START 0x0400 #define WM_CAP_DRIVER_CONNECT (W.pdf
Ans#define WM_CAP_START 0x0400 #define WM_CAP_DRIVER_CONNECT (W.pdfAns#define WM_CAP_START 0x0400 #define WM_CAP_DRIVER_CONNECT (W.pdf
Ans#define WM_CAP_START 0x0400 #define WM_CAP_DRIVER_CONNECT (W.pdf
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2go
 
tensorflow/keras model coding tutorial 勉強会
tensorflow/keras model coding tutorial 勉強会tensorflow/keras model coding tutorial 勉強会
tensorflow/keras model coding tutorial 勉強会
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
Computer graphics File for Engineers
Computer graphics File for EngineersComputer graphics File for Engineers
Computer graphics File for Engineers
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph
 
My bitmap
My bitmapMy bitmap
My bitmap
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C Programs
 
Cg my own programs
Cg my own programsCg my own programs
Cg my own programs
 
include.docx
include.docxinclude.docx
include.docx
 
C questions
C questionsC questions
C questions
 
Otsu
OtsuOtsu
Otsu
 
R meets Hadoop
R meets HadoopR meets Hadoop
R meets Hadoop
 
Save game function
Save game functionSave game function
Save game function
 

Dernier

Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 

Dernier (20)

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 

Bmpread

  • 1. function [X,map,out3]=bmpread(filename); %BMPREAD Read a BMP (Microsoft Windows Bitmap) file from disk. % [X,MAP]=BMPREAD('filename') reads the file 'filename' and % returns the indexed image X and associated colormap % MAP. If no extension is given for the filename, the % extension '.bmp' is assumed. % [R,G,B]=BMPREAD('filename') reads the 24-bit BMP file % from the file 'filename'. % BPP=BMPREAD('filename') returns the number of bits per % pixel in the BMP file. % % BMPREAD does not read 1-bit or compressed BMP files. % % See also: BMPWRITE, GIFREAD, HDFREAD, PCXREAD, TIFFREAD, % XWDREAD. % Mounil Patel 3/10/94 % Revised Steve Eddins February 9, 1995 % Copyright (c) 1994 by The MathWorks, Inc. % $Revision: 1.14 $ $Date: 1996/06/14 12:39:07 $ if (nargin~=1) error('Requires a filename as an argument.'); end; if (isstr(filename)~=1) error('Requires a string filename as an argument.'); end; if (isempty(findstr(filename,'.'))==1) filename=[filename,'.bmp'];
  • 2. end; fid=fopen(filename,'rb','l'); if (fid==-1) error(['Error opening ',filename,' for input.']); end; bfType=fread(fid,2,'uchar'); if (bfType~=[66;77]) fclose(fid); error('Not a BMP file.'); end; bfSize=fread(fid,1,'uint'); bfReserved1=fread(fid,1,'ushort'); bfReserved2=fread(fid,1,'ushort'); bfOffBytes=fread(fid,1,'uint'); biSize=fread(fid,1,'uint'); if (biSize~=40) fclose(fid); error('Not a MS Windows Device Independent Bitmap BMP file.'); end; biWidth=fread(fid,1,'uint'); biHeight=fread(fid,1,'uint'); biPlanes=fread(fid,1,'ushort'); biBitCount=fread(fid,1,'ushort'); if (biBitCount == 1) error('BMPREAD does not read 1-bit BMP files.'); end biCompression=fread(fid,1,'uint');
  • 3. if biCompression~=0 error('Can''t load compressed format bitmaps.'); end; biSizeImage=fread(fid,1,'uint'); biXPels=fread(fid,1,'uint'); biYPels=fread(fid,1,'uint'); biClrUsed=fread(fid,1,'uint'); biClrImportant=fread(fid,1,'uint'); if (nargout <= 1) X = biBitCount; map = []; fclose(fid); return; end if ((nargout == 2) & (biBitCount == 24)) error('Three output arguments required for 24-bit BMP file.'); end if ((nargout == 3) & (biBitCount < 24)) error('Only two arguments needed for 4- and 8-bit BMP files.'); end if (biBitCount == 24) if (rem(biWidth,4)~=0) XSize=biWidth+(4-rem(biWidth,4)); else XSize=biWidth; end YSize=biHeight; Size=XSize*YSize;
  • 4. fseek(fid, bfOffBytes, 'bof'); X=fread(fid,Size*3,'uchar'); out3 = rot90(reshape(X(1:3:length(X)), XSize, YSize)) * (1/255); map = rot90(reshape(X(2:3:length(X)), XSize, YSize)) * (1/255); X = rot90(reshape(X(3:3:length(X)), XSize, YSize)) * (1/255); if (rem(biWidth,4)~=0) X=X(:,1:biWidth); map = map(:,1:biWidth); out3 = out3(:,1:biWidth); end; fclose(fid); return; end if (biClrUsed==0) nColors=2.^biBitCount; else nColors=biClrUsed; end; % load color map now if (biClrUsed>256) map=[]; % 24-bit images have no colormap else map=fread(fid,4*nColors,'uchar'); map=reshape(map,4,nColors); map=map'; map=map(:,1:3); map=fliplr(map); end;
  • 5. map=map./255; % read in 8-bit image data if (biBitCount==8) if (rem(biWidth,4)~=0) XSize=biWidth+(4-rem(biWidth,4)); else XSize=biWidth; end YSize=biHeight; Size=XSize*YSize; fseek(fid, bfOffBytes, 'bof'); X=fread(fid,Size,'uchar'); X=reshape(X,XSize,YSize); X=rot90(X); X=X+1; if (rem(biWidth,4)~=0) X=X(:,1:biWidth); end; end; if (biBitCount==4) XSize=ceil(biWidth/2); if (rem(XSize,4)~=0) XSize=XSize+rem(XSize,4); end; YSize=biHeight; Size=XSize*YSize; fseek(fid, bfOffBytes, 'bof'); X=fread(fid,Size,'uchar');
  • 6. X=reshape(X,XSize,YSize); X=X'; loX=X; index=loX>127; loX(index)=loX(index)-128; index=loX>63; loX(index)=loX(index)-64; index=loX>31; loX(index)=loX(index)-32; index=loX>15; loX(index)=loX(index)-16; X=X-loX; X=X./16; [m,n]=size(X); X(:,1:2:(n*2))=X; X(:,2:2:(n*2))=loX; X=flipud(X); X=X+1; end; cmax=max(max(X)); map=map(1:cmax,:); fclose(fid);
  • 7. X=reshape(X,XSize,YSize); X=X'; loX=X; index=loX>127; loX(index)=loX(index)-128; index=loX>63; loX(index)=loX(index)-64; index=loX>31; loX(index)=loX(index)-32; index=loX>15; loX(index)=loX(index)-16; X=X-loX; X=X./16; [m,n]=size(X); X(:,1:2:(n*2))=X; X(:,2:2:(n*2))=loX; X=flipud(X); X=X+1; end; cmax=max(max(X)); map=map(1:cmax,:); fclose(fid);