SlideShare uma empresa Scribd logo
1 de 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);

Mais conteúdo relacionado

Mais procurados

Assignment3 solution 3rd_edition
Assignment3 solution 3rd_editionAssignment3 solution 3rd_edition
Assignment3 solution 3rd_editionMysore
 
imager package in R and examples..
imager package in R and examples..imager package in R and examples..
imager package in R and examples..Dr. Volkan OBAN
 
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.Dr. Volkan OBAN
 
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...Mozaic Works
 
Gate level minimization (1st update)
Gate level minimization (1st update)Gate level minimization (1st update)
Gate level minimization (1st update)Aravir Rose
 
Interpolation graph c++
Interpolation graph c++Interpolation graph c++
Interpolation graph c++rpiitcbme
 

Mais procurados (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++
 

Destaque

ppcHIT Introduction
ppcHIT IntroductionppcHIT Introduction
ppcHIT Introductionsortivo
 
Istilah, pengertian & cakupan ideologi
Istilah, pengertian & cakupan ideologiIstilah, pengertian & cakupan ideologi
Istilah, pengertian & cakupan ideologiakucintaalloh
 
Sexual maturation
Sexual maturationSexual maturation
Sexual maturationDaniel_OF
 
Panduan pelayanan-kerohanian-baru
Panduan pelayanan-kerohanian-baruPanduan pelayanan-kerohanian-baru
Panduan pelayanan-kerohanian-baruAmat Brandals
 
Why are Good Theorys Good- Review
Why are Good Theorys Good- ReviewWhy are Good Theorys Good- Review
Why are Good Theorys Good- ReviewSinu G S
 
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]Øyvind Jacobsen
 
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]Øyvind Jacobsen
 

Destaque (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]
 

Semelhante a Bmpread

Creating masterpieces with raphael
Creating masterpieces with raphaelCreating masterpieces with raphael
Creating masterpieces with raphaelPippi Labradoodle
 
Company_X_Data_Analyst_Challenge
Company_X_Data_Analyst_ChallengeCompany_X_Data_Analyst_Challenge
Company_X_Data_Analyst_ChallengeMark 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.pdfanithareadymade
 
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 creditRaihan 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.pdfaryan9007
 
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/c2goMoriyoshi Koizumi
 
tensorflow/keras model coding tutorial 勉強会
tensorflow/keras model coding tutorial 勉強会tensorflow/keras model coding tutorial 勉強会
tensorflow/keras model coding tutorial 勉強会RyoyaKatafuchi
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manualUma mohan
 
Computer graphics File for Engineers
Computer graphics File for EngineersComputer graphics File for Engineers
Computer graphics File for Engineersvarun arora
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graphkinan keshkeh
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsKandarp Tiwari
 
Cg my own programs
Cg my own programsCg my own programs
Cg my own programsAmit Kapoor
 
include.docx
include.docxinclude.docx
include.docxNhiPtaa
 

Semelhante a 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
 

Último

Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 

Último (20)

Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 

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);