ClarkVision.com

To Clarkvision.com Galleries
Home Galleries Articles Reviews Best Gear Science New About Contact

Astrophotography Image Processing:
Advanced Image Stretching with the
rnc-color-stretch Algorithm

by Roger N. Clark

Complex astrophotography image processing is made simpler with the rnc-color-stretch algorithm


The Night Photography Series:


Contents

Introduction
M31
M33
M8 + M20
Stretching Functions
Command Line Program
Download
Conclusions


All images, text and data on this site are copyrighted.
They may not be used except by written permission from Roger N. Clark.
All rights reserved.

If you find the information on this site useful, please support Clarkvision and make a donation (link below).


Introduction

Current verision available: 1.02 (June, 2023). see below.

One of the most difficult problems in astrophotography image processing is stretching the image to boost faint signals. Simple brightening is easy, but that brightens skyglow too. Skyglow is the unwanted signal that includes light pollution from artificial lights, airglow in the Earth's atmosphere, and scattered light (from stars, light pollution and airglow). Skyglow adds an offset to the signal from the astronomical objects, and it is colored, so the offset is different in the red, green and blue channels of a film or digital camera image. The challenge is to subtract the correct amount of skyglow and establishing what is true black. The true black point is not always easily established. Even so, there are clues to the black point even when there are no black areas in the scene.

Once the black point is found, the image can be stretched. But all stretching pushes brighter parts to the image to higher intensities, losing color. We commonly see astrophotos made with a variety of methods with mostly white stars and relatively colorless galaxies and nebulae. To correct the lack of color, the saturation is often boosted, but in the process, it enhances noise. This leads to astrophotographers acquiring longer exposures to try and combat the noise, not realizing some (or in some cases a lot of) the noise is from processing methods.

To solve these problems, I wrote new software. The software, rnc-color-stretch, works to automatically establish the black point, subtract the skyglow, stretch the image, and analyze the pre and post stretched image to recover color lost in the stretch. An example of the power of rnc-color-stretch is shown in Figure 1. The stacked image for this example is shown in the top of Figure 1. The bottom image in Figure 1 is the stretched image from rnc-color-stretch with no post-algorithm manipulation. In fact, the image is a crop of the of the out-of-algorithm generated jpeg. The algorithm also puts out a 16-bit png image.

The current version of rnc-color-stretch does not yet handle gradients from light pollution or airglow that you want removed. If your image has such gradients, they need to be (mostly) removed before application of rnc-color-stretch. The image can have strong light pollution, as long as gradients are low.

M31

With some small tweaks to the rnc-color-stretch result using only the curves tool in an image editor, an image like that in Figure 2 is possible.


Figure 1. Result of feeding the top image to rnc-color-stretch to produce the bottom image. The bottom image has had no post algorithm manipulation except to downsize it for this display.


Figure 2. Some small tweaks to the image from Figure 1, bottom, after some work with the curves tool.

As stated above, stretching loses color. Stretching using the same rnc-color-stretch algorithm but with the color recovery turned off is shown in Figure 3.


Figure 3. Traditional stretching loses color. Compare this image to the image in Figure 1 bottom. Both images used the same input data.

M33

M33 is a low surface brightness spiral galaxy. It is very difficult to extract color. The raw-converted and stacked image is shown in Figure 4 (left) and the out-of-algorithm image with no additional processing except downsizing for display is shown in Figure 4 (right). See the Gallery Image for a larger version and more details.

Traditional stretching (Figure 5) loses color. Traditional stretching is harder to control, typically resulting in additional noise (Figure 6).


Figure 4. Stacked raw image (left) and stretched out-of-algorithm image (right). Larger gallery Image.


Figure 5. Traditional stretching loses color (left), but rnc-color-stretch maintains color (right).


Figure 6. Stretching with the curves tool in an image editor loses color and can introduce noise due to quantization (left). Rnc-color-stretch maintains color and does not add noise as all calculations are done in 32-bit and 64-bit floating point.

M8 + M20

