MaskedStretch focuses on stretching mid tones and avoids saturating very bright regions. MaskedStretch works by progressively masking your image with each iteration of a stretch so that the mask becomes stronger as the number of iterations increases thereby protecting the highlights while stretching the mid tones.

Use MaskedStretch when you have a particularly bright region in the image that becomes saturated when you try stretching using something like HistogramTransformation.

Understanding The Effect of MaskedStretch

A good way to understand the effect of MaskedStretch is to compare its result with the result of a regular HistogramTransformation stretch.

Here is an image of the Saturn nebula (NGC 7009) that has been stretched using HistogramTransformation:

The background is very dark and the central part of the nebula is saturated with most pixels at 1.0 (completely saturated).

Here is the same image stretched using MaskedStretch (this image uses the HSI Intensity color mask setting which you’ll learn about shortly):

The nebula in this image has more detail in it, you can see the inner and outer shell, and the maximum pixel value is around 0.83, so the maximum pixel values are not even close to being clipped. 

Using MaskedStretch

Follow these steps to use MaskedStretch:

1. Ensure you have at least one image open on your PixInsight desktop

MaskedStretch works well with both monochrome and color images. If using MaskedStretch with a color image, you can choose the color mask type that is used for the stretch, otherwise this option has no bearing on a monochrome image.

2. Select a target background value

You can use the default value of 0.125 as a starting point and it is generally a good setting for a broad range of images. You can set this value by trial and error or can set the value to a desired background by doing the following:

a. Clone the image you want to stretch (drag the image’s identifier to someplace on your PixInsight desktop)

b. Open HistogramTransformation or CurvesTransformation

c. Using the Real-Time preview, adjust your image’s background level to what you desire

d. Using Readout Mode (press ALT+R on your keyboard), evaluate the values of the pixels that make up the background sky and use an average value of what you find

You can more accurately determine the average background value by doing the following:

i. Create a preview (ALT+N) of background sky

ii. From the menu, select Processes – ImageInspection – Statistics

iii. Select the preview from step i. at the top of the Statistics window

iv. Note the pixel value in the row marked ‘mean’

e. Enter the number from step d) into the Target background field of MaskedStretch

f. Close the cloned image

3. Set the Iterations value

If you are stretching a non-linear image, starting at 100 is a good value to use in most cases. If you are stretching a non-linear image, try starting at about 50 and experiment to find what works best for your image

4. Set the Clipping Fraction

This is the number of pixels that will be clipped before applying a stretch; the default value of 0.0005 is 0.05% of dark pixels which is a good starting point. Increasing this value will result in images where large parts are clipped (set to zero)

5. Select the Color mask type

This setting is applicable only when stretching a color image. The difference between the two settings is likely to be subtle. The HSI Intensity setting uses the average of the RGB pixel values, whereas the HSV Value setting uses the maximum value of RGB pixel values.

For comparison, this is NGC 7009 stretched using the HSV Value setting (the original used the HSI Intensity setting):

6. Set the Background reference

If you leave this at its default setting of <target image> then the average value of all the pixels in the image are used as the background reference.

You can set this option in a couple of ways – the second method is recommended:

a. You can create a preview of a patch of background sky and select it in the ‘Background  reference’ field

b. You can select the ‘Region of interest’ option, create a preview, and click the ‘From Preview’ button to select an area. This is the recommended method because PixInsight stores the selected area as part of the history of your image and you can restore it at any point in the future. Previews are not saved along with your image’s history state

7. Set the lower and upper limits

Pixels having a value less than the lower limit or more than the upper limit get ignored when MaskedStretch determines the average background. The default values are adequate for most images.

Once satisfied with the settings, drag the New Instance icon (the triangle at the lower-left of the MaskedStretch window) over to your image to execute the MaskedStretch

 Conclusion

In this article, you learned about MaskedStretch, learned about its settings and learned how to apply the process.

More Articles In This Series

This article is part of a whole series of articles about processing images using PixInsight: