Jump to content

Banner.jpg.b83b14cd4142fe10848741bb2a14c66b.jpg

Pixelmath Formula in Pixinsight


Recommended Posts

iif((starsonly<=0.01),starsonly,001);~(~Starless*~starsonly)

I've seen and used the above formula to combine a star only image with a starless image quite successfully. However 'd like to fully understand what it's doing.

With my limited maths I think the first part is saying, "If the pixel value of the starsonly image is less than or equal to 0.01, use the starsonly for those pixels, if not use 0.001? or something similar but I don't understand the second part of it at all.

Can anyone throw any light on this? :) 

Edited by Scooot
Link to comment
Share on other sites

The first part works like you describe.

 iif( condition, expr_true, expr_false )

 

The second part

~x. does a Pixel inversion on x so Evaluates to 1 − x, where x is in the normalized [0,1] range (0=black, 1=white).

So it is combining the two images by calculating 1-((1-Starless) * (1-starsonly))

 

Thats the limit of my pixel maths knowledge.

  • Like 1
Link to comment
Share on other sites

What you've written doesn't make much sense to me.  The result of the "iif" statement is never used.

The part of the expression that does all the work is ~(~Starless*~starsonly)

It can be re-written as:  1- (1-Starless)*(1-starsonly)

The effect is to create a resulting image where the bright parts of each image are combined to produce a result that is brighter than either of the originals.  But they are not combined in as additive manner. 

It probably works well for stretched data but if your data are linear then Starless+starsonly  would work better

Mark

Edited by sharkmelley
  • Like 2
Link to comment
Share on other sites

Many thanks both of you, I copied it from this article by Steve Richards in the Sky at Night, https://www.skyatnightmagazine.com/astrophotography/astrophoto-tips/pixinsight-enhance-galaxy-brightness-without-affecting-stars/

It’s designed to maintain the background levels of the combined images. I have never seen the iif function either, but it works, maybe it’s specific to Pixinsight (or a typo in the article). It is to be used on stretched data.

Anyway I better understand how it’s doing it now thank you. :) 

Edited by Scooot
Link to comment
Share on other sites

25 minutes ago, steppenwolf said:

Not a typo!!

Ah hello Steve, my apologies, no offence intended. It’s a good article and very useful thanks. The formula worked well when I tried it, I was just trying to more fully understand it. 

 

Link to comment
Share on other sites

40 minutes ago, Scooot said:

Ah hello Steve, my apologies, no offence intended.

None taken, I assure you :thumbright:  With some of my data, the background sky levels became brightened and this odd bit of PI pixelmath worked fr me:-

iif( cond, expr_true, expr_false )

Conditional function (or inline if function):

 

Returns expr_true if cond evaluates to nonzero.

Returns expr_false if cond evaluates to zero.

 

Invariant subexpression: When each of the three arguments is either an immediate numeric value or an invariant subexpression.

  • Like 1
Link to comment
Share on other sites

36 minutes ago, steppenwolf said:

None taken, I assure you :thumbright:  With some of my data, the background sky levels became brightened and this odd bit of PI pixelmath worked fr me:-

iif( cond, expr_true, expr_false )

Conditional function (or inline if function):

 

Returns expr_true if cond evaluates to nonzero.

Returns expr_false if cond evaluates to zero.

 

Invariant subexpression: When each of the three arguments is either an immediate numeric value or an invariant subexpression.

Thanks Steve,

I think I understand. So is the first part of the formula choosing what pixel value to use in the second part of the formula based on the condition?

EG if the pixel value of the starsonly image is 0.02, as this is bigger than 0.01 in the first condition, the number to use in the second part of the formula for the starsonly image is 0.001. 

Link to comment
Share on other sites

43 minutes ago, Scooot said:

I think I understand. So is the first part of the formula choosing what pixel value to use in the second part of the formula based on the condition?

EG if the pixel value of the starsonly image is 0.02, as this is bigger than 0.01 in the first condition, the number to use in the second part of the formula for the starsonly image is 0.001. 

Hi Richard,

I wrote this over a year ago and haven't used it since as I normally move into PhotoShop after I have calibrated, aligned, stacked and deconvolved in PI but I believe that this is correct. The second algorithm then carries out the actual 'screen blend' maths.

  • Like 1
Link to comment
Share on other sites

4 minutes ago, steppenwolf said:

Hi Richard,

