Author Topic: PJSR: Blend script  (Read 14498 times)

Offline Mike Reid

  • Newcomer
  • Posts: 47
    • Mike's Astro
PJSR: Blend script
« on: 2012 February 26 14:35:21 »
I was surprised that I could not find this script already in the forums so I decided to have a go.  The "Blend" script will blend two images using any of the blending modes whose PixelMath formulae were detailed in this posting,
  http://pixinsight.com/forum/index.php?topic=2409

I have also added a variable opacity slider to allow for adjustment of the amount of mixing of the blended image with the bottom image.  This led to the addition of the "Normal" blend mode (simple percentage mixing of the two images) to those enumerated in the posting, namely,

  Darken
  Multiply
  Color Burn
  Linear Burn
  Lighten
  Screen
  Color Dodge
  Overlay
  Soft Light
  Hard Light
  Vivid Light
  Linear Light
  Pin Light
  Difference
  Exclusion

There is nothing here that you can't already do with Pixel Math but maybe it will prove to be a time saver for some.  I have attached the script and a screenshot of the popup.

Mike

Offline Harry page

  • PTeam Member
  • PixInsight Jedi Knight
  • *****
  • Posts: 1458
    • http://www.harrysastroshed.com
Re: PJSR: Blend script
« Reply #1 on: 2012 February 26 14:44:23 »
Hi

Excellent Idea will have a go soon  :D

Thanks for your work

Harry
Harry Page

Offline budguinn

  • PixInsight Addict
  • ***
  • Posts: 106
Re: PJSR: Blend script
« Reply #2 on: 2012 February 26 16:27:46 »
super job, Mike

Offline Alejandro Tombolini

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1267
    • Próxima Sur
Re: PJSR: Blend script
« Reply #3 on: 2012 February 26 19:42:41 »
Thank you Mike !!!

Regards, Alejandro.

Offline Herbert_W

  • PixInsight Addict
  • ***
  • Posts: 204
    • Skypixels - Astrophotography by Herbert Walter
Re: PJSR: Blend script
« Reply #4 on: 2012 February 26 20:31:05 »
Hi Mike!

Great job - thank you!

Best regards
Herbert, Austria

Offline Enzo De Bernardini

  • PTeam Member
  • PixInsight Addict
  • ***
  • Posts: 274
  • Resistance is futile.
    • Astronomí­a Sur
Re: PJSR: Blend script
« Reply #5 on: 2012 February 26 20:47:06 »
Very nice work Mike! Thanks! (and thank you for mention me in the credits! :D )

Best,

Enzo.

Offline sleshin

  • PixInsight Old Hand
  • ****
  • Posts: 431
Re: PJSR: Blend script
« Reply #6 on: 2012 February 26 21:10:29 »
That's really useful, Mike. Thanks.

Steve
Steve Leshin

Stargazer Observatory
Sedona, Arizona

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: PJSR: Blend script
« Reply #7 on: 2012 February 29 08:14:16 »
Good work Mike. Thanks for a nice and useful script.

I would add also the missing arithmetic operations:

Add
(Multiply - already included)
Subtract
Divide

and also the flat fielding operation:

IMG1*mean( IMG2 )/IMG2

where IMG2 acts like a flat frame. There are other useful ones that we probably can figure out with a bit of brainstorming.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Harry page

  • PTeam Member
  • PixInsight Jedi Knight
  • *****
  • Posts: 1458
    • http://www.harrysastroshed.com
Re: PJSR: Blend script
« Reply #8 on: 2012 February 29 09:35:13 »
Hi

As I am photoshop useless , other than the obvious what are the real world use of the blend modes  >:D

