Author Topic: PixelMath Help  (Read 721 times)

Offline dhb2206

  • Newcomer
  • Posts: 41
PixelMath Help
« on: 2019 February 15 09:36:04 »
I've noticed in my images that areas with blown out highlights after PCC have a green value that is almost half of that for red and blue, which leaves star core in linear form looking somewhat magenta. So, I was wanting to have a play with PixelMath and see if I can set a ratio for the green channel where red and blue are above a certain threshold, but I'm stumped. I've gotten as far as defining the functions for R and B as $T (admittedly that bit isn't too complex), but I have no clue as to how to refer to individual colour channels to construct my iif statement for G (IIF(myredvalue>0.85,$T/5*8,$T))?

Addendum: I suppose I could utilise a symbol definition and iterate through the individual pixels using myR = pixel($T, x, y, 0), but then we hit iteration - how does one loop through x and y from 0 to with and height respectively, or does the process just do this anyway?

I've no idea if it'll work, but no try, no know!

Cheers,

David

« Last Edit: 2019 February 15 09:50:51 by dhb2206 »

Offline TinySpeck

  • PixInsight Enthusiast
  • **
  • Posts: 81
Re: PixelMath Help
« Reply #1 on: 2019 February 15 10:06:13 »
Have you tried opening the Expression Editor in PixelMath, expanding the Syntax items, and clicking on the entries?  There's a pretty good Help that pops up in the middle pane there to show you what the functions, operators, etc, do.  You might find what you need there.
Gerrit

Offline ngc1535

  • PixInsight Old Hand
  • ****
  • Posts: 326
Re: PixelMath Help
« Reply #2 on: 2019 February 15 11:37:07 »
I've noticed in my images that areas with blown out highlights after PCC have a green value that is almost half of that for red and blue, which leaves star core in linear form looking somewhat magenta. So, I was wanting to have a play with PixelMath and see if I can set a ratio for the green channel where red and blue are above a certain threshold, but I'm stumped. I've gotten as far as defining the functions for R and B as $T (admittedly that bit isn't too complex), but I have no clue as to how to refer to individual colour channels to construct my iif statement for G (IIF(myredvalue>0.85,$T/5*8,$T))?

Addendum: I suppose I could utilise a symbol definition and iterate through the individual pixels using myR = pixel($T, x, y, 0), but then we hit iteration - how does one loop through x and y from 0 to with and height respectively, or does the process just do this anyway?

I've no idea if it'll work, but no try, no know!

Cheers,

David

SCNR actually gets pretty close to what you want...something to consider or know about.

Concerning Pixel Math- the expression you create applies to a single pixel. Pixel Math automatically iterates through every pixel with your expression. I think that is what you are asking.
So if your expression was "1"... every pixel will be assigned the value of "1" as it iterates through your image.

You can access the color channels by specifying $T[channel]  where $T[0] is Red... $T[1] is Green and $T[2] is Blue.
Then... and this isn't correct.... you could make an expression like
iif( $T[0] > 2*($T[1] + $T[2]), $T[1]*2, $T)

This says if twice the sum of the blue and green channel is less than the red channel then double green- otherwise don't do anything.
This probably isn't going to solve your problem... but I just wanted to show an example of how to interact with the color channels.

-adam

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: PixelMath Help
« Reply #3 on: 2019 February 15 11:44:07 »
Hi David,

I was starting to write an answer but Adam has nailed it. Let us know if you need more information.

Just an additional point. You can use channel subscripts with any existing image, not just with $T (the target image); for example:

iif( MyReferenceImage[1] > 0.85, $T/5*8, $T )

Yes, yes, a reference documentation for PixelMath is absolutely necessary...  :-[
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline dhb2206

  • Newcomer
  • Posts: 41
Re: PixelMath Help
« Reply #4 on: 2019 February 15 13:53:07 »
Thanks guys, I'd tried all sorts but forgot about square versus round brackets!

Offline dhb2206

  • Newcomer
  • Posts: 41
Re: PixelMath Help
« Reply #5 on: 2019 February 15 13:58:20 »
And no, that really didn't work..... I'll have a look and see if I can find a pattern to work with.

Offline ngc1535

  • PixInsight Old Hand
  • ****
  • Posts: 326
Re: PixelMath Help
« Reply #6 on: 2019 February 15 19:12:33 »
And no, that really didn't work..... I'll have a look and see if I can find a pattern to work with.

*laugh* Yeah, I didn't think it would. I just kinda made it up. I have tried to solve some problems like yours with ratios of colors and things- but it is fairly difficult to do cleanly because of the way chrominance and luminance are represented in general. In addition, the data is expressed in a continuum of values whereas conditional statements tend to be discrete with boundary conditions that make life hard. Sometimes the change is small (in size or amount)- so that the artifacts remain small- sometimes not.

Anyway the limit is really only your ability to be creative with ideas- and knowing the tools at hand certainly helps.
-adam