// CPP includes #include #include #include #include #include #include #include #include #include // C includes #include #include #include #include // ROOT includes #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "TObjString.h" #include "TRandom3.h" #include "TGraph.h" #include "TGraphSmooth.h" #include "TSpline.h" #include "TImage.h" #include "TArrayD.h" #include "TPave.h" //#include "TPalette.h" // #include // #include using namespace std; #if defined (__CINT__) && !defined(__MAKECINT__) { gSystem->Load("libtiff.so"); gROOT->LoadMacro("tiff_test.C+"); run(); } #else #include #include void run(){ TCanvas*c1 = new TCanvas("c1","c1",500,500); TCanvas*c2 = new TCanvas("c2","c2",500,500); // TCanvas*c3 = new TCanvas("c3","c3",500,500); TH1::AddDirectory(kFALSE); TH1::AddDirectory(kFALSE); gStyle->SetOptStat(0); // gStyle->SetPalette(9909); gStyle->SetPalette(1); TImage *img = TImage::Open("/local/home/fbelloni/WORK/Archiver/13PS1\:image1\:ArrayData\ 0.png"); if (!img) { printf("Could not create an image... exit\n"); return; } c1->cd(); img->Draw("xxx"); cout <<"Height: " << img->GetHeight() << " pixels " <GetWidth() << " pixels" <GetHeight(); UInt_t xPixels = img->GetWidth(); UInt_t *argb = img->GetArgbArray(); TH2D*h = new TH2D("Image","Image",xPixels,0,xPixels,yPixels,0,yPixels); TH2D*h2 = new TH2D("Image2","Image2",xPixels,0,xPixels,yPixels,0,yPixels); ofstream myfile1; myfile1.open("test.txt"); int z = 0; for (int row=0; rowSetBinContent(row+1,yPixels-col,grey); //cout << (UInt_t(grey->GetRed()))<< endl; myfile1 << "row " << row +1 << " yPixels-col " << yPixels-col << " index " << float(argb[z]&0xff)<< endl; z++; // h->SetBinContent(row,col,float(argb[index])); // printf("%d %lf \n", index, float(argb[index]&0xffffff)); // myfile1 << index << " " << float(argb[index]&0xffffff)<< endl; // float grey = float(argb[index]&0xff)/256; // h->SetBinContent(row+1,yPixels-col,grey); } } c2->cd(); h->Draw("colz"); /* // scan all pixels in fore image and // make rgb1, rgb2 colors transparent. for (UInt_t i = 0; i < yPixels; i++) { for (UInt_t j = 0; j < xPixels; j++) { Int_t idx = i*xPixels + j; // RGB part of ARGB color UInt_t col = argb[idx] & 0xffffff; // 24..31 bits define transparency of the color in the range 0 - 0xff // for example, 0x00000000 - black color with 100% transparency // 0xff000000 - non-transparent black color cout << col <SetBinContent(i+1,j+1,col); // if ((col == rgb1) || (col == rgb2)) { // // argb[idx] = 0; // 100% transparent // } else { // argb[idx] = 0xff000000 + col; // make other pixels non-transparent // } } } c3->cd(); h2->Draw("colz"); gPad->Update(); TPalette *palette = (TPalette*)h2->GetListOfFunctions()->FindObject("palette"); Int_t ci = palette->GetBinColor(1,1); TColor *c = gROOT->GetColor(ci); float x,y,z; cout << c->GetRGB(x,y,z)<