New script: ColorMask

RickS

Well-known member
My first attempt at a script and my first time programming in JavaScript so please excuse any newbie errors. Any feedback on non-idiomatic PJSR programming, bugs or improvements will be gratefully received.

The ColorMask script is intended to provide a convenient and interactive method for tweaking color. It builds a mask that selects a range of hues in an image. You then apply the mask and manipulate the image, e.g. with CurvesTransformation (probably using a real-time preview to examine the results of fine adjustments.)

I have been meaning to play with PI scripting for a while. David Ellison, who shares a scope with me at SRO, suggested that I try to automate Bob Franke's process for getting nice Hubble Palette colors in PhotoShop (http://bf-astro.com/hubblep.htm). Trying to do the whole process in one go seemed a bit hard, so this is a first step towards that. The following demonstrates the use of the ColorMask script to do a quick & dirty color adjustment on a SHO narrowband image of the Soul Nebula.

Here is the "before" image created simply with a [L]RGBCombine followed by an unlinked STF stretch applied with HistogramTransformation. It shows the usual magenta stars. The worst of the green was fixed by the unlinked stretch but the colors aren't particularly attractive.

SHO_combine_before.jpg


This is the after image resulting from successive application of a few color masks and manipulation with curves. This was just slapped together quickly as an example. It is not intended to be a perfect image - just an improvement on the one above :)

SHO_combine_after.jpg


Here are the four steps that I used.

1. Make magenta mask (just click on the Magenta button) then apply desaturation twice:
ScreenShot_magenta.jpg


2. Apply green mask (just click on the Green button) then reduce Green slightly:
ScreenShot_green.jpg


3. Apply cyan mask (you can probably guess this one) then use Curves to boost Blue and Red, reduce green and increase saturation:
ScreenShot_cyan.jpg


4. Apply yellow mask and boost Red. Voila!
ScreenShot_yellow.jpg


I hope some of you find the script useful. If you have ideas for improvements let me know.

Cheers,
Rick.

NB: as of PixInsight 1.8.5 ColorMask is now included as one of the standard scripts.
 
Last edited:
Hello Rick

I have just a couple of NB images almost ready for processing.
Your script seems interesting to give it a try.

Can it be downloaded from somewhere?
Edit: I just saw the download clip at the bottom.


Geert
 
Alejandro Tombolini said:
Hi Rick, it works perfectly well. Thanks for this script.

Thanks for the feedback, Alejandro.  I have a few ideas for improvement when I get some free time.
 
Got it!  Played around with it just a little.  Works fine.  I can see a lot of potential use for this one.  I hope it goes "Prime Time" real soon.  Thanks!  :D
 
cdesselles said:
Got it!  Played around with it just a little.  Works fine.  I can see a lot of potential use for this one.  I hope it goes "Prime Time" real soon.  Thanks!  :D

Great, thanks!
 
Great job.  Just did a quick test and managed to knock back some magenta halos in about 30 seconds.  Before:

M33_V3_4x.png


After:

M33_V3_1_4x.png


My only request would be to make it possible to turn the script in to a process icon.  I've noticed some scripts have the ability and others don't, which makes it hard to create repeatable processes that rely on such scripts.  Even without, this ought to be put in the standard release asap!
 
Yes.  It did a very nice job on the magenta stars.  But it also knocked back any areas of Ha in the galaxy.  But this is a problem of the mask being applied globally to all magenta across the image, which is exactly what is was designed to do. 

The only way around that issue I can think of is to be able to apply more than one mask simultaneously.  For instance, create both a magenta color mask and a star mask and use them on the main image in such a way as to only affect the magenta color of the bright stars while leaving the galaxy alone.  Unfortunately, I don't think this is currently possible in PixInsight.  Something for the future maybe?
 
cdesselles said:
Yes.  It did a very nice job on the magenta stars.  But it also knocked back any areas of Ha in the galaxy.  But this is a problem of the mask being applied globally to all magenta across the image, which is exactly what is was designed to do. 

The only way around that issue I can think of is to be able to apply more than one mask simultaneously.  For instance, create both a magenta color mask and a star mask and use them on the main image in such a way as to only affect the magenta color of the bright stars while leaving the galaxy alone.  Unfortunately, I don't think this is currently possible in PixInsight.  Something for the future maybe?

It was only a quick test and it also picked up a fair amount of the background which I would also want to protect.  The answer is probably something like creating the colour mask, taking an existing star mask (which I have) to just protect the just stars in the colour mask (might need to use dilation or similar to grow the star mask a bit first), then use dilation to grow the unprotected (background/galaxy) parts of the colour mask, and then finally apply the modified colour mask to the image and apply curves.  Other strategies using pixelmath to apply a star mask to a colour mask might also work quite well.