I wrote this over a year ago and haven't used it since as I normally move into PhotoShop after I have calibrated, aligned, stacked and deconvolved in PI but I believe that this is correct. The second algorithm then carries out the actual 'screen blend' maths.

Great, thanks Steve, much appreciated.

Link to comment
Share on other sites

As an alternative, I often use this to combine starless and starry images:

(A^N + B^N) ^ (1/N)

Where A and B are the images and N is a numeric constant greater than unity, typically 3.

The rationale here is that raising something less than one to a power greater than one makes it smaller, so for any pixel, i, if

Ai <  Bi

then 

Ai^N << Bi^N

and the combination tends very quickly to the larger value for increasingly different Ai and Bi. The (1/N) power simply renormalises the result.

There are, of course, many variations of this formula which could be used.

Tony

Edit: I should add that the big advantage here is that there is no sharp transition, and there is no threshold to choose. 

Edited by AKB
  • Like 2
Link to comment
Share on other sites

13 minutes ago, AKB said:

As an alternative, I often use this to combine starless and starry images:

(A^N + B^N) ^ (1/N)

Where A and B are the images and N is a numeric constant greater than unity, typically 3.

The rationale here is that raising something less than one to a power greater than one makes it smaller, so for any pixel, i, if

Ai <  Bi

then 

Ai^N << Bi^N

and the combination tends very quickly to the larger value for increasingly different Ai and Bi. The (1/N) power simply renormalises the result.

There are, of course, many variations of this formula which could be used.

Tony

Edit: I should add that the big advantage here is that there is no sharp transition, and there is no threshold to choose. 

Many thanks Tony, I’ll try that.

Link to comment
Share on other sites

9 hours ago, steppenwolf said:

Not a typo!!

It certainly looks like a typo to me. 

The iif statement does absolutely nothing because the result of the iif statement is not applied to any image.  In fact that's a good thing because the effect of the statement iif((starsonly<=0.01),starsonly,0.001) would be to remove all the stars from the starsonly image by capping their value to 0.001!

Mark

Edited by sharkmelley
Link to comment
Share on other sites

11 hours ago, sharkmelley said:

It certainly looks like a typo to me. 

The iif statement does absolutely nothing because the result of the iif statement is not applied to any image.  In fact that's a good thing because the effect of the statement iif((starsonly<=0.01),starsonly,0.001) would be to remove all the stars from the starsonly image by capping their value to 0.001!

Mark

Hi Mark,

I tried an experiment with my last image.

A combination using “iif”in the expression and then using just “if” instead. I had intended to then show the image stats of the results to compare the difference. However, the “if” attempt failed. See below.

9B87EE3F-EC83-4722-BFA3-5673D1AA3535.thumb.jpeg.9fdb47e42dfd92d74979f4d90f8f7c10.jpeg

 

Link to comment
Share on other sites

11 hours ago, sharkmelley said:

It certainly looks like a typo to me.

The non-typo that I was referring to was in reply to Richard's comment about not seeing the 'iif' function before. However, I checked the S @ N text against my original manuscript and I am pleased to report that the editors have not made a typo as the two match.

Unfortunately that doesn't explain any lack of functionality in the first calculation which is a mystery unless I introduced an error when I added it to my article. As it is benign in nature, it will have to remain a mystery for now.

  • Like 1
Link to comment
Share on other sites

7 minutes ago, steppenwolf said:

The non-typo that I was referring to was in reply to Richard's comment about not seeing the 'iif' function before.

Yes that was my lack of knowledge I should have googled it before posting, my apologies again. 🙄

Edited by Scooot
Link to comment
Share on other sites

9 minutes ago, steppenwolf said:

The non-typo that I was referring to was in reply to Richard's comment about not seeing the 'iif' function before. However, I checked the S @ N text against my original manuscript and I am pleased to report that the editors have not made a typo as the two match.

Unfortunately that doesn't explain any lack of functionality in the first calculation which is a mystery unless I introduced an error when I added it to my article. As it is benign in nature, it will have to remain a mystery for now.

Your formula as in the article worked perfectly, and the result looked good. It was when I changed yours to just “if” that failed. :) 

Link to comment
Share on other sites

2 hours ago, steppenwolf said:

Unfortunately that doesn't explain any lack of functionality in the first calculation which is a mystery unless I introduced an error when I added it to my article. As it is benign in nature, it will have to remain a mystery for now.

It's very odd but as you say, it can remain a mystery 😉

Mark

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. By using this site, you agree to our Terms of Use.