I did see the little demo in the other thread , but give me some real use ideas so dumbo here can understand  :-[

Kind regards Harry
Harry Page

Offline Mike Reid

  • Newcomer
  • Posts: 47
    • Mike's Astro
Re: PJSR: Blend script
« Reply #9 on: 2012 March 01 05:44:26 »
Harry,

I've never used most of them either but one example that comes up often in astrophotography is to make a copy of an image, use high pass filtering on it and then blending it back with the original using "overlay" blending mode.

Juan,

I'll add these other operations.  I have some other improvements in mind as well.

Thanks all for the kind remarks,
Mike

Offline pfile

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 4729
Re: PJSR: Blend script
« Reply #10 on: 2012 March 01 12:37:48 »
yes the flat fielding op would be very nice, since i find myself having to quickly flatten single frames while i'm evaluating my pointing...

Offline oldwexi

  • PixInsight Guru
  • ****
  • Posts: 627
    • Astronomy Pages G.W.
Re: PJSR: Blend script
« Reply #11 on: 2012 March 01 14:11:15 »
Hi Mike!
Great tool.
I like it because it adds a slider to selected PixelMath functions.
And additional PixelMath functions can be added very simple.

To find out what is the best percentage with the slider it woud be nice
when the script stays with the selected parameters for another and another try with percentage etc.
Finally then to exit with an exit button. ("OK" should not end the script)

I managed somehow to remove the "break" in your script so i can run and test the different results without
starting the script again and again. However my exit needs to be more elegant - have no idea with scripts how to
exit...

Thanks for your work and your help if possible.

aloha
gerald

Offline Riccardo A. Ballerini

  • Newcomer
  • Posts: 37
Re: PJSR: Blend script
« Reply #12 on: 2013 September 30 14:22:00 »
THANX!!!!  8)

Offline Geoff

  • PixInsight Padawan
  • ****
  • Posts: 908
Re: PJSR: Blend script
« Reply #13 on: 2013 September 30 18:43:24 »
Hi Mike!
To find out what is the best percentage with the slider it woud be nice
when the script stays with the selected parameters for another and another try with percentage etc.
Finally then to exit with an exit button. ("OK" should not end the script)

gerald

+1
Don't panic! (Douglas Adams)
Astrobin page at http://www.astrobin.com/users/Geoff/
Webpage (under construction) http://geoffsastro.smugmug.com/

Offline ngc1535

  • PixInsight Old Hand
  • ****
  • Posts: 326
Re: PJSR: Blend script
« Reply #14 on: 2017 September 26 07:16:01 »
I am replying to this very old message just in case anyone should come here as I did and find the old version of the Blend.js script. Blend v1.0 handles some things incorrectly- specifically the Screen blending mode. Later versions of Blend apparently fix this (good job). I did not find mention of later versions or anyone fixing the issue in forum posts.

I spent a good hour trying to understand what was going on. The formula is correct- but I finally noticed in the process console window that the script RESCALES the result. This is the (subtle) problem and not correct. Maybe very old attachments like scripts can be cleaned occasionally? Version 3.0 truncates values as expected.

___
Here is what I wrote in an e-mail to try to understand the issue:

I think I found something strange...

Here is the formula for the Photoshop Screen blending mode (Pixel Math):

a=0.7;
top=Mean_m27_H_alpha;
bottom=Mean_m27_DBE_Deconvolved;
a*(1-(1-top)*(1-bottom)) + (1-a)*bottom

Symbols, a, top, bottom

This will blend these two images together. However... if you use the Screen Blending mode in the script that Mike Reid wrote (Blend) it gives you a different result. Looking at the Processing Console, the formula is CORRECT. However the implementation is not (in my mind).

This blend mode should be symmetric in that the order of the layers (which image is top or bottom) doesn't matter. To quote from wikipedia:



" With Screen blend mode the values of the pixels in the two layers are inverted, multiplied, and then inverted again. This yields the opposite effect to multiply. The result is a brighter picture.

f(a,b)=1-(1-a)(1-b)} f(a,b)=1-(1-a)(1-b), where a is the base layer value and b is the top layer value."



This mode is symmetric: exchanging two layers does not change the result. If one layer contains a homogeneous gray, Screen blend mode is equivalent to using this gray value as opacity when doing “normal mode” blend with white top layer."

Note that homogeneous gray values act as an "opacity." This is an important part of the behavior for Screen. When pixels are black in one image- the result is the value of the OTHER image. ie Screen(top = 0, bottom = 0.5) = 0.5. This behavior allows you to create a threshold for the blend by making black pixels and it is VERY powerful.

The script however takes an extra step that breaks this result. It RESCALES the result. This breaks the symmetry and also breaks the opacity and black pixel behavior. So it does not work like the true Photoshop blending mode.

Have I gone down the wrong road- is my logic unsound?

Thanks,