The region near the galactic center around Messier 8 and Messier 20 is full of amazing colors. Key to success in bring out detail is 1) the raw conversion, and if necessary, subtract skyglow gradients, 2) stretching that brings out subtle details without losing color. Figure 7 shows the sequence from out of camera, stacked and rnc-color-stretch result. See the Gallery Image for a larger version and more details.

Traditional processing loses color (Figure 8).


Figure 7. M8 + M20 region. Left) an out of camera jpeg, a single 1-minute exposure showing the nebula and brown background which is a combination is light from interstellar dust plus sky glow (airglow and some light pollution). Middle) the raw converted and stacked image. Right) The rnc-color-stretch out of algorithm result with no additional processing except for downsizing for display. Larger gallery Image.


Figure 8. Traditional stretching loses color (left), but rnc-color-stretch maintains color (right).

Stretching Functions

The stretching functions used are presented in Figures 9a, 9b, and 9c. The main stretch is the power function and you can do 1 or 2 passes. How far you can stretch depends on the data quality. If you have good data with reasonable signal-to-noise root power factors of 200 to 300 on pass 1 can be done. If you have noisy data made in a high light pollution zone, a rootpower of 5 and one pass may be too much. As a general strategy try rootpowers of 5, 9, 20, 50, 100, 200, 300 with one pass and see if the stretched image is still holding up. If so and you want to stretch more, add a second iteration of power stretch. If the first iteration power stretch is a high number, above 10, the second iteration should be a small number, e.g. under 6, at least in my experience.

As I have gained experience with the power factor on my images, I believe it is better to do the first power iteration with a larger number than the second. For example, power factors 50 and 3 for iteration 1 then 2.

Next try adding scurve1 (Figure 9b) which adds contrast to the lower mid-tones.

If the image still needs brightening, try the scurve2 option which applies the scurve1 function followed by the scurve 2 (Figure 9c) function.

If as you push the stretch harder with power factors, power iterations and scurves, if you start to see artifacts, back off. Artifacts are an indication you data is not of sufficient quality for that extreme of a stretch. You might be able to push further by hand in an image editor with the curves tool. if so, this will be an easier starting point than an unstretched image.


Figure 9a. Example power stretch functions. Note that 2 iterations of power factor 5 produces a much stronger stretch than a single stretch with a high power factor.


Figure 9b. The scurve 1 function adds contrast in the lower midtones


Figure 9c. The scurve2 function brightens the image overall with slightly more emphasis on the brighter parts of the image.

Command Line Program

The rnc-color-stretch algorithm does 3 main things. 1) Analyze the image histogram to maintain a black point or use set low level color throughout the stretching process. The histogram is analyzed at multiple stages from beginning to end. 2) A power stretch while maintaining the black point. 3) Recover lost color after the stretching process. How far you can stretch an image depends on the signal-to-noise ratio.

Here is a small version of the image in Figure 7, middle for testing:
16-bit tif, 2.3 megabytes: m8+m20.rnclark.c08.12.2015.19frames.test-c1b5x5.tif

Usage

Usage is simple. From the command line:
rnc-color-stretch inputfilename options

The current version of rnc-color-stretch does not yet handle gradients from light pollution or airglow that you want removed. If your image has such gradients, they need to be (mostly) removed before application of rnc-color-stretch. The image can have strong light pollution, as long as gradients are low. If you do not remove most of the gradient before rnc-color-stretch, the stretch will amplify the gradient and its color. You can subtract the gradient after rnc-color-stretch but it might be more difficult.

Run the command from the command line with no options to get a list of options:
rnc-color-stretch

Options:

Use the above test image with the commands below to see different effects.
cd to the directory where the image is located.
Type/copy the following onto the command line in a terminal session. The full line in bold should be one line (it can wrap around on the screen, but needs to be one line with the only line feed at the end of the command).

Example:
rnc-color-stretch inputfilename -rootpower 50 -obase outputfilenamenoextension -scurve2 -display

If the input file name is: m8+m20.rnclark.c08.12.2015.19frames.test-c1b5x5.tif, and the output base file name is m8+m20.test1-rs50 (output will be m8+m20.test1-rs50.png) then here are some examples.

rnc-color-stretch m8+m20.rnclark.c08.12.2015.19frames.test-c1b5x5.tif -rootpower 50 -obase m8+m20.test1-rs50 -scurve2 -setmin 5140 5200 5650 -jpegonly -display

