Dear all,
I am trying to print out each pixel value of a TIFF image. I read some posts, but
it is the first time I work with images. I tried the following, but I get the same value for each pixel.
void run(){
TH1::AddDirectory(kFALSE);
TH1::AddDirectory(kFALSE);
gStyle->SetOptStat(0);
TImage *img = TImage::Open("../Door.tiff");
if (!img) {
printf("Could not create an image... exit\n");
return;
}
//img->Draw("xxx");
cout <<"Height: " << img->GetHeight() << " pixels " <<endl;
cout <<"Width: " << img->GetWidth() << " pixels" <<endl;
UInt_t yPixels = img->GetHeight();
UInt_t xPixels = img->GetWidth();
UInt_t *argb = img->GetArgbArray();
for (int row=0; row<xPixels; ++row) {
for (int col=0; col<yPixels; ++col) {
int index = col*xPixels+row;
cout << index << " " << float(argb[index]&0xff)/256<< endl;
}
}
}
Why are you doing this operation? If you get the same value everywhere, this is the first suspect to check, since you are only considering the lowest 2 bytes of your data (while integers are 4 bytes wide). It’s proabably a good idea to follow the example linked above.
So, I understood, once you have the results of GetRed(), GetGreen() and GetBlue() how to get the decimal 14531207
(i.e. you make GetRed()* 255* 2^16+GetGreen()* 255 * 2^8 +GetBlue()* 255 * 2^0).
But when I read the result of cout << "bk1 " << bk1 << endl; which is “0x1e29bd0” … How is this number related to 221./255, 186./255, 135./255 please?
In other words, 0x1e29bd0 gives you the fractions of red,green and blue. How do you obtain such fractions from 0x1e29bd0, please?
I am not sure I fully understand your question. Imagine I open a canvas, the background is white. If I get the background color and then get the value of red green and blue I get 1 1 1 …ie: white.
root [0] TCanvas C;
root [1] TColor *bk1 = gROOT->GetColor(gPad->GetFillColor());
root [2] printf("R = %g G = %g B = %g\n",bk1->GetRed(), bk1->GetGreen(), bk1->GetBlue());
R = 1 G = 1 B = 1
root [3]
If the background is white and you ask cout <<bk1 <<< endl;
you get 0x1f415e0
If you then ask
printf(“R = %g G = %g B = %g\n”,bk1->GetRed(), bk1->GetGreen(), bk1->GetBlue());
you get
R = 1 G = 1 B = 1
But how is 0x1f415e0 related to R=1 B=1 G=1, please?
The functions GetRed(), GetGreen() and GetBlue() makes this "translation’ for me. But
how is the translation made, pls?