Author Topic: Elliptical Gradient Generator (for masks)  (Read 5227 times)

Offline ngc1535

  • PixInsight Old Hand
  • ****
  • Posts: 326
Elliptical Gradient Generator (for masks)
« on: 2017 November 10 23:14:08 »
Hi all,

I am finding a tool I made increasingly useful for a number of processing scenarios I have encountered. I am not certain if someone has already done this, if so I apologize for the reinvention of the already well known. My real motivation is a personal goal thing... I would like to contribute something that is promoted to a sticky or makes  it into Jim's PI "cribsheet" at some point. :)

Using PixelMath I created an expression that will generate ellipses (arbitrary sizes and angles) that are filled in a gradient like fashion. The gradient part isn't required- and different forms of infill from solid to other functions are useful. However the gradient version is generally useful as many astronomical objects (and artifacts) are brighter in their centers and fade to fainter values.

The section below is one of the tutorials in a collection I will be releasing soon:

https://www.youtube.com/watch?v=2sAYyZYcrJI

In addition, you will find in the tutorial I make a shameless plea for someone to work with me and create a script for this! (again, if it does not already exist)
And finally, feedback would be welcomed if more tutorials like this posted to this forum are desirable.

-adam


Offline sleshin

  • PixInsight Old Hand
  • ****
  • Posts: 431
Re: Elliptical Gradient Generator (for masks)
« Reply #1 on: 2017 November 11 09:58:59 »
Hi Adam,

That's a very useful and easy technique for making an object mask. The tutorial is excellent. Thanks for posting it. I would love to see more tutorials like this from you and if some already exist, please point me to them.

Steve
Steve Leshin

Stargazer Observatory
Sedona, Arizona

Offline sleshin

  • PixInsight Old Hand
  • ****
  • Posts: 431
Re: Elliptical Gradient Generator (for masks)
« Reply #2 on: 2017 November 11 14:08:00 »
Hi Adam,

Could you please post the correct equation as it should be entered into Pixel Math. Turns out the video cuts off the complete expression and when I enter what I tried to piece together, I get a parse error that an expression has been incorrectly entered. Obviously doing something wrong but not enough of a math guy to figure it out. Would like to give this a try so a little more help would be appreciated.

Thanks,

Steve
Steve Leshin

Stargazer Observatory
Sedona, Arizona

Offline ngc1535

  • PixInsight Old Hand
  • ****
  • Posts: 326
Re: Elliptical Gradient Generator (for masks)
« Reply #3 on: 2017 November 11 17:27:56 »
Hi Steve,

I hope to encourage everyone to watch my tutorial (first)...
You know what the hardest part of the expression was? Keeping track of the  %*&#! parenthesis!!
Here is the expression I created:

Expression:

PA=pi()*angle/180;
r = sqrt( (((x()-offsetx)*cos(PA) + (y()-offsety)*sin(PA))/a)^2 + (((x()-offsetx)*sin(PA) - (y()-offsety)*cos(PA))/b)^2 );
iif(r<max_r, ~(r/max_r), 0)

Symbols:

offsetx=1000,
offsety=1000,
max_r=1,
a=200,
b=100,
angle=90,
PA,
r


-------
Hints:
Offsets are for the center of the ellipse.
a and b are the semi-major and minor axes (again... SEMI... radius... watch the video)
angle rotates ellipse clockwise for positive values and CCW for negative.
The ellipse is normalized to 1.
Change the "0" to "$T" in order to add more than one ellipse to a mask (after adding one)

-adam


Offline avastro

  • PixInsight Addict
  • ***
  • Posts: 181
    • http://astrosurf.com/avastro/
Re: Elliptical Gradient Generator (for masks)
« Reply #4 on: 2017 November 12 02:11:46 »
Hi Adam,
Great tutorial,excellent.
 I made a test using a galaxy image worked just fine, used it also to attenuate Star halo building a donuts mask easy to do and efficient.
Tested in linear image,works fine also.
Antoine
Antoine
Lentin Observatory
http://www.astrosurf.com/avastro/

Offline Herbert_W

  • PixInsight Addict
  • ***
  • Posts: 204
    • Skypixels - Astrophotography by Herbert Walter
Re: Elliptical Gradient Generator (for masks)
« Reply #5 on: 2017 November 13 01:04:33 »
Hi Adam!

That's a reasoned solution.
I've always searched for how to rotate an ellipse in Pixelmath - your Pixelmath expression is the solution!!

So far, I did it in my way - but have a look:

http://endor.uv.es/files/data/public/8e4405.php?lang=de

Best regards!

Herbert, Austria


Offline ngc1535

  • PixInsight Old Hand
  • ****
  • Posts: 326
Re: Elliptical Gradient Generator (for masks)
« Reply #6 on: 2017 November 13 07:06:08 »
Hi Herbert,

I see what you did- clever. There may be a better expression for the ellipse- but this is really the best I could figure out.
Perhaps OldWexi or Juan can instantly fashion something more elegant from their mathematical minds.  Math isn't my strength. :(

