New MaskedStretch Tool

Juan Conejero

PixInsight Staff
Sep 2, 2004
8,380
467
57
Valencia, Spain
pixinsight.com
Hi all,

As we already have announced, the latest version 1.8.1 of PixInsight introduces the new MaskedStretch tool.

The original MaskedStretch technique was devised by Carlos Sonnenstein, and a first JavaScript implementation was published by David Serrano as long back as September of 2007. Since then, MaskedStretch has been available as an official script in all PixInsight distributions. It has seen also several important improvements, especially a faster implementation by Andr?s del Pozo in 2010.

The idea behind MaskedStretch is conceptually simple: instead of stretching a linear image with a strong nonlinear transformation (or a set of similar transformations), such as the midtones transfer function (MTF) with the HistogramTransformation tool, apply a series of weaker MTFs iteratively, masking the image successively with the result of the previous iteration. As often happens in the algorithmic arena, this is one case of a pretty simple idea leading to something powerful and useful: MaskedStretch has proven one of the best ways to perform the initial stretch of linear deep-sky images. The iterative stretching/masking process prevents saturation of the highlights efficiently. At the beginning of the process the masks are very weak, so the stretching task really boosts the whole image. Once the image has reached good levels, the masks become stronger to protect bright structures selectively. The neat result is no saturated bright stars and nebular structures, which in turn means much better stellar profiles, less invasive stars?especially in wide field images?, and much better color saturation.

The new MaskedStretch tool is the result of a complete rethinking of the above idea. In the original script implementation there is a mask blurring feature that we have removed from our implementation. The reason is that such a blurring feature is a wrong concept in our opinion: MaskedStretch must be implemented strictly as a point operation; any low-pass filter applied to the masks turns the whole process into a neighborhood operator, with the consequent risk of artifact generation. Other than this, the tool implements a different algorithm to compute the MTF curves applied at each iteration. We have implemented also a user-selectable region of interest (ROI), similar to other ROI features in tools such as BackgroundNeutralization and ColorCalibration. Finally, the MaskedStretch process is fully parallelized, as is customary in PixInsight. MaskedStretch is part of the standard IntensityTransformations module, so it is open-source and its source code is available in the latest PixInsight Class Library (PCL) distribution.

Rather than a parameter-level description?which isn't very useful for relatively simple tools like this one in my opinion?, I'm going to show you how MS works through practical examples. In this post I'll work with an H-alpha image by Antonio P?rez, who kindly allowed me to use it in an example of StarAlignment's mosaic generation capabilities, back in 2010. The image is part of a six-frame mosaic of the Sadr region in Cygnus.


With images covered by extended nebulosity, the ROI feature of MaskedStretch allows us to define the mean value of a sky background area on the final image. The easiest way to do this is by defining a preview roughly covering a background region, as I am doing in the screenshot above. An alternative would be to not use a ROI and define an overall "background" value for the whole image?normally quite high; something in the range from 0.2 to 0.4 for example?, but in these cases working on a true background region is much more intuitive and controllable, in my opinion.

After selecting the preview as a region of interest, the screenshot below shows the result of applying the tool with a target background value of 0.08.


This target background value has been chosen to mimic the result of STF AutoStretch, which can be seen on the first screenshot. Now let's apply an equivalent?in terms of overall contrast and brightness?histogram transformation for comparison purposes.


and without more preambles, let's compare both results side by side on a region with some relatively bright stars.


The images speak loud and clear. These are the processed images and their histograms:

MaskedStretch



HistogramTransformation



It's clear that the HT version has better contrast?although this is always a matter of taste, and hence discussable?, but the lacking contrast can usually be recovered after MS with a careful application of CurvesTransformation or, much better, by mixing both results selectively through masks and/or multiscale techniques. This advanced example with NGC 7023 implements this technique.

For a more exhaustive comparison, I'll show the results achieved on two small crops covering bright stars. The three-dimensional representations have been generated with the 3DPlot script in PixInsight.

First crop - MaskedStretch



First crop - HistogramTransformation



Second crop - MaskedStretch



Second crop - HistogramTransformation



In the next examples, I'll show you how MaskedStretch works for a completely different deep-sky target: a galaxy image where the field is mostly free sky background. I'll show you also the kind of results that can be achieved with color images.
 

Juan Conejero

