Logo ROOT   6.10/09
Reference Guide
image2hist.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_image
3 /// \notebook
4 /// Create a 2-D histogram from an image.
5 ///
6 /// \macro_image
7 /// \macro_code
8 ///
9 /// \author Olivier Couet
10 
11 void image2hist()
12 {
13  TASImage image("$ROOTSYS/tutorials/image/rose512.jpg");
14  UInt_t yPixels = image.GetHeight();
15  UInt_t xPixels = image.GetWidth();
16  UInt_t *argb = image.GetArgbArray();
17 
18  TH2D* h = new TH2D("h","Rose histogram",xPixels,-1,1,yPixels,-1,1);
19 
20  for (int row=0; row<xPixels; ++row) {
21  for (int col=0; col<yPixels; ++col) {
22  int index = col*xPixels+row;
23  float grey = float(argb[index]&0xff)/256;
24  h->SetBinContent(row+1,yPixels-col,grey);
25  }
26  }
27 
29  h->Draw("colz");
30 }
Image class.
Definition: TASImage.h:31
R__EXTERN TStyle * gStyle
Definition: TStyle.h:402
TH1 * h
Definition: legend2.C:5
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2851
unsigned int UInt_t
Definition: RtypesCore.h:42
THist< 2, double, THistStatContent, THistStatUncertainty > TH2D
Definition: THist.hxx:316
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content.
Definition: TH2.cxx:2471
void SetPalette(Int_t ncolors=kBird, Int_t *colors=0, Float_t alpha=1.)
See TColor::SetPalette.
Definition: TStyle.cxx:1460
tomato 2-D histogram with a double per channel (see TH1 documentation)}
Definition: TH2.h:290