New script: GrayscaleDeepSNR

VicVP

Member
Nikita Misiura's DeepSNR module is a very powerful Deep-Learning based tool for denoising color images. However, it is currently only trained to run on color images, and does not work well on RGB-converted monochrome images.

The example below was converted from grayscale to RGB (left image). When you run DeepSNR on such a mono image, the algorithm will produce lot of artefacts (speckle noise, looks a bit like fake stars) and the denoise effect is not very strong.

Grayscale_convertToRGB.PNG


I figured this undesired effect was due to autocorrelation between the 3 channels of an RGB converted image. My script injects random noise in 2 channel copies to reduce autocorrelation, and then runs DeepSNR on the synthetic image. The extra noise results in a small loss of high-frequency detail, but it greatly improves the performance of DeepSNR on grayscale data without dedicated training of the network on monochrome images.

Dialog example.PNG


The strength parameter determines the amplitude of the injected noise. You may need to increase or decrease the default setting for optimal result, it is recommended to test a couple settings. NOTE: DO NOT run the script on a preview. It will crash and close your image. Testing strength settings goes very quickly if you first make a copy of the target image, then crop to 512x512 pixels.

Strength_Effect.PNG


The images of Messier 94 below show a comparison between the typical native DeepSNR performance on a real RGB image, and the script performance on a grayscale image derived from the same dataset.
  • Top left: starting RGB image (Messier 94)
  • Top right: red channel after applying native DeepSNR module on the RGB data
  • Bottom left: Extracted red channel from RGB, script applied with strength = 1
  • Bottom right: Extracted red channel from RGB, script applied with strength = 10

Native DeepSNR vs Script.PNG



The native DeepSNR result is extremely well denoised. Running the script with strength = 1 leaves visible artefacting, however sharpness is almost unaffected. Script strength 10 has much smoother noise reduction (much closer to the native DeepSNR result) at the cost of reduced sharpness in the galaxy core. With a proper mask, both images could be combined for the optimal denoise and sharpness.

This was my first time programming in JavaScript. I followed Roberto Sartori's video for the basics. Any suggestions for code improvement are very welcome! I hope this script is useful. If you test it on your own data, please share the results here.

Official page for DeepSNR process module: https://www.deepsnrastro.com/
 

Attachments

Last edited:
Attention!

After downloading DeepSNR_Win_0.9.0_x64_update.zip, unzipping, copying into C:\Program Files\PixInsight\bin, starting PixInsight and searching for new modules, my AV software (Avira Security) moved my complete PixInsight installation into quarantine and PixInsight was terminated.

Looks like I'll have to delete the files and freshly install PixInsight.

Bernd
 
Thank you and of course thanks to Nikita for DeepSNR which I am using since it's release. It works brilliantly on my datasets and most of the times it is the only denoising tool I apply.
 
After downloading DeepSNR_Win_0.9.0_x64_update.zip, unzipping, copying into C:\Program Files\PixInsight\bin, starting PixInsight and searching for new modules, my AV software (Avira Security) moved my complete PixInsight installation into quarantine and PixInsight was terminated.
I directly reported DeepSNR-pxm.dll as false positive to Avira. Today they confirmed that the file is clean, and I now have no problem in installing and using the DeepSNR module any more. Like StarNet2, DeepSNR appears in the <Etc> process folder, and it benefits from CUDA GPU acceleration. I will try DeepSNR on my integrations.

Thanks a lot, Nikita!

Bernd
 
I fixed some minor bugs and added new features based on feedback.
The new version is attached as a zip.

Changes in v0.3
- Added parameter to replace target image or create new image.
- Strength setting now scales from 1 - 100 instead of 0.1 to 10.
- Added option in Dialog to run the script automatically with multiple Strength settings to quickly identify a good Strength value. This Quick test option is run on the central 512x512 pixel center of the image.

Changes in v0.2
- Added GNU licence text
- Prevent script from running on preview images.
- Prevent script from running on RGB images and notify user that DeepSNR should be used without this script.
- Prevent script from running on images smaller than 512x512 pixels.
- Added parameter to run on non-linear data.
- Added parameter to choose between AutoSTF or existing STF for DeepSNR.

Script test v0.3.PNG


Tweaking the Strength setting can take some time, so I added an option to make the script try different values of this parameter on a small patch of the input (as small as possible). This Quick test produces 3 small images, each will be named according to the applicable Strength value.

In the example below you can see that a Strength value of 3 is too low (small white dots) and a Strength value of 10 produces satisfactory denoising performance on this particular dataset.

Script v0.3 quick test feature.jpg



Any new feedback is welcome!
 

Attachments

Last edited:
@VicVP, thanks for this wonderful script! In private email with Nikita, I'm convinced that your methodology is sound. I have two suggestions, if you don't mind. I'd suggest lowering the default of 10. At least in two tests I ran, the 'stipple' artifacts return at the 10-30 presets of the preview feature, 1-3 sometimes did a fabulous job, so perhaps '5?' Maybe lower the preview defaults as well (1-5-10?). Lastly, as the central part of an image is often a high/strong signal area, why not preview a noisy corner or midway instead. I also found that splitting an OSC image into grayscale channels, running GDSNR and recombining them, produced a fine result! Again, thanks for this! Nikita doesn't see being able to train DSNR on mono or OSC any time soon, and your script is an excellent 'stopgap!' While I have seen what I believe to be generative AI results (questionable stars) with DeepSNR, it is pretty fabulous. Thank you!
 
Last edited:
Warren, apologies for missing your message several months ago. Thanks for the suggestions! Nikita released DeepSNR module v1.0.3 today, which includes an updated Model version 2 and native support for running the process on grayscale images.

I ran a quick comparison between my GDSNR PixelMath with Model v1 (top right), GDSNR with Model v2 (bottom left), and direct execution of DeepSNR Model v2 through the standard PixInsight process interface (bottom right). The application of model version 2 greatly improves the GDSNR result as the background is a lot smoother with less medium frequency blotchiness. Running DeepSNR model v2 without the GrayscaleDeepSNR script has an even smoother background and is also significantly better at restoring the diffraction spikes. I think my script has limited applications for users of DeepSNR module v1.0.3.

GDSNRv2 mosaic.png


I also found that splitting an OSC image into grayscale channels, running GDSNR and recombining them, produced a fine result!

This approach sounds interesting when you only have access to a stacked OSC image, and integration with CFA Drizzle is not available. I will need to experiment with this now that we have access to Model v2.

Up until now, my best trick for HOO combinations was to split the OIII subs in 2 sets, and stack each of these individually. E.g., 40 OIII subs would first be sorted in even and uneven file numbers, then stacked as two 20-sub masters. When these two OIII masters are then combined with Ha as HOO, DeepSNR can run in native RGB mode without correlated noise artefacts in the Green/Blue channel. This works because the noise in each of the 20-sub OIII masters is slightly different, since they were stacked using different sub-exposures.

In my experience, the small decrease in SNR that resulted from stacking half the numbers of OIII subs was greatly compensated by the improved noise reduction achieved through native application of DeepSNR. It worked far better than the noise-injection in my GDSNR script. This approach might no longer be required with the new release of DeepSNR v1.0.3 and Model v2 since it shows improved performance on grayscale data. I will have to perform more testing to see which one works best.
 
Last edited:
Victor,

Thanks a lot for looking at the new version and for your work on the mono script for DeepSNR!

I think your script might still see some use - looking at the screenshots above I feel like top left image has a bit more detail left in the Hydrogen, no? Hard to say if that's real of course given just the screenshots...

Also, the HOO problems should also be solved in the new version now!
 
Back
Top