Author Topic: Stupid question of the week.. Histogram Transformation  (Read 7054 times)

Offline Phil Leigh

  • PixInsight Addict
  • ***
  • Posts: 220
I've been struggling all day with an image taken by someone else where the RGB levels are messed up.  What I'd like to know is this: with HT you can choose an RGB channel and move the centre peak of the histogram curve right or left with the mid tone control... Great. Is there any way to make the peak higher or lower and make the spread of the histogram curve narrower or wider without moving the left/right position of the peak?
Basically what I'm asking is how do I get full control over the shape of the histogram curves.

Sorry if this is a stupid question,
Regards
Phil

Offline bianry

  • PixInsight Enthusiast
  • **
  • Posts: 90
Re: Stupid question of the week.. Histogram Transformation
« Reply #1 on: 2014 March 26 14:51:24 »
I don't think you can make the peak higher or lower. The histogram is a measure of how many pixels have a certain RGB value. The higher the peak the more pixels. Only way to get a higher/lower peak would be adding/removing data. Also, as I understand it, moving the mid tone control moves the peak by stretching the histogram. So the toe of the curve will also be affected.
You can move a R,G,B peak separately with PixelMath. Member Gerald has a good PixelMath video demonstrating this.
http://www.werbeagentur.org/oldwexi/PixInsight/PixInsight.html

regards

Mats

Offline Phil Leigh

  • PixInsight Addict
  • ***
  • Posts: 220
Re: Stupid question of the week.. Histogram Transformation
« Reply #2 on: 2014 March 27 10:02:55 »
Thanks - see I said it was a stupid question...but...

I understand now that you can't raise/lower the peak without losing or inventing data.

But what about the width of the area under the (fixed) peak? - is there a way to widen/narrow the area?

DSS can do it...(seemingly)

thanks
Phil

Offline bianry

  • PixInsight Enthusiast
  • **
  • Posts: 90
Re: Stupid question of the week.. Histogram Transformation
« Reply #3 on: 2014 March 27 10:18:49 »
I am skating on thin ice here.... but anyway.

The peak is no more or less fixed than the toe. The histogram shows how many pixels are of a certain value. If normalized as PI does all values are 0..1 0 being black and 1 being saturated. If your red curve starts rising at say 0.002 then it means that there are no pixels with red data that has a lower value than 0.002.
If you want to widen the curve you stretch it. Ie convert the image to non-linear. As I understand it, what happens when we stretch an image by moving the midpoint is that the readout is moved. What should have been say 0.03 now reads 0.07. So the image gets lighter.

I can't see how DSS could do anything else than this. Then there are other means of stretching. Gamma-strecthing and whatever they are called.

The same thing happens when you use the Curve tool. You are moving the readout points and getting a lighter/darker/ more constrasty image. What you can't do with curves or Histogramstretch is inventing data that is not there. You can destroy data very easily by clipping the high or low point.

http://www.luminous-landscape.com/tutorials/understanding-series/understanding-histograms.shtml

I hope someone with deeper knowledge on this subject will take part in this discussion as I also would sometimes very much like to get the toes of the RGB-curves to line up better.

Regards

Mats

Offline IanL

  • PixInsight Addict
  • ***
  • Posts: 116
    • The Imaging Toolbox
Re: Stupid question of the week.. Histogram Transformation
« Reply #4 on: 2014 March 27 13:04:14 »
First it is worth reminding yourself what the histogram is and what it is not.  This explains it:

http://www.blackwaterskies.co.uk/2013/12/how-to-interpret-image-histogram.html

Secondly, it is also important to understand that the histogram transformation process and the curves process are functionally equivalent.  All they do is apply a transfer function to the image.  Basically you have a curve on a graph, with the input values on one axis and the output values on the other axis.  Both axes would have a range of values representing the full range of 8, 14, 16 bit values for the image (or whatever range is appropriate for the image format).

To perform the transfer, you just read up from the X axis from each possible pixel value to intercept the transfer curve, and then across to the Y axis to find the new value. Every pixel that had a value of (say) 1,000 is converted to a new value of (say) 1,500, and from 1,001 to 1,503, etc.  As you transform values, the histogram of the new image will change shape to reflect the newly transformed set of pixels.

