From $ROOTSYS/tutorials/image/image2hist.C

//Create a 2-D histogram from an image.
//Author: Olivier Couet

void image2hist()
{
   TASImage image("rose512.jpg");
   UInt_t yPixels = image.GetHeight();
   UInt_t xPixels = image.GetWidth();
   UInt_t *argb   = image.GetArgbArray();

   TH2D* h = new TH2D("h","Rose histogram",xPixels,-1,1,yPixels,-1,1);

   for (int row=0; row<xPixels; ++row) {
      for (int col=0; col<yPixels; ++col) {
         int index = col*xPixels+row;
         float grey = float(argb[index]&0xff)/256;
         h->SetBinContent(row+1,yPixels-col,grey);
      }
   }
   
   gStyle->SetPalette(53);
   h->Draw("colz");
}
 image2hist.C:1
 image2hist.C:2
 image2hist.C:3
 image2hist.C:4
 image2hist.C:5
 image2hist.C:6
 image2hist.C:7
 image2hist.C:8
 image2hist.C:9
 image2hist.C:10
 image2hist.C:11
 image2hist.C:12
 image2hist.C:13
 image2hist.C:14
 image2hist.C:15
 image2hist.C:16
 image2hist.C:17
 image2hist.C:18
 image2hist.C:19
 image2hist.C:20
 image2hist.C:21
 image2hist.C:22
 image2hist.C:23
 image2hist.C:24