Author Topic: New script: ColorMask  (Read 81928 times)

Offline RickS

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1298
New script: ColorMask
« on: 2014 November 13 20:22:00 »
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.



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  :)



Here are the four steps that I used.

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


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


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


4. Apply yellow mask and boost Red.  Voila!


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. I would remove the download but it doesn't look like editing the post allows me to do that.
« Last Edit: 2017 August 03 20:48:08 by RickS »

Offline msmythers

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1178
    • astrobin
Re: New script: ColorMask
« Reply #1 on: 2014 November 13 20:47:00 »
Rick,

This opens some interesting doors!



Mike

Offline RickS

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1298
Re: New script: ColorMask
« Reply #2 on: 2014 November 13 21:00:30 »
Hope you find it useful, Mike!

Offline gvanhau

  • PixInsight Old Hand
  • ****
  • Posts: 345
Re: New script: ColorMask
« Reply #3 on: 2014 November 14 11:28:44 »
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
Geert Vanhauwaert

Offline Alejandro Tombolini

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1267
    • Próxima Sur
Re: New script: ColorMask
« Reply #4 on: 2014 November 15 06:57:16 »
Hi Rick, it works perfectly well. Thanks for this script.

Saludos,
Alejandro.

Offline cdesselles

  • PixInsight Addict
  • ***
  • Posts: 164
Re: New script: ColorMask
« Reply #5 on: 2014 November 15 11:33:46 »
After downloading, How do we integrate this script into PI?
Celestron CPC1100 - Canon 550D (T2i) and of course, Pixinsight!

Offline Alejandro Tombolini

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1267
    • Próxima Sur
Re: New script: ColorMask
« Reply #6 on: 2014 November 15 11:45:13 »
Hi, see this video about adding scripts.
Saludos, Alejandro.
« Last Edit: 2014 November 15 11:52:34 by Alejandro Tombolini »

Offline RickS

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1298
Re: New script: ColorMask
« Reply #7 on: 2014 November 15 14:08:03 »
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.

Offline cdesselles

  • PixInsight Addict
  • ***
  • Posts: 164
Re: New script: ColorMask
« Reply #8 on: 2014 November 15 14:18:39 »
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
Celestron CPC1100 - Canon 550D (T2i) and of course, Pixinsight!

Offline RickS

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1298
Re: New script: ColorMask
« Reply #9 on: 2014 November 15 15:43:28 »
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!

Offline IanL

  • PixInsight Addict
  • ***
  • Posts: 116
    • The Imaging Toolbox
Re: New script: ColorMask
« Reply #10 on: 2014 November 16 08:59:44 »
Great job.  Just did a quick test and managed to knock back some magenta halos in about 30 seconds.  Before:



After:



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!

Offline cdesselles

  • PixInsight Addict
  • ***
  • Posts: 164
Re: New script: ColorMask
« Reply #11 on: 2014 November 16 10:24:47 »
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?
Celestron CPC1100 - Canon 550D (T2i) and of course, Pixinsight!

Offline IanL

  • PixInsight Addict
  • ***
  • Posts: 116
    • The Imaging Toolbox
Re: New script: ColorMask
« Reply #12 on: 2014 November 16 11:29:44 »
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.

Offline RickS

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1298
Re: New script: ColorMask
« Reply #13 on: 2014 November 16 14:46:06 »
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.

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.

Offline cdesselles

  • PixInsight Addict
  • ***
  • Posts: 164
Re: New script: ColorMask
« Reply #14 on: 2014 November 16 17:15:05 »
I'm definitely not up to speed with Pixel Math yet.  Could you elaborate on that method of combining masks a little?
Celestron CPC1100 - Canon 550D (T2i) and of course, Pixinsight!