Author Topic: New MaskedStretch Tool  (Read 17482 times)

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 6035
    • View Profile
    • http://pixinsight.com/
New MaskedStretch Tool
« on: 2014 January 23 19:42:15 »
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.
« Last Edit: 2014 January 23 19:50:22 by Juan Conejero »
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline sreilly

  • PixInsight Guru
  • ****
  • Posts: 734
    • View Profile
    • Imaging at Dogwood Ridge Observatory
Re: New MaskedStretch Tool
« Reply #1 on: 2014 January 23 20:07:23 »
I'm curious the difference in scripts. Mine is shown below:
Steve
www.astral-imaging.com
AP1200
OGS 12.5" RC
Tak FSQ-106ED
ST10XME/CFW8/AO8
STL-11000M/FW8/AO-L
Pyxis 3" Rotator
Baader LRGBHa Filters
PixInsight/MaxIm/ACP/Registar/Mira AP/PS CS5

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 6035
    • View Profile
    • http://pixinsight.com/
Re: New MaskedStretch Tool
« Reply #2 on: 2014 January 23 20:10:31 »
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 :)
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline sreilly

  • PixInsight Guru
  • ****
  • Posts: 734
    • View Profile
    • Imaging at Dogwood Ridge Observatory
Re: New MaskedStretch Tool
« Reply #3 on: 2014 January 23 20:15:19 »
Not to disagree but.....I looked under each as well and have checked all for updates
Steve
www.astral-imaging.com
AP1200
OGS 12.5" RC
Tak FSQ-106ED
ST10XME/CFW8/AO8
STL-11000M/FW8/AO-L
Pyxis 3" Rotator
Baader LRGBHa Filters
PixInsight/MaxIm/ACP/Registar/Mira AP/PS CS5

Offline sreilly

  • PixInsight Guru
  • ****
  • Posts: 734
    • View Profile
    • Imaging at Dogwood Ridge Observatory
Re: New MaskedStretch Tool
« Reply #4 on: 2014 January 23 20:18:43 »
Hello Juan,

I should also mention that it isn't listed under all processes. Below is how my updates are checked. Am I missing something important?

Thanks,

Steve

Steve
www.astral-imaging.com
AP1200
OGS 12.5" RC
Tak FSQ-106ED
ST10XME/CFW8/AO8
STL-11000M/FW8/AO-L
Pyxis 3" Rotator
Baader LRGBHa Filters
PixInsight/MaxIm/ACP/Registar/Mira AP/PS CS5

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 6035
    • View Profile
    • http://pixinsight.com/
Re: New MaskedStretch Tool
« Reply #5 on: 2014 January 23 20:24:03 »
Yes, a new version of PixInsight :)

Don't you receive our notification messages?
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline sreilly

  • PixInsight Guru
  • ****
  • Posts: 734
    • View Profile
    • Imaging at Dogwood Ridge Observatory
Re: New MaskedStretch Tool
« Reply #6 on: 2014 January 23 20:51:08 »
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
Steve
www.astral-imaging.com
AP1200
OGS 12.5" RC
Tak FSQ-106ED
ST10XME/CFW8/AO8
STL-11000M/FW8/AO-L
Pyxis 3" Rotator
Baader LRGBHa Filters
PixInsight/MaxIm/ACP/Registar/Mira AP/PS CS5

Offline Andres.Pozo

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 808
    • View Profile
Re: New MaskedStretch Tool
« Reply #7 on: 2014 January 23 23:07:26 »
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.

Offline niteman1946

  • PixInsight Addict
  • ***
  • Posts: 196
    • View Profile
Re: New MaskedStretch Tool
« Reply #8 on: 2014 January 24 13:09:00 »
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

Offline sreilly

  • PixInsight Guru
  • ****
  • Posts: 734
    • View Profile
    • Imaging at Dogwood Ridge Observatory
Re: New MaskedStretch Tool
« Reply #9 on: 2014 January 24 15:55:10 »
I'd be curious to see what the left image looks like with about the same amount of stretching showing the galaxy as in the right image. It looks like a lot is still hid by the dark background.

-Steve
Steve
www.astral-imaging.com
AP1200
OGS 12.5" RC
Tak FSQ-106ED
ST10XME/CFW8/AO8
STL-11000M/FW8/AO-L
Pyxis 3" Rotator
Baader LRGBHa Filters
PixInsight/MaxIm/ACP/Registar/Mira AP/PS CS5

Offline niteman1946

  • PixInsight Addict
  • ***
  • Posts: 196
    • View Profile
Re: New MaskedStretch Tool
« Reply #10 on: 2014 January 24 16:29:26 »
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

Offline dgbarar

  • PixInsight Enthusiast
  • **
  • Posts: 91
    • View Profile
Re: New MaskedStretch Tool
« Reply #11 on: 2014 January 26 02:06:30 »
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
« Last Edit: 2014 January 26 02:21:48 by dgbarar »
AP 155 EDF
Paramount ME
ST10 XME/CFW 8A

Offline rockyraccoon

  • Member
  • *
  • Posts: 63
    • View Profile
    • My gallery of astrophotos
Re: New MaskedStretch Tool
« Reply #12 on: 2014 January 27 03:45:05 »
What's the role of the "region of interest" parameter in this tool?

Offline MikeWiles

  • Newcomer
  • Posts: 31
    • View Profile
Re: New MaskedStretch Tool
« Reply #13 on: 2014 January 28 16:01:43 »
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

Offline ajbarr

  • PixInsight Old Hand
  • ****
  • Posts: 378
    • View Profile
Re: New MaskedStretch Tool
« Reply #14 on: 2014 January 31 05:02:47 »
Harry we desperately need you to do a tutorial on this that's easy for neophytes to understand.