Author Topic: Statistics Process Inconsistent/Invalid Results  (Read 4081 times)

Offline IanL

  • PixInsight Addict
  • ***
  • Posts: 116
    • The Imaging Toolbox
Statistics Process Inconsistent/Invalid Results
« on: 2012 December 13 12:12:12 »
Forgive me if I have this wrong or if it has been raised before.  I did a forum search and one other user mentioned the same issue but there was no response that clarified the issue.  I am trying to use the statistics to check/verify the system gain, etc. of my DSLR.

Process I am following is:

- Debayer a flat frame (Debayer -> Bilinear).
- Extract the green channel (ChannelExtraction)
- Create a preview in a small, flattish part of the flat.
- Run statistics on the preview.

If I check the StdDev and Variance with the 'Range' dropdown set to 'Normalised Real [0,1]', then I get a meaningful result.  The StdDev figure is the square root of the Variance figure, as you would expect, in this case Variance is approximately 2.2E-04 and StDev is 1.48E-02

If I set the 'Range' dropdown to '16-bit [0,65535]' then StdDev (in this case) is 971.428 and Variance is 14.400.  Clearly this is wrong since Variance is much smaller than StdDev!  The same issue occurs if you select any other bit range from the 'Range' dropdown.

Now I can happily work with the Normalised Real figures, but it does not exactly inspire confidence that something so basic as image statistics are displayed wrongly.

As ever, happy to be told I am an idiot and doing it wrong or don't understand, but pretty sure I am not (for once).

ruediger

  • Guest
Re: Statistics Process Inconsistent/Invalid Results
« Reply #1 on: 2012 December 13 13:21:29 »
If I check the StdDev and Variance with the 'Range' dropdown set to 'Normalised Real [0,1]', then I get a meaningful result.  The StdDev figure is the square root of the Variance figure, as you would expect, in this case Variance is approximately 2.2E-04 and StDev is 1.48E-02

If I set the 'Range' dropdown to '16-bit [0,65535]' then StdDev (in this case) is 971.428 and Variance is 14.400.ce).
0.00022 * 65535 = 14.4 and 0.0148 * 65535 = 969.9, so there is no computational error for the different range selections in the ImageStatics windows (some difference to your numbers because of missing fractional units).

However, I can't explain what "variance" represents in the ImageStatistics and how it is related to the StdDev value (which is computed as explained e.g. in wikipedia).

Rüdiger

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: Statistics Process Inconsistent/Invalid Results
« Reply #2 on: 2012 December 13 15:10:54 »
Hi Ian,

Quote
If I set the 'Range' dropdown to '16-bit [0,65535]' then StdDev (in this case) is 971.428 and Variance is 14.400.  Clearly this is wrong

Indeed. The 16-bit variance should be about 943672 in this case. Thank you for detecting this mistake.

The variance is on the squared scale of the data, so the normalized variance should be multiplied by the square of the integer range. In the 16-bit range, the variance should be multiplied by 65535**2 = 4294836225. Currently it is being scaled linearly, hence the erroneous variance values when an integer range is selected.

This bug is now fixed in the Image module that will be distributed with version 1.8. Note that the rest of statistics are correctly scaled (linearly), including the standard deviation.

Thanks again for discovering this. I hope we'll be able to inspire more confidence in future versions.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline IanL

  • PixInsight Addict
  • ***
  • Posts: 116
    • The Imaging Toolbox
Re: Statistics Process Inconsistent/Invalid Results
« Reply #3 on: 2012 December 13 15:17:26 »
Juan,

Thanks for your prompt response.  You beat me to it as I had just worked through a simple example in Excel following Rüdiger's post which set me thinking about it and come to the same conclusion which I was going to post.

My comment about confidence was meant in jest, so please don't think otherwise, I am a fan of PI and the fact that you are open about how things work (or don't) makes me far more confident than I am in other packages.  I can work with the normalised values for my purposes, but I was seriously beginning to doubt my (shaky) grasp of my high school statistics lessons for a while there!

ruediger

  • Guest
Re: Statistics Process Inconsistent/Invalid Results
« Reply #4 on: 2012 December 14 00:03:21 »
the variance should be multiplied by 65535**2 = 4294836225.
Oh of course.... now I feel stupid about my first post :)

I am trying to use the statistics to check/verify the system gain, etc. of my DSLR.
Have a look at the modified BasicCCDParameters script in this thread /forum/index.php?topic=4086.msg29090#msg29090. It should give correct values for DSLR that have a positive BIAS value. For Nikon however the values are still not correct because bias=0 so you have to force mean=0 from outside to get correct values.

Rüdiger

Offline IanL

  • PixInsight Addict
  • ***
  • Posts: 116
    • The Imaging Toolbox
Re: Statistics Process Inconsistent/Invalid Results
« Reply #5 on: 2012 December 14 02:25:32 »
Thanks Rüdiger,

I'll certainly take a look at the script, I already have questions but will post them in the other topic.  I wanted to complete a quick run through manually first, partly for my own education and partly to get a reliable benchmark to ensure I am using the script correctly.