PixInsight Staff
Sep 2, 2004
8,380
467
57
Valencia, Spain
pixinsight.com
The MaskedStretch script has been left as part of the official distribution for historical reasons, and also to show some due respect and love to their developers. However, it should no longer be used.

We are talking here about the new MaskedStretch *tool*, which you can find under the IntensityTransformations category on the Process Explorer window. Scripts and tools are different beasts :)
 

sreilly

Well-known member
I have the forum setup so I should be receiving messages but find that I seem to get some for some of the groups but not all. I am not using any spam filtering so there aren't any going there. Often I'll check the forum and see new messages that I haven't received notifications on but have been so involved in EMT classes and church building projects I haven't checked near as often. Seems I downloaded and installed version 1.8 just recently. I have just downloaded version 1.8.1. Sorry for my confusion.

Thanks Again,

Steve
 

Andres.Pozo

PTeam Member
Jul 7, 2008
943
5
Madrid
Juan Conejero said:
The MaskedStretch script has been left as part of the official distribution for historical reasons, and also to show some due respect and love to their developers. However, it should no longer be used.
As one of the developers, I don't mind (and even prefer) that you remove the script from the distribution.
 

niteman1946

Well-known member
Mar 2, 2011
252
5
Texas, USA
Here are two mask stretched images of the same file.  The left one is stretched after dynamic crop and DBE.  The right one is stretched after dynamic crop, DBE, TGVDenoise and deconvolution.  The effect on the second image is the same whether I use mask stretch defaults or use a background preview.  Does the use of TGVDenoise and/or decon cause problems (as apparent here) with the mask stretch?

Thanks,
Mark
 

Attachments

niteman1946

Well-known member
Mar 2, 2011
252
5
Texas, USA
Hi Steve, thanks for your response.
This image was shot with the object fairly low and setting directly over the lights of our town.  So there's quite a bit of LP.
I think it's fair to say that the left image can be stretched (using the Histogram Transformation) to look like the right image.  One noticeable difference is the right image has had noise reduction.

I've not used mask stretch for any processing as yet and have always relied on the HT.  So with the discussion, I'm trying to get my head around the how, when where and why.  At first glance, it looks like I need to tweak some parameter settings (i.e.Target Background) to keep the background under control.  And at that point, why not just continue to use HT?

FWIW, my skies are pretty bad and LRGB is a struggle to get right.  This one (NGC2403) was/is particularly problematic.  NB on the other hand comes out pretty good.

Mark
 

dgbarar

Well-known member
Nov 28, 2012
91
0
65
Phoenix, AZ
Hi,

I have begun to experiment with the new Masked Stretch Tool.  From Juan's example I developed a preview of a background area, used it as an "region of interest", and performed a masked stretch.  A "nice" result, but with not much contrast as expected.

I then thought I would not use the preview as the "region of interest" but as the "background reference".  Again, I performed the new masked stretch and got what looks like the same result.  Even the histograms of the stretched images look identical.

Since the result appears the same, why would I use one approach vs the other?  My guess is that if the I use the background reference approach I can specify the pixel values that are to be included in the background to the exclusion of pixels that have values outside the range.  Is this correct?

Don Barar
 

MikeWiles

Active member
Mar 11, 2012
31
0
Juan Conejero said:
In the next examples, I'll show you how MaskedStretch works for a completely different deep-sky target: a galaxy image where the field is mostly free sky background. I'll show you also the kind of results that can be achieved with color images.
Nothing would make me happier than to see these other examples.  I'm pretty excited about this tool - thanks again Juan.

Mike
 

ajbarr

Well-known member
Jun 6, 2011
390
0
Harry we desperately need you to do a tutorial on this that's easy for neophytes to understand.
 

Torsinadoc

Well-known member
Oct 6, 2013
100
0
I would agree on a tutorial.  It seems like a pretty dang simple tool

Questions:
1.  How do you determine the correct number for the target background and number of interations
2. Do you just leave the rest as default?


As you can see below, I get an odd coloration of a star.  I tried several settings but not sure how to avoid this?
 

Attachments

Ghsmith45

Well-known member
Mar 3, 2012
923
7
Sydney, Australia
One thing I have noticed is that using the masked stretch can soften and slightly blur the edges of the stars.  Is there a way to avoid this?  See this image http://www.astrobin.com/76328/ for an example.
Geoff