Image processing in root-projection

Supposse there is this image, which is a beam-spot

Is it possible in root to get the projection, across one axis, given a pixel on the other one?

For instance, go to pixel number N in x-axis, and compute the projection along the y-axis?

Is this possible in root?

Thank you very much in advance!

Hi,

you cannot “project an image”, but, having the input data at your disposal, you can fill a 2D histogram and obtain its projections along the x and y axes: root.cern.ch/root/html/TH2F.html

Cheers,
Danilo

root.cern.ch/root/htmldoc/tutor … ist.C.html

Thank you very much for your post!
Using this code I can indeed convert the image in a 2D histogram, although there is a malfunction with the palette.

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

void imageProcessingRoot()
{
TASImage image(“test.png”);
UInt_t yPixels = image.GetHeight();
UInt_t xPixels = image.GetWidth();
UInt_t *argb = image.GetArgbArray();

TH2D* h = new TH2D(“h”,“Beam Spot”,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(52);//grayscale
h->Draw(“colz”);
}[/code]

The thing is that, I don’t know how to project only one slice of the image accross one axis.
I can always use TProjectoin, but this includes the whole 2D-histogram and not the projection, given a certain pixel.

Yes it should be gray … I will try.

Yes you should use the projection methods defined in TH2 have a look to the help.

It is grey for me. May be you are using an old ROOT version.