I think the other thing people should take away from my implementation is the construct of r/r_max . It is synonymous with X()  which is the normalized form of x() over the dimension of the image. Thus it can be used to create gradients of different kinds to fill a geometry. As long as the function stays in the range of 0 to 1- anything is possible.

Now... is there ANYONE out there that writes scripts that would work with me to make this a reality?

For purposes of programming- does the READOUT process pass or communicate the current coordinates of the cursor? This would be very useful for many kinds of tools I would think.

-adam


Offline RickS

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1298
Re: Elliptical Gradient Generator (for masks)
« Reply #7 on: 2017 November 13 18:04:37 »
Hi Adam,

I'm willing to have a go at the script but I'm juggling a lot of time commitments so it might not happen quickly.  If you can find someone else then I'd be happy to let them run with it...

Cheers,
Rick.

Offline ngc1535

  • PixInsight Old Hand
  • ****
  • Posts: 326
Re: Elliptical Gradient Generator (for masks)
« Reply #8 on: 2017 November 13 18:35:04 »
Hi Rick,

I am not terribly "connected" as it were in the community at this time- so please! In my mind's eye it seems fairly straight forward- but of course I am thinking of the high-level, not the programming details.

-adam

Offline Geoff

  • PixInsight Padawan
  • ****
  • Posts: 908
Re: Elliptical Gradient Generator (for masks)
« Reply #9 on: 2017 November 13 19:33:35 »
I am a little uneasy with the techniques discussed here and in the thread https://pixinsight.com/forum/index.php?topic=11816.0 .  They seem to be veering close to the concept of a hand painted mask so often used in some other applications.  Maybe what saves the day is that the masking procedure can be accurately documented.
Geoff

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: Elliptical Gradient Generator (for masks)
« Reply #10 on: 2017 November 13 20:15:13 »
Hi Geoff,

I entirely understand. In fact others can testify that I discussed this behind the scenes extensively before posting (I will not name names now... :) ). I do think in the case of getting rid of an extraneous glow (as I demonstrate in the second part of my video) there may be usage that is less offensive.

So here are some questions...

1. If a mask is made using MLT at a large enough scale that basically "captures" the two galaxies and ("large") bright stars (and subtract all other scales)- is this different than just specifying the galaxies? Is it that contours of the result (approximating an ellipse) are linked to the data? With enough adjustments (convolution, binarization..etc) the result seems similar and this seems to be a practice among processors.

2. Even more egregious, I suspect, is substitute by preview. Instead of modifying pixels based on a defined area (mask)- pixels are written to an image wholly from any manifestation. However substitution of pixels seems within the canon of if PI with its inclusion of scripts for this purpose.

I think this is a great time to discuss (certainly for me anyway) and understand the framework of the PI zeitgeist regarding specific tools.
I really do get the "Philosophy" you ascribe as a PI foundation. 
Presumably authors of the program permit or curtail tools based on these ideas.
On a personally note, I do not want to run afoul of the community... so this is a good time to correct course.

-adam


Offline RickS

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1298
Re: Elliptical Gradient Generator (for masks)
« Reply #11 on: 2017 November 13 21:23:02 »
Here's a post by Juan which talks about building geometric masks.  Unfortunately, there were some images referenced in his post that no longer exist:

https://pixinsight.com/forum/index.php?topic=2165.msg14245#msg14245

Cheers,
Rick.

Offline Herbert_W

  • PixInsight Addict
  • ***
  • Posts: 204
    • Skypixels - Astrophotography by Herbert Walter
Re: Elliptical Gradient Generator (for masks)
« Reply #12 on: 2017 November 13 22:48:58 »
Hi Geoff!

Quote
I think this is a great time to discuss (certainly for me anyway) and understand the framework of the PI zeitgeist regarding specific tools.
I really do get the "Philosophy" you ascribe as a PI foundation. 
Yes, that would be fine +1

Quote
I am a little uneasy with the techniques discussed here and in the thread https://pixinsight.com/forum/index.php?topic=11816.0 .  They seem to be veering close to the concept of a hand painted mask so often used in some other applications.

I opened a new topic in Image Processing Challenges - https://pixinsight.com/forum/index.php?topic=11826.0
Maybe it is possible to show a method without painting - but how?

For me it is not always easy to avoid "painting" in a picture because I lack some knowledge and skills in PixInsight.

Any help would be appreciated!
Thank you and best regards!
Herbert, Austria

Here is an example to mask the halo - corrrect?
http://endor.uv.es/files/data/public/f88d1c.php?lang=de

Offline RickS

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1298
Re: Elliptical Gradient Generator (for masks)
« Reply #13 on: 2017 November 13 23:48:10 »
I opened a new topic in Image Processing Challenges - https://pixinsight.com/forum/index.php?topic=11826.0
Maybe it is possible to show a method without painting - but how?

Take a look at my response :)

Offline Astrostar

  • Newcomer
  • Posts: 11
Re: Elliptical Gradient Generator (for masks)
« Reply #14 on: 2017 November 30 05:31:02 »
Hi Adam,

As a novice PI user thanks for your tutorial, it's just what I've been looking for. Thus far it's been the Bee's knees.  8)

Dave