Author Topic: PixelMath question  (Read 135 times)

Offline CraigNZ

  • PixInsight Enthusiast
  • **
  • Posts: 94
    • View Profile
PixelMath question
« on: 2019 October 18 15:02:51 »
I have a monochrome CCD image and want to change the value of each pixel using this formula:

y = 0.99 *x + 140/x + 318.0

I tried this equation in PixelMath but it did not work:

0.99 * $T + 140/$T + 318.0

What would be the correct equation(s) to use in PixelMath?

Craig

Offline CraigNZ

  • PixInsight Enthusiast
  • **
  • Posts: 94
    • View Profile
Re: PixelMath question
« Reply #1 on: 2019 October 18 16:16:40 »
Further research into this shows the problem is with division.  For example, this equation

$T/1.0

works okay, every pixel is the same as before,

but this equation

$T / $T

changes every pixel to 65535 (unsigned 16 bit integer formatting)

it should have been 1 for each pixel (e.g., 100 / 100 = 1)
 

Offline sharkmelley

  • PTeam Member
  • PixInsight Addict
  • ***
  • Posts: 233
    • View Profile
    • Mark Shelley Astrophotography
Re: PixelMath question
« Reply #2 on: 2019 October 18 16:40:14 »
Quote from: CraigNZ
Further research into this shows the problem is with division.  For example, this equation

$T/1.0

works okay, every pixel is the same as before,

but this equation

$T / $T

changes every pixel to 65535 (unsigned 16 bit integer formatting)

it should have been 1 for each pixel (e.g., 100 / 100 = 1)

There's no problem there.  PixInsight natively works with floating point numbers in the range 0.0-1.0
But if you choose to display the pixel values as 16 bit integers then they will be displayed in the range 0-65535
You could equally choose to display them as 8 bit integers in the range 0-255

The answer to your original question:
y = 0.99 *x + 140/x + 318.0
depends on the range of values that your version of x is allowed to take.

I'm guessing your x is in the range 0-65535 and your constants are compatible with the same range, then the PixelMath formula you want is:

(0.99*($T*65535)+140/($T*65535) + 318)/65535

This is because PixelMath values of x are natively in the range 0.0-1.0 and the result of the expression needs to be in the same range.

Mark
« Last Edit: 2019 October 18 17:04:40 by sharkmelley »
Takahashi Epsilon 180ED
H-alpha modified Sony A7S
http://www.markshelley.co.uk/Astronomy/

Offline CraigNZ

  • PixInsight Enthusiast
  • **
  • Posts: 94
    • View Profile
Re: PixelMath question
« Reply #3 on: 2019 October 18 17:11:38 »
Thanks Mark,  that helped a lot.  I didn't realize that PI converts the input values to the range 0 to 1 but it makes sense.