The histogram transformation process applies a simple mid-tone transfer function, whereby you change the shape of the curve by moving the ends (the black and white points) plus a third point which is the mid-tone slider.  The curves tool allows you to create an arbitrary number of control points to build a more complex curve shape.  It is perfectly possible to create a mid-tones transfer function using the curves tool, but you can't create a more complex curve in the HT tool as you only have three fixed control points on the curve.

When dealing with an RGB image, you can create three MTF curves (using the HT tool) or and ditto you can create three different curves for RGB in the curves tool, one for each of the colour channels.  Doing so will shift the colour balance in the image. (Or you can create one MTF or curve to apply to all three channels equally, preserving the current colour balance).

Sticking with the HT tool for now:

- If you want to make the histogram narrower, you can drag the black and white points in towards the centre.  At some point you may start clipping the darkest / brightest pixels - essentially the start or end of the transfer curve is flat and every pixel below the black point is mapped to zero, and everything above the white point is mapped to the highest available value.  This is usually a bad thing because you have now lost information in the image.

- The only other option is to move the mid-tones slider.  As you move it you will tend to spread out or make narrower the histogram peak, and as a result you will make the peak higher or lower.

All that said, your problem is that you want to colour balance the image, but basically you are concentrating on completely the wrong thing.  The height of the colour peaks is not relevant to a good colour balance in an astro image.  Your aim is to align the three RGB peaks as best you can and you should then have a good colour balance.

There is a really easy way to do this:

