I use: ROOT 6.02/08
Generally my plan was to make normal C++ program, but it did not want to work so I made a script.
Dear ROOT Wizards,
What I want to do:
I generate pictures with peaks using tutorial peaks2.C . I convert them into files.png in grey scale (gStyle->SetPalette(52) - I would like to use 16 bit grey scale, but this is another problem). I cut them so I receive something which looks like a photo from a black and white camera (this is my camera simulation). That part works perfectly.
Than I want to read generated pictures, convert them to histograms and find peaks. That part does not work.
This is my code:
#include <all needed libraries>
using namespace std;
void picture(){
TCanvas *c2 = new TCanvas("c2","c2",600,400);
TImage * img = TImage::Open("histogram.png");
if (!img) {
printf("Could not create an image... exit\n");
return;
}
int height = img -> GetHeight();
int width = img -> GetWidth();
UInt_t *argb = img->GetArgbArray();
TH2F* h = new TH2F("h","argbArray",width,0,width,height,0,height);
// gStyle->SetPalette(52);
for (int row=0; row<width; ++row) {
for (int col=0; col<height; ++col) {
int index = col*width+row;
float grey = float(argb[index]&0xFF)/256;
h->SetBinContent(row+1,height-col,grey);
}
}
h->Draw();
TSpectrum2 *s = new TSpectrum2();
h->Draw("col");
int nfound = s->Search(h,2);
printf("Found %d candidate peaks\n",nfound);
s->Print();
c2->WaitPrimitive();
}
My problem: when the code is like that and I want to draw my histogram I receive completely black histogram and no peaks are found.
When I use: "h->Draw(“col”) - I see peaks on the Picture, but in RGB scale and still no peaks are found.
My question: how can I convert my picture to the histogram to receive correct results in grey scale?
I did almost the same things like in an example peaks2.C . However, as the tutorial works perfectly, my program does not.
I tried to use different colour palettes and simple getarray, but probably I am doing a lot of mistakes that is why it does not work:
TImagePalette pal = img->GetPalette();
TArrayD arg = img -> GetArray(width,height,&pal);
TH2F h = new TH2F(“h”,“argbArray”,width,0,width,height,0,height);
for (int row=0; row<width; ++row) {
for (int col=0; col<height; ++col) {
int index = col*width+row;
float grey = float(arg[index]&0xFF)/256; //HERE I HAVE CONVERSION PROBLEM WHICH I DO NOT KNOW HOW TO SOLVE
h->SetBinContent(row+1,height-col,grey);
}
}
Thank you in advance!
Attached you will find histogram.png which is my test file.