Author Topic: Repaired HSV Separation Script  (Read 27263 times)

Offline Bob Andersson

  • Member
  • *
  • Posts: 67
Repaired HSV Separation Script
« on: 2013 January 27 07:28:58 »
Hi folks,

This script owes its genesis to a discussion on "true colours" and the way that the H, and to a lesser extent, the Sv separations of an HSV channel separation clearly show the effects of non-linearity in the underlying data. The script allows one to set a threshold above which data is assumed to be non-linear and attempts to draw colour information in from the surrounding pixels. It also attempts to restore a more peaked profile to the luminance information but that processing is fairly conservative and an option exists to output an "unrepaired" version. The script may be downloaded from here, it was developed and tested under PI 1.7 and the interface looks like this:



The intention is to apply the script to linear data. Using this (6.8 MB FIT) test crop here is a screen grab of the unstretched image which illustrates a problem:



There is no reason at all to suppose that the star actually changes colour as the core is approached, quite the opposite in fact. After running the Repaired HSV Separation Script the result looks like this:



It looks weird but the relative ratios of red/green/blue at the center of the star highlighted by the loupe are now pretty much just as they are away from the star's core. While I've offered the option of outputting a "repaired" but unstretched RGB the purpose of the script is primarily to output repaired H, Sv and V separations so that the V separation can be stretched before recombination with the H and Sv data. This offers a way to stretch an image without the usual loss of colour saturation. Here is the result of passing the V image through the MaskedStretch script (100 iterations, Target Median 0.15), recombining with the H and Sv images and doing a spot of clipping and colour balancing:



Quite an extreme look and not one that will win many prizes. The script can highlight chroma noise quite readily if the underlying data is poor. For comparison here's how the same MaskedStretch settings changed the "repaired" RGB:



And, for fun, here's what the two images look like when added together in equal proportions using PixelMath:



Comments and suggestions are welcome. This is my first attempt at JavaScript, and that probably shows, and my first spot of programming in over ten years having previously dabbled as a self-taught C++ programmer so please forgive the multiple stylistic errors.  :)

Bob.
« Last Edit: 2013 July 25 05:24:34 by Bob Andersson »
TEC 140 'scope, FLI ML16803 camera, ASA DDM60 Pro mount.

Offline georg.viehoever

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2132
Re: Repaired HSV Separation Script
« Reply #1 on: 2013 January 27 10:59:23 »
Great! Star clusters were just what I had in mind when I was dabbling with the V-Transform. Looking good...
Georg
Georg (6 inch Newton, unmodified Canon EOS40D+80D, unguided EQ5 mount)

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: Repaired HSV Separation Script
« Reply #2 on: 2013 January 27 12:38:49 »
Hi Bob,

Brilliant! Can we release it as an official script?
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Bob Andersson

  • Member
  • *
  • Posts: 67
Re: Repaired HSV Separation Script
« Reply #3 on: 2013 January 27 12:50:57 »
Hi Juan,

I'd be honoured. Do you think it might be worth waiting a short while to see if any bugs surface or if improvements to the algorithms are suggested?

Bob.
TEC 140 'scope, FLI ML16803 camera, ASA DDM60 Pro mount.

Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • http://www.carpephoton.com
Re: Repaired HSV Separation Script
« Reply #4 on: 2013 January 27 16:54:16 »
Thanks for providing this script!
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity

Offline Andres.Pozo

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 927
Re: Repaired HSV Separation Script
« Reply #5 on: 2013 January 28 01:37:18 »
Thanks Bob. Nice idea!

I have however found a couple of errors using it in PI v1.8RC3:
  • Selecting the option "Repaired RGB" doesn't seem to do anything.
  • It fails at the line 264. The version 1.8 seems to have an stricter validation of the parameters of ImageWindow(). It should be:
Code: [Select]
let inputWindowCopy = new ImageWindow (1, 1, img.numberOfChannels, img.bitsPerSample, img.sampleType == SampleType_Real, img.isColor, inputWindowCopyName);

    Offline Bob Andersson

    • Member
    • *
    • Posts: 67
    Re: Repaired HSV Separation Script
    « Reply #6 on: 2013 January 28 02:25:53 »
    Hi Andres,

    Thanks for the bug report - having feedback from the PI 1.8 release candidate is particularly useful as I've still not dipped my toe in those waters yet. I've duly amended the code as you suggested and uploaded v1.0.1 (same download location here).

    I did notice that a similar "new ImageWindow()" constructor was in place to create the "Repaired RGB" window so I've also amended that as well. Hopefully that will solve your other issue.

    Bob.
    « Last Edit: 2013 July 25 05:26:15 by Bob Andersson »
    TEC 140 'scope, FLI ML16803 camera, ASA DDM60 Pro mount.

    Offline Andres.Pozo

    • PTeam Member
    • PixInsight Padawan
    • ****
    • Posts: 927
    Re: Repaired HSV Separation Script
    « Reply #7 on: 2013 January 28 02:35:08 »
    Hi Bob,

    both bugs in 1.8 are resolved but there is now another one  ;)
    In the line 42 you have to use quotes in the version number because otherwise it fails at the line 727.

    Offline Bob Andersson

    • Member
    • *
    • Posts: 67
    Re: Repaired HSV Separation Script
    « Reply #8 on: 2013 January 28 02:39:31 »
    Hi Andres,

    Darn it - you got there just before me! I needed, as you so rightly pointed out, to enclose the version number in quotes - fixed and thanks for your help. I added your name to the change log.  :)

    Bob.
    TEC 140 'scope, FLI ML16803 camera, ASA DDM60 Pro mount.

    Offline Andres.Pozo

    • PTeam Member
    • PixInsight Padawan
    • ****
    • Posts: 927
    Re: Repaired HSV Separation Script
    « Reply #9 on: 2013 January 28 02:44:25 »
    I added your name to the change log.  :)

    That is not necessary. IMO pointing to a couple of bugs it is not enough to merit the recognition.  :embarassed: :embarassed:

    Offline Bob Andersson

    • Member
    • *
    • Posts: 67
    Re: Repaired HSV Separation Script
    « Reply #10 on: 2013 January 28 02:49:48 »
    Hi Andres,

    I'm more than happy to leave your name there (maybe I should have asked) but if you want me to remove it then say the word.

    Bob.
    TEC 140 'scope, FLI ML16803 camera, ASA DDM60 Pro mount.

    Offline Bob Andersson

    • Member
    • *
    • Posts: 67
    M42 - The Orion Nebula
    « Reply #11 on: 2013 March 16 06:23:36 »
    Hi folks,

    I decided to remove my Pleiades image from this thread (too blue!) and replace it with M42. As noted below I really struggled with the weather this winter but I hope the result, even with such a limited number of subs, demonstrates that the script doesn't just have application to the stars.




         M42 - The Orion Nebula

    5 x 40 seconds in each of red, green and blue and 6 x 200 seconds in each of red, green and blue. I managed just 6 x 1,000 seconds of red subs and 2 x 1,000 seconds of blue subs and without any green that wasn't a lot of use for this object. And narrowband never happened - what a winter! Captured via my TEC 140 (f/7) and my FLI ML16803. The 100% version is available here for pixel-peeping fun.

    Bob.
    TEC 140 'scope, FLI ML16803 camera, ASA DDM60 Pro mount.

    Offline Alejandro Tombolini

    • PTeam Member
    • PixInsight Jedi
    • *****
    • Posts: 1267
      • Próxima Sur
    Re: Repaired HSV Separation Script
    « Reply #12 on: 2013 March 16 13:03:08 »
    Hi Bob, thank you for this script!, and nice image (I liked the pleyades too).

    I start playing a little with it and discover something that could be a bug.
    Screenshot 1: All works fine over the full image
    Screenshot 2: in a small image generated from a preview the "Repair Level" parameters is allways 1
    If you increase a little the size of preview it is enought to it work fine again.

    Saludos. Alejandro.

    Offline Bob Andersson

    • Member
    • *
    • Posts: 67
    Re: Repaired HSV Separation Script
    « Reply #13 on: 2013 March 17 03:06:52 »
    Hi Alejandro,

    I tried reproducing the behaviour using my M13 data but without success. It would seem that the pixel intensity of the histogram's peak as reported by the HistogramTransoformation module (my script, line 1188 of version 1.0.1) is 65536 (I'm using the module in 16 bit mode - line 1175). In the normalised range of 0.0 to 1.0 that equals 1.0 which is strange. I've never tried using the script on an image which hasn't been rescaled but which does need rescaling - is there any chance at all that the original image does need rescaling? That wouldn't be a problem when the script is looking at the whole image because most of it is dark so peaklevel would be well below the limit but when dealing with a crop of the bright central area maybe the peaklevel is off the scale?

    Bob.
    TEC 140 'scope, FLI ML16803 camera, ASA DDM60 Pro mount.

    Offline Alejandro Tombolini

    • PTeam Member
    • PixInsight Jedi
    • *****
    • Posts: 1267
      • Próxima Sur
    Re: Repaired HSV Separation Script
    « Reply #14 on: 2013 March 17 10:22:49 »
    Hi Bob, you are right, it does not depends on the size of the preview, but where it is located.
    Besides I tryed to reproduce it in other images without succes.
    I have uploaded to endor the image where it can be reproduced. It is in Forum Shared Files > Alejandro Tombolini > "HDR_Cumulo_Test_RepairedHSVSeaparationScript.fit"
    Direct link
    Saludos. Alejandro