Here it looks like you are calculating luminance by giving equal weight to each color channel. By default PixInsight does not weight the channels equally when extracting luminance, as discussed in documentation of RGB Working Spaces (such as https://pixinsight.c.../why_rgbws.html). Would you get better results by using the coefficients defined in the RGB Working Space?
Thanks for this observation. I've never really played with RGBWorkingSpace, so I've taken the time to research what it does and to incorporate it into a test version of the code. Using the RGBWS luminance coefficients when calculating the luminance does have some subtle but useful effects on the outcome of the stretch. For instance it can be used make H-alpha pop out more from the background during the stretch. It doesn't change the colour balance of those individual pixels but makes pixels dominated by that colour appear brighter in the stretched image.
I'll certainly put this in the next version so the more sophisticated user can take full advantage of it but I won't get a chance to do this for a little while.
Edited by sharkmelley, 22 March 2017 - 02:26 AM.