- Open the ScreenTransferFunction process from the process menu (don't use the icons on the toolbar).
- Now click the 'radioactive' icon in the process window to apply a basic STF.  (Click the 'chain' icon just above in the process window to unlink the channels if you don't have good colour balance, or leave them linked if you do).
- You should now have your image showing with a suitable STF.
- Next open the HistogramTransformation process and start the real-time preview.
- Drag the blue triangle from the ScreenTransferFunction process window to the bottom bar of the HistogramTransformation process.  This will transfer the STF parameters to the HT process and give you a reasonable starting point for doing the stretch.
- A this point the preview window will white out or be massively over-stretched, because you have double-applied the stretch (once from the active STF and once from the HT preview).
- You now just need to de-activate the STF - close the STF process and if necessary click the icon next to the radiation icon on the toolbar to clear the active STF.
- You should find the preview now shows a similar result to what you had when you first applied the STF, i.e. a good starting stretch.
- Now tweak the HT process as you wish to get a better stretch - you should only need to tweak the K curve (applied to all three channels) and leave the individual RGB curves alone to retain the new colour balance.
- Finally drag the blue triangle from the HT process to the image window to apply the stretch.
- Save the image and when you re-open it later, you should find it has the stretch applied as you'd expect.

Offline sctall

  • PixInsight Enthusiast
  • **
  • Posts: 88
  • scott
Re: Stupid question of the week.. Histogram Transformation
« Reply #5 on: 2014 March 28 08:30:12 »
That is an excellent article Ian.
The one thing I got from it , was to open up your histogram and see exactly where you at.

So I take images from a fairlly LP skies. Is there a way I can use PI to open and examine the histogram levels when taking images with .CR2 RAW files.
Without any processing, just to examine.
I know I can use HT to look at the RAW, but I never really see anything, except all smashed up on the Left end.
I have to use the MT slider to stretch to see. But at this point I think I lost what I am trying to accomplish.
It does not look at all like the Hist on the camera or APT for that matter.

How can I get a feel of what I want my sub exposures to look like?

Does anyone have some ideas that I could use to check this out?
I use APT and the histograms are somewhat small, so I might be missing some small peaks. And I don't want to oversaturate.

Scott T.
ES102, WO GT81, astronomics, guide scope  CEM60
ASI120MC, ASI224MC, ASI178MM
Lunt60 SS,  moonlight focuser
LX200GPS

Offline Carlos Milovic

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2172
  • Join the dark side... we have cookies
    • http://www.astrophoto.cl
Re: Stupid question of the week.. Histogram Transformation
« Reply #6 on: 2014 March 28 10:13:12 »
The histogram on the camera and APT are made with debayered/stretched/color balanced data (with your camera's color balance settings). It is not an accurate representation of the raw data.
Regards,

Carlos Milovic F.
--------------------------------
PixInsight Project Developer
http://www.pixinsight.com

Offline sctall

  • PixInsight Enthusiast
  • **
  • Posts: 88
  • scott
Re: Stupid question of the week.. Histogram Transformation
« Reply #7 on: 2014 March 28 11:47:25 »
So what is a good way to examine it?

I have attached 2 screenshots.
1.  1 RAW 4 min sub with no stretch. As it shows in HTT on a reset
2.  Same RAW sub but stretched.
I am not concerned with the color balance here.  I have a LP filter.  IDAS

Is #1 good. To be slightly off the Left edge.
Or is there something else I can look at to quickly get a good idea with.

Scott T.
ES102, WO GT81, astronomics, guide scope  CEM60
ASI120MC, ASI224MC, ASI178MM
Lunt60 SS,  moonlight focuser
LX200GPS

Offline pfile

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 4729
Re: Stupid question of the week.. Histogram Transformation
« Reply #8 on: 2014 March 28 11:58:57 »
as you probably know, there are DSLR rules of thumb. the main one is that if your back of camera histogram is 'well detached' (some people say left foot 20% over, some 30% over) then you have cleared the read noise and the subexposure length is "good enough". i guess to be safe here, one should use the canon software to debayer and stretch the image if you want to examine the histogram in software. by "stretch" here i mean simply the stretch that the camera firmware or the canon DPP software does *by default*. all terrestrial image processing packages debayer and stretch the sensor data whether you like it or not, including the camera firmware when it is showing you the histogram on the LCD.

if you want to examine the linear histograms, then it's probably better to just use statistics to determine if you have cleared the read noise. there are a lot of articles out there about how to determine the read noise of your sensor. there's even a script in PI called CalculateSkyLimitedExposure which will help you determine your minimum subexposure length to get good stacking efficiency. however, i used to expose much longer than that script calculated simply because i had more headroom and was willing to bring in shorter exposures for stars and any other stuff that got overexposed.

rob

Offline Harry page

  • PTeam Member
  • PixInsight Jedi Knight
  • *****
  • Posts: 1458
    • http://www.harrysastroshed.com
Re: Stupid question of the week.. Histogram Transformation
« Reply #9 on: 2014 March 28 12:03:57 »
Hi

We are approaching the problem from the wrong way , colour imbalance is common in astrophotography

Pixinsight has tools to combat this mainly with the use of DBE , BN and colour correction  :-*

When this is done correctly arbitrary fiddling with the histogram  will not be needed  :-*

There are vids on my web site showing you how to do this

Regards

Harry
Harry Page

Offline Phil Leigh

  • PixInsight Addict
  • ***
  • Posts: 220
Re: Stupid question of the week.. Histogram Transformation
« Reply #10 on: 2014 March 29 02:16:27 »
Harry,
It was the fact that DBE+BN+CC left me with nicely lined-up RGB histograms but a visibly bad red cast that prompted me to start fiddling with the HT tool. I've never had this issue with images I've taken myself...and despite appearances I am relatively proficient in Pi  :)

regards
Phil

Offline dmdimon

  • Newcomer
  • Posts: 3
Re: Stupid question of the week.. Histogram Transformation
« Reply #11 on: 2014 March 29 08:55:46 »
Basically what I'm asking is how do I get full control over the shape of the histogram curves.
HT just can not give you FULL control over histogram - curves instrument invented exactly for this task.

Offline Harry page

  • PTeam Member
  • PixInsight Jedi Knight
  • *****
  • Posts: 1458
    • http://www.harrysastroshed.com
Re: Stupid question of the week.. Histogram Transformation
« Reply #12 on: 2014 March 29 14:00:06 »
Hi

This vid shows you how to correct any further colour casts   http://harrysastroshed.com/RGB%20Combination.html   :-*


Regards

Harry
Harry Page

Offline Phil Leigh

  • PixInsight Addict
  • ***
  • Posts: 220
Re: Stupid question of the week.. Histogram Transformation
« Reply #13 on: 2014 March 30 03:56:43 »
Hi

This vid shows you how to correct any further colour casts   http://harrysastroshed.com/RGB%20Combination.html   :-*


Regards

Harry

Yes - that's what I needed - brilliant - thanks Harry! :D