ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
image2hist.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_image
3 /// Create a 2-D histogram from an image.
4 ///
5 /// \macro_image
6 /// \macro_code
7 ///
8 /// \author Olivier Couet
9 
10 void image2hist()
11 {
12  TASImage image("$ROOTSYS/tutorials/image/rose512.jpg");
13  UInt_t yPixels = image.GetHeight();
14  UInt_t xPixels = image.GetWidth();
15  UInt_t *argb = image.GetArgbArray();
16 
17  TH2D* h = new TH2D("h","Rose histogram",xPixels,-1,1,yPixels,-1,1);
18 
19  for (int row=0; row<xPixels; ++row) {
20  for (int col=0; col<yPixels; ++col) {
21  int index = col*xPixels+row;
22  float grey = float(argb[index]&0xff)/256;
23  h->SetBinContent(row+1,yPixels-col,grey);
24  }
25  }
26 
28  h->Draw("colz");
29 }
tuple row
Definition: mrt.py:26
Image class.
Definition: TASImage.h:33
R__EXTERN TStyle * gStyle
Definition: TStyle.h:423
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2878
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content.
Definition: TH2.cxx:2699
void SetPalette(Int_t ncolors=kBird, Int_t *colors=0, Float_t alpha=1.)
See TColor::SetPalette.
Definition: TStyle.cxx:1445
const char Int_t const char * image
Definition: TXSlave.cxx:46
2-D histogram with a double per channel (see TH1 documentation)}
Definition: TH2.h:297