Greyscale histogram for adjusting contrast


I’d like to implement a tool that would be useful to improve the visibility of some images I am getting from a detector. The tool is standard in all image manipulation programmes, but I don’t know if it’s easy or even advisable to have it in ROOT. It usually looks like this:

As far as I understand the way the histograms (TH2D) are displayed now in my code, the smallest value in the histogram is mapped to a black colour, and the largest value is mapped to white.
I would like to have a tool that displays the histogram shown in the link, with two sliders that can change this default behaviour.

I think I could do it in the following way:

  • draw a TH1D with the distribution of the values in the image (easy enough)
  • add two “sliders” (maybe with TLine?) whose position can be changed with a click
  • get the position of the sliders and feed it to the parameters of TColor::CreateColorGradientTable() to change the greyscale
  • set the new palette in the new image

Would this work? Is there any more efficient way of doing that? Should I consider saving the data as TASImage instead of TH2D? I’m not doing that at the moment because I’m really using them as histograms (calculating profiles and projections, fitting functions etc.)

Yes that way would be ok.

I implemented this, actually with a TSlider, which is even nicer.

I can then successfully create a colour table, but apparently changing the style is not enough. Do I also have to re-draw the histogram?

Yes … or update the canvas. Note that only one palette is available at a time.

Updating the canvas is not working :frowning:

Try the sequence (with “YourCanvas” or the “gPad”):
YourCanvas->Modified(); YourCanvas->Update();

Yes, that made it! Thanks