Author Topic: PixelMath and specifying channels - for luminance masks  (Read 6278 times)

Offline troypiggo

  • PixInsight Addict
  • ***
  • Posts: 258
PixelMath and specifying channels - for luminance masks
« on: 2014 January 05 04:55:36 »
I am creating some PixelMath process icons for luminance mask generation.  I could first extract the Lab L channel and operate on that, but would be easier if I could just work on the lum channel directly from PixelMath.  I know $T operates on the target image, but am having trouble figuring out how to just work on the L channel.

I tried using single expression and specifying the dest colour space to be grayscale, but it didn't appear to give the same results as when I was working on L extracted from Lab.
« Last Edit: 2014 January 13 20:46:38 by troypiggo »

Offline oldwexi

  • PixInsight Guru
  • ****
  • Posts: 627
    • Astronomy Pages G.W.
Re: PixelMath and specifying channels
« Reply #1 on: 2014 January 05 09:52:35 »
Hi Troypiggo!
I am not sure if i understood your question correct. However,
find a screenshot of the 2 actions wih PixelMath.
https://dl.dropboxusercontent.com/u/57910417/PixelMath_LuminanceMask.jpg

First with   
CIEL($T
i created a file "mask" pulling L out of the actual RGB image.

Second with
(($T[0] *(stretchR)) * mask) +    ($T[0] *( ~mask))
(($T[1] *(stretchG)) * mask) +    ($T[1] *( ~mask))
(($T[2] *(stretchB)) * mask) +     ($T[2] *( ~mask))
Symbols:stretchR=1.3,stretchG=1.2,stretchB=1.3

i stretched the different RGB channels with different stretch factors and used "mask" as a mask.
The different channels where selected with
"[2]" for blue
"[1]" for green
"[Null]" for red

The second PixelMath expression stretches the brighter part more than the darker parts...

Hope i did not misunderstand your question to much...
Gerald

Offline troypiggo

  • PixInsight Addict
  • ***
  • Posts: 258
Re: PixelMath and specifying channels
« Reply #2 on: 2014 January 05 12:13:43 »
Aah, that's what I was after.  CIEL($T).  Thanks mate.

Offline troypiggo

  • PixInsight Addict
  • ***
  • Posts: 258
Luminosity Masks (Was: PixelMath and specifying channels)
« Reply #3 on: 2014 January 05 15:35:21 »
Just to clarify what I'm attempting:

I've used Luminosity Masks for landscape (non-astro) images before using the tutorial and background here: http://goodlight.us/writing/luminositymasks/luminositymasks-1.html .  But those are using PhotoShop.  Thought I'd have a go at trying them in PI.  If I understand the theory of the above links correctly, I think it can be achieved using PixelMath (PM).

The "Lights Mask" (as defined in the above link) is pretty straight forward to understand, and I think many PI users probably use them a bit already, even if they don't call it the same thing.  Simply a mask created from the luminance of the image.  I achieved this using (thanks to your help) in PM using CIEL($T).

For the other lights masks, again assuming I understand the theory, I used CIEL($T)^2 for "light lights", CIEL($T)^4 for "bright lights", and CIEL($T)^8 for "super lights".

The "Dark Mask" I think is just inverse of "Light Mask", so used ~CIEL($T).  Then (~CIEL($T))^2 for "Dark Darks" and so on.

The "Midtones Masks" are a bit trickier.  The description on the web page for the "Basic Midtones" is to select all, then subtract the "Lights Mask" and the "Dark Mask" from it.  To me that sounds like "1-CIEL($T)-(~CIEL($T))", but clearly that just cancels itself out, so I added a small factor to change it to "1-CIEL($T)^x-(~CIEL($T)^x)" and have been playing with x around 1.05 to 1.2.  The "Wide Midtones" etc are more straightforward as "1-CIEL($T)^2-(~CIEL($T)^2)" and so on.

If someone has a better idea of the "Basic Midtones" formula, I'd appreciate feedback.

Offline RickS

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1298
Re: PixelMath and specifying channels
« Reply #4 on: 2014 January 05 17:11:06 »
Interesting, Troy.  I'll have a play around with some of those ideas when I get a chance.

I use Lightness and inverted Lightness masks quite frequently, often with further manipulation.  Probably my most used mask would be Lightness with the black clipped and a star mask subtracted.  For operations on "mids" I tend to use RangeSelection to target exactly the areas I want.

Cheers,
Rick.

Offline troypiggo

  • PixInsight Addict
  • ***
  • Posts: 258
Re: PixelMath and specifying channels
« Reply #5 on: 2014 January 05 17:26:55 »
G'day Rick,

Attached is a zip file with the process icons I've created if that helps.

Edit: zip file moved to post #1
« Last Edit: 2014 January 13 20:47:28 by troypiggo »

Offline oldwexi

  • PixInsight Guru
  • ****
  • Posts: 627
    • Astronomy Pages G.W.
Re: PixelMath and specifying channels
« Reply #6 on: 2014 January 06 04:48:37 »
Hi Troypiggo!
You can do in PixelMath a Midtonetransfer (Histogram) also with
MTF(Image,midtonevalue).

The PixelMath expression
~MTF( (CIEL($T)), 0.17)
does the same as moving the middle slider of the histogram to the left to position 0.17  .
It stretches the L channel.

More details about using MTF you can find in my Video:
http://dl.dropbox.com/u/57910417/Video09_PixelMath_IIb_english.wmv

Hope this helps again

Gerald

Offline troypiggo

  • PixInsight Addict
  • ***
  • Posts: 258
Re: PixelMath and specifying channels
« Reply #7 on: 2014 January 06 14:41:37 »
Thanks again Gerald.  Will look at your vid tonight.

Offline WarrenHatch

  • Newcomer
  • Posts: 1
Re: PixelMath and specifying channels - for luminance masks
« Reply #8 on: 2020 January 16 11:07:25 »
Hi Troypiggo,

I'm new to PixInsight and like you have a fair amount of experience using luminosity masks for landscape work.   I stumbled across this old post looking to do exactly what you were attempting.

I would offer 2 suggestions to improve your masks (or at least them make them more closely match those from the folks at Goodlight)...

First use a different gray scale calculation for the Lights.  Secondly, the midtone formula does not require a adjustment factor. 

Instead, you might want to try something like:

Lights_1 = ($T[0]+$T[1]+$T[2])/3;
Darks_1 = ~Lights_1;
Midtones_1 = ~Lights_1 * ~Darks_1;


Lights_2 = Lights_1 * Lights_1;
Darks_2 = Darks_1 * Darks_1;
Midtones_2 = ~Lights_2 * ~Darks_2;

Cheers,

Warren

Offline troypiggo

  • PixInsight Addict
  • ***
  • Posts: 258
Re: PixelMath and specifying channels - for luminance masks
« Reply #9 on: 2020 January 16 15:08:23 »
Thanks Warren.  I'll have a bit of a play with your PM formulae below when I get a chance.

I've found I mostly use the light and dark expressions, rarely the midtones anyway.  They're very useful for creating a nice smooth mask for noise reduction, since it's usually the darkest areas that have more noticeable noise (less signal).

Offline Cosmick

  • Member
  • *
  • Posts: 52
Re: PixelMath and specifying channels - for luminance masks
« Reply #10 on: 2020 January 17 01:43:46 »
Another very flexible way of getting a smooth midtones mask is using CurvesTransformation.

Three examples below -



This curve creates a nice smooth mask usefull for boosting contrast or saturation.



This is just a clipped version that is more restrictive in what it lets through.



The asymmetric version allows you to target other ranges rather than being centered exactly on the midtone.

I'm sure this could be scripted or replicated in Pixelmath. (Not by me  :P)

(Images are attached in case the link breaks)
« Last Edit: 2020 January 17 01:58:41 by Cosmick »
Clear Skies

Mick