The advantage of using the colour mask seems to be that it is a lot better at picking up the magenta halos that start in the dark areas just outside the stars and bleed some way to the centres. I've tried other methods of growing/blurring normal star masks to do the same job, but they usually end up creating undesirable artefacts inside or outside the stars as it is quite hard to grow/soften them correctly to fit all the different sized stars.
 
IanL said:
My only request would be to make it possible to turn the script in to a process icon.  I've noticed some scripts have the ability and others don't, which makes it hard to create repeatable processes that rely on such scripts.  Even without, this ought to be put in the standard release asap!

Good thinking.  I can add the ability to create process icons in the next version.  I have some of the code already in there and I just need to finish off the save/restore of the parameters.

cdesselles said:
Yes.  It did a very nice job on the magenta stars.  But it also knocked back any areas of Ha in the galaxy.  But this is a problem of the mask being applied globally to all magenta across the image, which is exactly what is was designed to do. 

The only way around that issue I can think of is to be able to apply more than one mask simultaneously.  For instance, create both a magenta color mask and a star mask and use them on the main image in such a way as to only affect the magenta color of the bright stars while leaving the galaxy alone.  Unfortunately, I don't think this is currently possible in PixInsight.  Something for the future maybe?

As Ian mentioned, the way to do this in PI is to combine masks with PixelMath.  His suggestion of using Morphological Dilation to "fatten" the stars in a star mask is a good one.  A HT stretch would probably help too.  Then if you use PixelMath to multiply the masks: fat_star_mask*magenta_mask, you'll get a mask that targets just the magenta stars and their halos.

Cheers,
Rick.
 
I'm definitely not up to speed with Pixel Math yet.  Could you elaborate on that method of combining masks a little?
 
cdesselles said:
I'm definitely not up to speed with Pixel Math yet.  Could you elaborate on that method of combining masks a little?

Sure... you create the magenta mask using ColorMask and let's assume its name is "magenta_mask".  You create a star mask and fatten the stars by whatever method you prefer.  Let's call this mask "fat_star_mask".  Now, you type "magenta_mask*fat_star_mask" as the RGB/K expression in PixelMath and run the process by clicking on the new instance triangle and dropping it on either mask.  This will create a new mask (or replace the one you dropped the new instance on depending on if PixelMath has "replace target image" set.)

The pixel values of the new mask are calculated by multiplying the pixel values in the fat_star_mask and the star_mask.  Because the result of multiplying by zero is always zero, the new mask will be zero anywhere either of the source masks is zero.  You'll only get nonzero values where there is a star and the colour is also magenta.

Hope that helps...

Cheers,
Rick.
 
Hi Rick,

Very nice and useful script. What are the "canned magic hue parameters"? Magic settings, especially when they are used to mimic the behavior of other applications, isn't something we like too much in PixInsight. In my opinion, the Red, Green, etc. color buttons should set device/application-independent hue ranges by default, such as (just sample values, not intended to be these ones precisely):

Red = {330,0,30}
Green = {90,120,150}
...

and so on. Then you can create an auxiliary dialog to define custom color range presets. User-defined color range presets can be stored as plain text files (for example, CSV files) that your script can load very easily on demand. With this change your script would be a really powerful, general-purpose image processing tool. Let me know if you need help to implement this.
 
Two great responses Rick and Juan.  Seeing this script come into its full potential is exciting to watch.  A learning process all to itself.  :D

 
Juan Conejero said:
Hi Rick,

Very nice and useful script. What are the "canned magic hue parameters"? Magic settings, especially when they are used to mimic the behavior of other applications, isn't something we like too much in PixInsight. In my opinion, the Red, Green, etc. color buttons should set device/application-independent hue ranges by default, such as (just sample values, not intended to be these ones precisely):

Red = {330,0,30}
Green = {90,120,150}
...

and so on. Then you can create an auxiliary dialog to define custom color range presets. User-defined color range presets can be stored as plain text files (for example, CSV files) that your script can load very easily on demand. With this change your script would be a really powerful, general-purpose image processing tool. Let me know if you need help to implement this.

Thanks, Juan.  The predefined colour parameters are a hangover from the original attempt to emulate Bob Franke's technique for narrowband colour.  I agree that a mechanism to allow for presets is a much better and more general solution.  I'll have a go at implementing that and let you know if I need any help.

Cheers,
Rick.
 
Rick,

Is it possible to add a selection for a wavelength range? I know the user must define the color space properly but I would think that type of masking would be very helpful.



Mike
 
Back
Top