Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - FrankW

Pages: [1] 2
General / Re: MaskGen
« on: 2019 June 22 02:11:01 »
I suspected that there is a problem with the current PI version. With I get the same error message. Running the script with the same picture on 01.08.061457 everything works fine.

This looks normal. It is intended that the console will be left open after completing the calculations to view the log. The console does not close until you press the script's EXIT button. (As long as a script is open, no other process can be started anyway.)
During the calculation, all input fields and buttons turn gray, after the run they all become active again. If that happens, everything is ok.

Hello Charles,

It's the first time I hear of a problem with the script. Can you please send me the console output of the script.

Kind regards,


As already announced in the forum, in the last weeks I worked on an update of the LFHH script. Today, I am pleased to present some significant improvements and enhancements to the script. These cover the following topics:

Membership functions
On the one hand I added the MTF function as an additional membership function and also the possibility of normalization for the Sigmoid function. But the most important innovation, however, is a membership function with which you can stretch linear images. The script was originally intended only for contrast enhancement, but the discussion with Alejandro Tombolini in the forum gave me the idea to deal with stretching as well.
When looking for a suitable membership function for the stretching, I was inspired by one of the PixelMath tutorials by Gerald Wechselberger. I adapted the idea of „masking“ the MTF function and developed a special membership function for the use with LFHH. Although PixInsight already has a number of excellent processes for image stretching, the results with the new membership function - I called it „Masked MTF“ - were so convincing that I absolutely had to include it in the script. Apart from this I think that's a good opportunity to thank Gerald for his excellent tutorials!

Here is an example: the first image is stretched with AutoSTF, the second one with the new Masked MTF function.

I did a lot of testing with the new feature and I achieved really good results with it. I would be interested in further experiences. With appropriate feedback, I would invest more work in the development of this functionality.

Extrapolation algorithm for the image borders
This feature is not visible, but still a significant improvement of the program. Even if all marginal errors, such as stacking artifacts, were removed in the target image, the old version of the script occasionally had problems with the interpolation of the segments at the image borders. By improving the algorithm, these problems could be resolved on all critical test images. The algorithm is now much more robust.

Color images
Basically, I think contrast enhancement should be applied to the luminance component of an image. Nevertheless, the question arises, how to treat color images. I already described a possibility in the forum: extract the L component from the RGB image, then apply LFHH to the L image and merge it back to the RGB image using LRGBCombination. Another possibility I have now implemented in the script. There the individual colors are modified in the same ratio as the underlying L component.

Here is an example: the target image, contrast enhancement with extracted L component and direct application of the script.

Although the masked MTF function gives good results for color images, it is still not capable for rationally stretching linear RGB images. The script has a check routine, if a processing of an RGB image leads to meaningful results. Basically, the existing stretching processes like MaskedStretch or ArcsinhStretch are better suited for this.

Documentation of parameters
In my numerous tests, I came across the problem of reconstructing the script parameters at a later date. Although the selected parameters have been displayed in the console output so far, this information is lost after a reboot. Therefore, in the new version, all parameter data are stored in the FITS header of the resulting image.

You can read everything about all the new functionalities in the revised documentation you can download together with the updated script from the following link:

I hope you like the new features and I would be happy to receive comments and suggestions for further improvement.

Kind regards,

Jon, Rick,

Thank you very much. I tried the method and I am really excited.  :D  At the moment I work on an update of the script to apply LFHH to color images and even use the algorithm for stretching linear images. I am not sure if I can include your method in the script but it is a great hint anyway.

To give you an impression how the update works, I attached one of my test images. For this image of the Pelican Nebula most of the contrast enhancement was achieved with LFHH. I hope I will finish the work in the next weeks.



that' s a great image! And it's a really interesting idea how to handle the 'star problem'. Can you give a brief description how you remove and add the stars.


it took a while to tune the settings but it works really well after Masked Stretch, TGVDenoise and with a good star mask

Hi Chris ,

It’s really a great image! Yes, tuning the settings is always a cumbersome job. :-[ When I wrote the script, I faced the choice that the script works more “automatically”. But the characteristics of astronomical images can vary in a wide range and I belief that finally only the user can decide what is the best result from an image process. And your image shows that the effort will be worthwhile. :smiley:


I have installed it, but it is not visible in the "script" --> "utilities" menu (and any other "script" menu).
I'm able to execute it only via "Script" --> "Execute script file".
What can I do, to make it visible in the "script" --> "utilities" menu??

That sounds strange! Have you already tried  "Script" --> "Feature Scripts..." --> "Regenerate"?

Hi Alejandro,

Thanks again for sending me that image. The analysis of it was a really helpful exercise!

First, coming to these troubles at the right side of your image. That has nothing to do whether the image is linear or nonlinear. I had the same troubles with some more powerful parameter settings for the nonlinear image. The fact is that there are stacking artifacts on your image, at the bottom but especially an edge of two pixels at the right side! These artifacts lead to that strange results for the the LFHH algorithm and the impact of them is higher for a linear image than for a nonlinear one. This is the reason why you only recognized them for the linear image. But the main massage is:

Remove all stacking artifacts before applying LFHH!

After cropping the image, I got fine results - even at the borders of the image!

The other finding from this analysis was a deeper understanding why the script doesn’t work for linear images. Predominantly, the image improvement you achieved for the linear images doesn’t depend on LFHH. In fact it is effect of the automatic HistogramTransformation included in the script. After unchecking this option you will see the real effect of the LFHH algorithm on a linear image. The underling problem is that the implemented membership functions are not aggressive enough to stretch a linear image. This is an important issue for the further improvement of the script! Thus your comments were really helpful.   :) Thank you for that!


Of course, let me know if this link works

Hi Alejandro,

Thank you, it works.  :)


This will work in general. This is one of the ideas I have tested to apply LFHH to a color image, but I am still searching for the best method. The results are extremely dependent on the color distribution of the target image - so just try it!  :D


Hi Alejandro,

Actually the target image should be non linear (I mentioned it in the documentation  ;)). To apply LFHH also on linear images is one topic on my to-do-list. The other one is the possibility to use color images. If you like, please send me your linear image. This may help me to solve the problem with linear images.


Thanks again for this great feedback!  :)

Thank you, Juan, for your help to tackle my problems with GitHub. I hope that everything is going well now. And a big compliment for the PIDoc Compiler: It is a fantastic tool!

I just managed it! Now all files are also available on the GitHub repository:


I have now finished the documentation of the script! Enclosed find a new version of the script which now includes a link to the documentation. The documentation can be downloaded as a pdf here:

All relevant files for the use in PixInsight can be downloaded here:

I tried to submit the files to the GitHub repository but I fear I didn’t get it.  So I would be glad to get some advice how to do this.


Pages: [1] 2