This article will attempt to provide a guide to begin building masks with PixInsight. There is a huge universe of possible masks that will depend on the image you are processing and the specific needs. Here we will show some of them from the simplest and quickest to made until some a little more complex. The purpose of this guide is to show easily the most important ways to built and use a mask with the available processing tools.
Masks have the functionality of a selective protection of certain areas of an image. PixInsight is extremely flexible regarding mask and any image can be use as mask, but tipically a mask is a gray scale image, where a pixel value of 1 (white) represent a point where a process will be applied completely, and a pixel value of 0 (black) represent a point where the process will not be applied. In the intermediate pixel values between 1 and 0 the applied processes will have intermediate result. Examples of using masks are the protection of stars while applying a process that affect a nebula or galaxy, or protection of an object while performing noise reduction to the background.
Usually you will build a mask using different tools and techniques as will be described in this article, then apply it to the image and finally perform some processes on the image. But PixInsight has also tools with built in masks that allow you to built the mask directly from the tool that is being used such the case of ACDNR, MultiscaleLinearTranform, MultiscaleMedianTransform.
There are also other tools that allow you to use a Lightness mask but without the ability of modify it, such the case of HDRMultiscaleTransform and ExponentialTranformation.
Note: Lightness masks incorporated in the tools are compatible with a possible mask that can have the image.
There are also tools that allow you to generate the masks that are used internally during the process, this functionality can be very useful in some cases as the generated mask could be utilized in further processing, such is the case of GradientHDRComposition, GradientMergeMosaic and HDRComposition tools.
This article covers the construction and use of different kind of masks using the specifically designed available tools like StarMask and Range Selection or combinations of other tools.
Note: The images of this article are random and do not represent a specific workflow or processing example and they belong to various authors. Thanks to Ezequiel Bellocchio, Andrés Vattuone, Vik Kohli and Tim (Chusellon).
You can generate a Lightness Mask extracting the CIE L* component of an image using the button Extract CIE L* Component from the Image tool bar or using ChannelExtraction tool checking CIE L*a*b* Color Space and L Channel.
Working with linear astro images, the generated mask (an image in gray scale) will look dark and in most of the cases this image will need some processing in order to adjust it to the needs of the image to be protected (for instance utilizing HistogramTransformation tool). The name of the new image (the mask) will have by default the _L suffixe added to the original name of the image, (Image_L) and you can rename it conveniently, or you can replace the
When applied to an image, a linear Lmask will look completely red due to most of the pixels in astronomical linear images have values next to 0 (black) and those values represent points where the process will not be applied.
An inverted Lmask, by opposite, will look completely transparent (most of the values near 1) and its visualization will show a red tone over the brightest part of the image
In the Intensity Transformation Tool Bar is located the Invert image buttom that allow you to invert an image. It may be useful to invert the Lmask if you need to modify it, as it may allow a better visualization of the modifications performed to the mask.
The invertion of the image can be also performed from Menu Process › IntensityTransformation › Invert , with the Lmask active.
Once extracted, the linear Lmask may need to be stretched and modified. For example when you need to mask the brightest areas of an image to do denoising over the background with a more aggressive protection of a nebula.
On the inverted Lmask you can obtain a first attemp of the desired mask by moving the midtones balance slider of the Midtones Transfer Function (MTF) in HistogramTransformation tool to the right, and also the hightlight clipping slider a little to the left, to reach the histogram peak as showed in the next screenshot.
By moving the midtones to the right you will vary the values of the MTF from 0.5 to 1 and will notice if using RTP that the mask gets dark (pixels have values next to 0 (black) and those values represent points where the process will not be applied). Moving the highlight slider to the left you will vary the values from 1 to 0 and will notice in the RTP that the mask comes white in the background as the pixels values of the mask reach the value of 1 (those values represent points where the process will be fully applied).
This way, if your Lmask is intended to protect the object during a denoising action, you have to Apply it directly to the image and the process will have full effect in the background and middle or none effect where the image has more signal (the object).
So, if you Apply this inverted Lmask directly onto the image, it will protect mainly the neblula and stars and will give less protecction to the background. If you need the opposite, Apply Inverted Mask or invert it form the Invert Mask button in the Tool Bar.
Lets see what happens if the image is already stretched.
Working with non linear astroimages, the generated mask (an image in gray scale) will show clearly the object and generaly this mask can be used as it is, but also can be processed (for instance utilizing HistogramTransformation tool) to fit the needs of the image to be protected.
When applied, an image with a non linear Lmask will look partially red due to most of the pixels of the mask have low values and those values represent points where the process will be partially applied or will not be applied. Only the objects and stars will be partially transparent and those values represent points where the process will be applied.
An inverted Lmask, by opposite, will look red over the objects and stars protecting those pixels from any process and will be total or partialy transparent to process applied on the background.
The non linear Lmask may need to be stretched and modified. For example when you need to mask the brightest areas of an image to do denoising with a more aggressive protection of a nebula in which you want to protect some finest details. The stretch of the mask can be done with many intensity transformation tools, in this example a choose AdaptiveStretch.
AdaptiveStretch makes a very good job with default values in most of the non linear Lmask but always modify them conveniently to adapt the result to the needs of the image.
Lets process this mask a little more. Suppose that we need to make noise reduction in the image. For denoising purposes the mask may need to be smoothed to achieve a better result and avoid that a nosier mask protect also noise of the image. One usual way to do this is with MultiscaleLinearTranform tool where you can set noise reduction values per layer or delete layers. Making a small preview that covers both bright and dark areas you can check in the Real-Time Preview windows of the MultiscaleLinearTransform tool how the mask is modify while setting per layer noise reduction values as showed in the next screenshot.
The Lmask can now be applied to the image protecting the object to perform noise reduction with any of the available noise reduction tools.
You can generate a Lightness Mask extracting the CIE L* component of an image using the button Extract CIE L* Component from the Image tool bar or using ChannelExtraction tool checking CIE L*a*b* Color Space and L Channel.
In this example we are working with a non linear astroimage, already stretched and the generated mask (an image in gray scale) will not look dark as happens when working with linear image, it is an image that can be visualized without any further processing or need to use STF tool. The name of the new image (the mask) will have by default the _L suffixe added to the original name of the image, (Image_L) and you can rename it conveniently, or also you can specify the new name (L in this example) by replacing
Once extracted the Lightness of the image, using PixelMath tool you can binarize it. In the binarization process the pixel values will be converted to 0 or 1 depending on whether they are greater or less than a defined value. Using the expresion iff ($T<0.12, 0, 1) we define that all the values of the pixels in the image ($T) will be converted to 0 (black) if they are lower that 0.12 and will be converted to 1 (white) if they are equal or biggest than 0.12.
The value of 0.12 will depend on the image and the kind of nebulosity you are working with.
In this example I will use MultiscaleLinearTransform tool to make the needed smoothness of this first auxiliar mask. Note that I removed the layers from 1 to 4 and also reduced the Bias in layer 5. This way the values that where 0 o 1 in the mask now are in between and the mask will be applied partialy in those places.
The second step is to repeat the operation with PixelMath tool but this time with a lower value for binarizing. This way you will get a similar auxiliar mask but with another range of protection on the image.
Once again we smooth the result using MultiscaleLinearTransform tool. Note that I remove the layers from 1 to 5. This way the values that where 0 or 1 in the mask now are in between and the mask will be applied partialy in those places.
Now we will operate with those two auxiliar masks in order to obtain a new one that represent the nebulosity where we want to apply intensity tranformations.
By subtracting the 50 % of one from the other we obtain the desired result.
Finaly we smooth again the result using MultiscaleLinearTransform tool and the Lmask is ready to be used protecting the background and dark nebula while applying an Intensity tranformation in the faint nebulosity. Typicaly can be applied a transformation to increase nebulosity while protecting the background and then invert the Lmask and apply another tranformation to decrease the background while protecting the nebula.
My tool of choise in this example was GammaStretch tool. First protecting the soft nebula decreased the value of background brightness
Now invert the mask and apply the opposite transformation. This increases the brightness of the nebula while the mask protects the background
See the next screenshot with the Final Before and After GammaStretch with the support of Lmask.
The StarMask module is located in Process>MaskGeneration>StarMask
You can generate a StarMask applying default values of StarMask process over a linear image but may be necesary to fine tune some parameters in order to adjust the result. In general big stars on linear image are not included with default parameters of the process and it can be adjusted increasing the "Scale" value. Higher values of Scale will include larger structures in the generated star mask.
Lets start applying default values in StarMask process on a linear image:
Increase Scale parameter to increase the protection of big stars. You will notice that the radius of big stars increased while in the rest remained constant:
The Structure Growth section on the StarMask tool allow to control the protection of large and small structures in the mask. In this example, if we need to extend the area of protection only on the largest stars it has to be increased the "Large-scale" parameter which apply mask protection to larger regions in the image, and at the same time we can control the growth of protection of small stars by decreasing "Compensation" value, or even setting it to zero.
Further processing of the mask can also be done within the StarMask module. If it is needed to increase the protection (higher values in the 0-1 range) you can use "Truncation". Decreasing this value improve protection in the core of the mask structures. Values of 0.5 to 0.3 are enough to have a good protection of stars cores of big stars.
Some cases as the use of Deconvolution process may require a full protection of the saturated cores in big stars (Saturation of stars cores can be avoid performing a HDR composition). Decreasing even more Truncation values you can reach pixels values near to one, (or one) and get full protection on those places.
Lets analize the generation of a StarMask over the following image of NGC 253. This is also a linear image that have some very big stars and our objective will be to protect those stars with an adequate mask during the Deconvolution and MultiescalMedianTransform processes. Note that I will work with the STF activated to visualize the image. You can always identify if the STF is activated or not by checking if the green identification line is present on the margin of the image identifier.
First apply the StarMask process with the default values. The generated image will let us have a first idea on how values of the StarMask process should be modified in order to adjust the mask to the need.
In this mask we have to analyze if the stars we want are there. In our example we look for the big and medium size stars that are the ones that could be affected when applying deconvolution on the image. Note that those stars are included but they seems to be yet small.
You can easyly visualize the coverage of the mask by applying it on the image.
So the first logical change to do in the StarMask tool parameters is to increase the growth of large structures of the image. This modification will affect directly the diameter of the stars in the StarMask. Note that I have increased it considerably, as the big stars always have big halos and I am also looking for its protection due to in this particular example I will also give contrast to the galaxy using MultiescalMedianTransform tool.
Now we have the desired radius for protection but the main two stars of the image have not enough protection in its halos. Increasing the Scale parameter we will obtain the desired protection of those stars.
See how increasing of the Scale affects the radius and protection of big stars when the growth parameter has been previously increased:
The desired stars of the image will be now very well protected by the StarMask for the subsequent application of Deconvolution and MultiscaleMedianTransform
Finally see the sequence after applying both processes protecting the stars with StarMask. Note that the critical stars have remained absolutely invariant.
You can also perform a star reduction of the big stars using the inverted StarMask. In the next animation you can see the blink between the original image with no processes applied and the final image to which was applied Deconvolution and MultiscaleMedianTransform protecting the stars and MorphologicalTransformation and NoiseGeneration protecting the galaxy.
Lets see another example to generate a StarMask applying default values of StarMask process but this time over a non linear image.
Again we start with default values in StarMask process:
The default "Noise threshold" parameter of the StarMask process generate in this image a mask with a lot of background detected as stars. So the first action will be to adjust this parameter, you have to increase the value in order to prevent the inclusion of noise and fine tune it to adjust the result checking that the detected stars of the mask are realy stars but not noise.
Adjusted "Noise threshold" values in StarMask process on a non linear image:
In general big stars on non linear image are not included with default "Scale" parameters of the process and it has to be adjusted. Higher values of Scale include larger structures in the generated StarMask.
See before and after increasing the "Scale" paramenter on StarMask tool
Now, these parameters of the StarMask tool comply with what I was looking for to protect this image.
A simple and quick HaloMask can be done working with StarMask Process, which is located in Process>MaskGeneration>StarMask
Over a linear image you can apply StarMask tool with apropiated values to include medium and large stars. May be necesary to fine tune some parameters in order to adjust the result. In general big stars on linear image are not included with default parameters of the process and it can be adjusted increasing the "Scale" value in StarMask tool. The biggest values of Scale the largest the structures that will be included in the generated star mask.
In this example I have only inceased the "Scale" parameter to include the bigest stars of the image. You may want to lower "Noise Threshold" parameter to include more stars in the mask.
Second step, change only the "Working mode" paramater to "Structure Detection" and apply to generate the structure_map image.
The difference between these two images (star_mask - structure_map) will generate a HaloMask. Using PixelMath tool write that expression in RGB/K
In most cases, depending on the images and situation, the structure_map, which is a binarized image, will need some processing to smoothness the edges of the stars cores. This processing can be done before or after the substraction of the mask obtaining different results. The tool of choise to perform it in this example was MultiscaleLinearTransforamtion where I have deleted the layer of one pixels and decreased slightly the Bias value in layer of two pixels.
Let see both situations:
Applying smoothness directly on the generated HaloMask. That is after that the structure_map image was substracted from the star_mask image.
Or applying smoothness directly on the structure_map before it was substracted to generate the HaloMask.
And now substracting
Note that the parameters applied on MultiscalLinearTranformation were the same in both cases but the result is slightly different in the amount of protection that the mask will have in the stars cores.
To adecuate the intensity of the halo's protection, you can multiply the result by a factor. You may need to try different values of that factor in order to have a correct HaloMask.
If the image is a non linear image (for example it was already stretched with HistogramTransformation tool) the default parameters of StarMask process will give very different result to the ones obtained in the linear stage of the image. An halo mask made in this stage of the image will need more tunning of the parameters for achieving similar results.
Let see a second example of HaloMask following the same procedure than before but with a stretched image. This image has been processed through the linear stage and has been applied the MaskedStretch tool for the non linear transformation.
On this non linear image we will apply StarMask tool with appropriated values with the target of including medium and large stars. May be necessary to fine tune some parameters in order to adjust the result. In general big stars on non linear images are not included using default parameters of the process, so "Scale" value in StarMask tool will need to be increased to include those stars. The biggest values of Scale the largest the structures that will be included in the generated starmask.
Note: increasing the Scale may deal with the inclusion of non stellar objects like the cores of the galaxies.
In this example of a non linear image I have also increased the "Noise Threshold" parameter to avoid the inclusion of noise in the mask.
Generate the starmask:
Now change the "Working Mode" to "Structure Detection" in the StarMask tool to generate the structure_map image:
Apply smoothness on the structure_map image using MultiscaleLinearTransform tool with the objective of having better transition between the star cores and the star halos. The generated structure_map image is a binarized image with values of 0 (full protection) or 1 (no protection) and the process will generate in the transitions, values between 0 and 1. Note that in this example I have only deleted the layer of one pixel and set a negative value of the layer of two pixels which resulted enough, but you may need to fine tune this parameter.
Finally apply PixelMath process to generate the HaloMask. The difference between these two images will generate the mask. On PixelMath tool write the expression in RGB/K field (star_mask4 - structure_map1) and drag the blue triangle on one of the images.
Note: the name of the images to be substractred (star_mask4 and structure_map1) are particular of this example, you must change them by the names of the image you have generated in your process.
Note: PixelMath tool will generate a new image only if it has been set up in the tool. If not, the HaloMask will replace the target image.
See Before and After star halo reduction:
Let see another example of HaloMask, in this case the image has stars and a dark nebulas, and we will use RangeSelection tool instead of StarMask tool to make the intermediate masks.
We are working here in a non linear image, in which has been applied TGVDenoise in chominance and TGVImpaint to correct darkest pixels on the nebula as detailed in this processing example.
The objective here is to work on the halos of big and medium size stars, generating a mask that can protect at the same time the stars cores, the nebula and background of the image.
The first step is to open RangeSelection tool and generate a rangemask to represent the cores of the stars. Note that the Smoothness has been increased to have an adequate transition between the stars and the halos.
The next step is to increase the radius of the stars on the generated mask to reach the radius of the halos using MorphologicalTransformation tool. I have chosen Erosion as operator with a circular structure of 25 pixels which gives the desired halo. This step may need some trial and error.
This representation of the halos needs to be smoothed, for so I used MultiscaleLinearTransform deleting the six first layers.
Once obtained this first intermediate mask, you may want to blink between it and the original image (CTRL+PageDown - Switch Images) to test that the radius in the mask are a good representation of the radius of the stars in the image.
The next step will be to find a representation of the stars cores. The tool of choise is also RangeSelection tool.
This second mask is more crucial to adjust if there are stars inside the radius of the halos. It could be common to have little stars near to big stars, and inside its halo, so you need to protect those stars to avoid them to be affected for further processes. In this example I have decreased a little more the Upper limit in RangeSelection tool to ensure those stars are in the mask.
At this point we have two masks, rangemask_01 which represent the halos of the stars and rangemask_02 which represent the cores of the stars. Using PixelMath we will obtain the final HaloMask.
The values of the pixels in the rangemask_02 are one in the background and zero on the stars, so if we divide rangemask_01/rangemask_02 we will obtain an image where the values of the center of the stars will be one, the same as the background.
This HaloMask needs to be smoothed to have a better transition between the values of the pixels in the cores and in the halos, for so I use MultiscaleLinearTransform deleting the three first layers.
In order to protect the stars cores and the background of the image, the HaloMask must be applied inverted. This way, the values that are one on the mask will be zero once inverted, and will represent points of full protection of the image, and the halos will remain with intermediate pixel values (between 1 and 0) and will be points where the processes will be partially applied. It will look like it is shown in the following screenshot:
Now, using the HaloMask you can apply different processes to work on the halos of big and medium size stars. In this example I used various configuration of MorphologicalTransformation tool and got the bellow result. See how the big star is reduced in diameter:
Another area of the image where the big star halos are reduced while the little stars located into the halo of the big stars remain invariables.
A Terrestrial Mask is a conveniently made mask that allows to work independently the ground and the stars in a typical image of landscape with stars. For instance if you have mountains and sky and if the objective is to add several images to have a good SNR in both, the mountains and the sky and make a composition of both images, the mask will be necesary for adding those images protecting the moved (rotated) and partialy rejected mountains.
In this example are considered two images, one is an integration of a set of images during the sunset called "land" which has the information of the mountain. This image was conveniently corrected with DBE to reduce vigneting.
The second image is called "stars" and is an integration of another set of image taken in the same position later in the night. This group of images were aligned on stars and the mountains moved in every registered image, so they were partially rejected in the integration.
You can generate a Terrestrialmask using RangeSelection process over the "land" image. However, in most of the cases the pixels values of the ground are similars to values of the darkest areas of the sky. Also may have the additional complexity of some residual vigneting if you did not use flats (as in this example) that complicate the separation.
Applying RangeSelection you can see that the mask covers both the mountains and the darkest pixels of the sky and we aim to have a mask with only a representation of the mountains.
This article shows several ways of generate gradients. The idea is to generate first an auxiliary Terrestrialmask with a gradient to protect the image over which we want to generate the RangeMask while applying a non linear stretch on the unprotected region.
Rotate your "land" image 90º clockwise.
Open PixelMath tool and write the following expression in RGB/K: log2( X()+h)/(1-$T)
Write in Symbols: h= (the value that better adjust the shadows to the high of the mountains (your terrestrial object)).
In Destination select "Create new image" and drag and drop PixelMath process over the image.
This will generate and auxiliar mask where the values of the pixels in the mountain will be considerably lower than the values of the pixels in the sky.
Apply this auxiliary mask to your "land" image protecting the mountains and stretch it conveniently using HistogramTranformation tool.
Now you can generate the Terrestrialmask over the stretched "land" image and the result will be a well defined silhouette of the mountains as can be seen in the following Real-Time Preview of the RangeSelection tool.
Apply RangeSelection tool and generate the mask. For the final composition of the image, rotate the Terrestrialmask 90º counterclockwise and also undo the modifications made to "land" image and apply the mask protecting the mountains.
Make the needed processes to the "land" image and finally while protecting the mountains with the Terrestrialmask add the "stars" image using PixielMath.
A Circular Mask is basically a circle that you can use to protect a region of interest in an image. The typical use involves the Sun. In Sun images taken with an appropriate equipment you may be able to enhance solar flares using a mask to protect the disc of the Sun. It is also useful to protect the background while you give color to the Sun.
To built a Circular Mask, first generate a new image with the same dimensions of the image you want to protect. The easy way is to open the NewImages Module (Process>Images>NewImage) or also from the Image Menu (Image>New) or CTRL + N button.
Press Set as active image button in New Image module to have the new image with the same size that the image you have acquired (it has to be open on the workspace). Apply global button (F6) and you will get a black image.
Open PixelMath tool and write the following expression in RGB/K: (~max( 0, ( rdist( cx, cy ) / r )))*h
Write in Symbols: cx= (the value in pixels of the x coordinate of the center of the circle), cy= (the value in pixels of the y coordinate of the center of the circle), r= (the value in pixels of the radius of the circle), h is to define how is the border of the circle, the bigger the value, the sharper the edge.
You can read the coordinates values directly placing the cursor on the image and reading them on the Position tool bar or using DynamicCrop tool. In this case you will get a more precise value.
Click on the image to focus on it and open DynamicCrop tool. Reset it and adjust the borders to fit the Sun. On the Size/Position section of the tool you can read cx and cy values and calculate the radius dividing the width or the height by 2 (you should have an square with width = height).
Apply PixelMath process on the black image and you will get the circle located in the correct position of the image. If you need to make some adjustment simply correct the value of cx, cy, r or h and apply again on the same image.
Tip: It is very useful to apply the mask, visualize it, and make the needed corrections on the mask while it is applied. This will let you see every minor adjustment.
A Circular Mask can also be used as reference image to align a set of Sun images. It is very common in long sesions of Sun images like transits, eclipses, or when following the movement of the Sun to have several set of images with the Sun in different positions and the usual need is to align all of them in the center of the image.
To make this task, first open one of your Sun images. Generate a Circular Mask that will work as reference image. The tool of choise is PixelMath as it lets you locate the Sun perfectly in the center of the image.
First generate a new image with the same dimensions of the acquired images. The easy way is to open the NewImages Module (Process>Images>NewImage) or also from the Image Menu (Image>New) or CTRL + N button.
Press Set as active image button in New Image module to have the new images with the same size that the images you have acquired (it has to be open on the workspace). Apply global button (F6) and you will get a black image.
Measure the diameter of your Sun and calculate the radius (r). You can read the coordinates values directly placing the cursor on the image in the border of the Sun and reading them on the Position tool bar or using DynamicCrop tool as was previously described.
See the width and height of your image and calculate the center of the image.
Write in PixelMath in RGB/K the expression: (~max( 0, ( rdist( cx, cy ) / r )))*h
Write in PixelMath in Symbols: cx=(the value in pixels of the x coordinate of the center of the circle), cy=(the value in pixels of the y coordinate of the center of the circle), r=(the value in pixels of the radius of the Sun), h=150
cx is the width divided by 2, cy is the high divided by 2 and r is the diameter divided by 2. h is to define how is the border of the circle, the bigger the value, the sharper the edge. A value of 150 is apropiate in this case.
Apply PixelMath on the black image and you will get the reference image with the white circle in the center.
Open ImageContainer and add the images you want to align.
Select an output directory different to where are located your input images
Write an output template, for example: &filename;_r.xisf
Generate the ImageContainer instance on your Workspace.
Open FFTRegister Module (if you do not have it, see how to get and install Carlos Milovic' modules here)
Set identifier: here you have to select the reference image that was created with PixelMath
Layer index: set the value to 1
Output image: set "Replace Target" (This is important and will not replace your images due to you have already selected a new location in ImageContainer)
Apply FFTRegister Module over ImageContainer instance.
You can further inspect you aligned images _r using Blink Tool and continue making a video or with the integration you want to make.
Writing the word "mask" in the search field of your browser or in the search field of PixInsight Resources Home Page you will have a quick access to many Video tutorials, Articles and Processing examples related to the use and creation of masks.
Click ENTER to have the complete list of the available resources:
To apply a mask over an image in PixInsight, the image and the mask must have the same dimensions, otherwise will be incompatible. There are several ways to apply a mask:
This method can also be used to apply an inverted mask holding the Ctrl key at the same time that you drag the image identifier and drop it on the view selector in the main image.
Note that the image identifier of the main image changes color when there is an active mask applied.
Mask have different states that can be controlled from the Mask toolbar:
Note that the mask can be active and be hidden (not visible but having effect), or be inactive and be visible (visible, but have no effect). The status Enable/Disable Mask and Show Mask are independent. Visualize the status of the buttons in the toolbar (active/inactive) and the color in the image identifier which indicate if the mask is active.
To remove a mask (unlink the main picture image from the mask image) can be used the button Remove Mask from the Mask toolbar, or the menu option Mask › Remove Mask.
PixInsight Reference Documentation - HistogramTransformation
PixInsight Reference Documentation - RangeSelection