Add a little color enhancement:
rnc-color-stretch m8+m20.rnclark.c08.12.2015.19frames.test-c1b5x5.tif -rootpower 50 -obase m8+m20.test1-rs50-e1.4 -scurve2 -setmin 5140 5200 5650 -enhance 1.4 -jpegonly -display

More aggressive stretch:
rnc-color-stretch m8+m20.rnclark.c08.12.2015.19frames.test-c1b5x5.tif -rootpower 5 -rootiter 2 -obase m8+m20.test2-rs5-2iter -scurve1 -setmin 5140 5200 5650 -jpegonly -display

More aggressive stretch plus color enhancement:
rnc-color-stretch m8+m20.rnclark.c08.12.2015.19frames.test-c1b5x5.tif -rootpower 5 -rootiter 2 -obase m8+m20.test2-rs5-2iter-e1.3 -scurve1 -setmin 5140 5200 5650 -enhance 1.3 -jpegonly -display

Now compare to nocolor correction:

rnc-color-stretch m8+m20.rnclark.c08.12.2015.19frames.test-c1b5x5.tif -rootpower 5 -rootiter 2 -obase m8+m20.test2-rs5-2iter -scurve1 -setmin 5140 5200 5650 -nocolorcoerect -jpegonly -display

Once you have settings that produce a result you like, drop the -jpegonly option and the program will also write a 16-bit/channel png file which you can further edit.

Notes: if you use the -display flag, davinci must be configured to display images. See davinci.asu.edu for information.

You might have seen stretching software in image processing program with things like square root of the signal, or logarithm of the signal. Rnc-color-stretch does a variable power function: intensity1/power_factor where power_factor can vary from 1 to 499. But simply doing a power stretch is only part of the problem. Rnc-color-stretch maintains the black point and color. To see the process at each stage including image and plots of histograms, use the -plots and -display options together. Example:

rnc-color-stretch m8+m20.rnclark.c08.12.2015.19frames.test-c1b5x5.tif -rootpower 5 -rootiter 2 -obase m8+m20.test2-rs5-2iter-e1.3 -scurve1 -setmin 5140 5200 5650 -enhance 1.3 -jpegonly -plots -display

On macs and linux, use the tee program to record the output as the program runs:
rnc-color-stretch m8-stack.tif -rootpower 50 -obase m8-rs50e0.66sc2m5140 -scurve2 -enhance 0.66 -setmin 5140 5200 5654 |& tee cmd.rnc-color-stretch-rs50e0.66sc2m5140

The above examples work well with some of my images. You will need to tune settings for what works best for you.

Note: the setmin option fills in irregularities at the low level in typical DSLR raw-converted images. This mitigates low level red, green, blue splotches in the dark parts of the image and is discussed in Part 3f4 of this series.

To explore settings with your images, I suggest making a small 16-bit tiff, a few hundred pixels in size, then include the -jpegonly flag to record only jpeg images. With the small image size, the program runs faster and the -jpegonly saves disk space.

Depending on the speed of your computer, rnc-color-stretch can take many minutes to run. On my 3 GHz I7-950 computer, a 20 megabyte 16-bit tif image takes 10 to 30 minutes to run depending on the number of power iterations and numbers of scurves used.

Download

The rnc-color-stretch software is free and open source. You can download it from
8a) Software for nightscape and astrophotographers in this series.

Conclusions

The new rnc-color-stretch program is a powerful new tool for stretching astrophotos and maintaining color. I have been able to extract more detail and color with this program than any other method I have tried, including traditional linear processing. Natural color is more consistent with a color managed workflow with modern raw converters with rnc-color-stretch.


If you find the information on this site useful, please support Clarkvision and make a donation (link below).


References and Further Reading

Clarkvision.com Astrophoto Gallery.

Clarkvision.com Nightscapes Gallery.

The Night Photography Series:


Home Galleries Articles Reviews Best Gear Science New About Contact

http://www.clarkvision.com/articles/astrophotography-rnc-color-stretch/

First Published November 29, 2016
Last updated May 10, 2017