New Script to Automatically find the background ROI in PixInsight Pleiades Astrophoto PixInsight · Franklin Marek · ... · 26 · 2070 · 7

seti_v2 19.05
...
· 
·  25 likes
·  Share link
Gerrit Erdt and I jointly developed a new and much improved script to find background in astronomical images. 

Video explaining the new script:  LinkToYoutubeVideo

Screenshot 2024-05-26 074613.jpg

What problem does it solve:
In images of dense star fields or nebula, it is often hard or close to impossible to find a region where you are sure that there are no objects.
FindBackground is able to quickly and reliably find a very good background estimate or the best possible background estimate based on your parameters. 

What is the result after application:
The script creates a preview covering the found background region and prints all relevant information about it to the console. This includes the average background brightness per channel, additive color correction constants, and the coordinates of the found region. 

Requirements:
- Gradients must have been removed. Otherwise, it will just chase the gradient and converge on a place with the lowest gradient impact.
- Stacking artifacts at the edges must have been removed for the same reason. 

How to use the script:
You can apply the script to monochrome and color images.
For most images, the default parameters should work well, so you can immediately apply the script to any of the open images.
It will, per default, create a preview covering the background and print information about it to the console.For more complex cases, you can adapt all relevant parameters.

The complete documentation of every functionality can be found in the tooltips of the script. Yes, every element on there has a tooltip! 

Known limitations:
Currently, none. 

Installation:
Add my repository to your updates repository list (be sure to click the link then copy the full URL from the address bar):https://raw.githubusercontent.com/setiastro/pixinsight-updates/main/
You can manage your update repository list under Resources -> Updates -> Manage Repositories -> Add
It will install this script, and all my other scripts. You can find them under Script -> SetiAstro 

For a standalone download, you can use this link to my website: https://www.setiastro.com/pjsr-scripts

In case you have any questions, please reach out!!

[email][email protected][/email]
[email][email protected][/email]

We hope you enjoy the script and it simplifies your process!
Edited ...
Like
Giulio 1.51
...
· 
·  Share link
Hi Franklin,
I tried to install the script but Pixinsight gives this error:
Repository URL : https://raw.githubusercontent.com/setiastro/pixinsight-updates/main/
Signature : <* unavailable *>
Authorized : false
Available packages : 0
Selected packages : 0
Error log:
https://raw.githubusercontent.com/setiastro/pixinsight-updates/main/: Parsing repository update information: Parsing Signature element (line=1 offset=0): Unknown code signing identity 'FranklinMarek'
Like
apo20232 0.90
...
· 
·  Share link
Franklin,

Great script. I appreciate the effort to develop this, and your other recent scripts. They certainly help streamline my workflow.

Jim
Like
MalcolmPark 0.00
...
· 
·  Share link
repository doesnt work 

image.png
Like
seti_v2 19.05
Topic starter
...
· 
·  2 likes
·  Share link
If you havent upgraded to PixInsight build 1605 (which came out in March) I highly recommend you do that as all scripts are going to require signatures going forward.  You do this from the PixInsight download site. This will fix the error if you are trying to use the repository. 

If you still run into a parsing error or signature error you can download the zip file directly from my website and then just extract the .js files (delete the .xsgn file).  You can then go to Scripts -> Feature Scripts -> Add Script and select the folder you extracted the .js file too. 

Let me know if this helps 

Frank
Edited ...
Like
CWTauri 22.98
...
· 
·  1 like
·  Share link
Frank,

One of the places the calculation of the background is commonly encountered by users is SPCC. 
You mention the avoidance of stars as a feature of your script to find a relevant background area.
As you know PixInsight developers use the median absolute deviation of the median to accomplish this feat.
In doing so previews of the background can be selected that include stars (but not nebulosity) and given an appropriate size of the preview can have good statistics with the large sampling (number of pixels) of the area.
I have made public for purposes of this conversation (temporarily) my video on this subject here:
https://www.adamblockstudios.com/articles/spcc-background-neutralization

Given the above it seems natural to compare the results of your small samples with large samples employing the MedADmed.
Can you provide the statistics of the results (showing meaningful differences in larger samples with stars using MedADmed) and indicate if you intended your script to in some way supplant or make easier the choice of background vis-a-vis background neutralization in SPCC (again, the most front facing example of when the calculation is important). You indicate you should never use it- which is a strong statement since this is what is used in SPCC. That is certainly a critique. In addition, I didn't understand the symmetry comment- you can asymmetrically apply the sigma thresholds. 

-adam
Like
seti_v2 19.05
Topic starter
...
· 
·  Share link
Yes, I understand that the background neutralization disregards values above some threshold (I believe 0.1 is the default).  The bigger goal was it avoid nebulosity to find a good background.  Star avoidance came about directly from the method of gradient descent. 

In my video I am not referring to MAD that PI utilizes.  The checkbox in this script is looking at the Absolute value of the difference in the median and mean and not the Median Absolute Difference, in the tooltip we say that you shouldnt confuse that checkbox with MAD that PI uses.  This checkbox filter would measure 0 if the mean and median were the same which is what would happen in perfectly normal distribution, hence my symmetric statement.  By default it is unchecked as astro images dont exhibit this behavoir.  My collaborator Gerrit wanted to keep it in as an option if a user chooses to check it.

Hope that clear up the confusion between that checkbox and MAD in PI (again different things)

Frank
Edited ...
Like
CWTauri 22.98
...
· 
·  Share link
Frank,

You need to continue please.
Gradient descent appears to be a clever way to find a background sample. However, once done the question I am asking is whether the offsets calculated for each channel are any different given this selection. As I mention, you can include stars when using the the MedADmed . The distinction I think you are making is that gradient descent automates the choice rather than me selecting a box using my eyes and brain. I do not worry about stars..just about background nebulosity. 
The question is do I need to run the script for SPCC (perhaps in advance)- what is the benefit? Are the offsets different in a meaningful way given my eye/brain choice compared with gradient descent? Can you provide some counterexamples?

-adam
Like
CWTauri 22.98
...
· 
·  Share link
Frank,

And I am confused about your comment "Background neutralization disregards values above some threshold (0.1)…" This isn't what background neutralization in SPCC is doing (please watch my video). An absolute value was discarded a few years ago in favor of the MedADmed.

-adam
Edited ...
Like
seti_v2 19.05
Topic starter
...
· 
·  Share link
Adam Block:
Frank,

And I am confused about your comment "Background neutralization disregards values above some threshold (0.1)..." This isn't what background neutralization in SPCC is doing (please watch my video). An absolute value was discarded a few years ago in favor of the MedADmed.

-adam

 I thought you were referring to the process BackgroundNeutralization which does have an upper limit threshold for the background.  I also agree that stars in the background for SPCC specifically dont matter as they already robustly filter for that.

The script though is intended to avoid nebulosity (which can be a hard thing to find sometimes by eye) and find a good background for use.  The way gradient descent is working it will also avoid stars.  Which is also beneficial for processes like BackgroundNeutralization or ColorCalibration.

In my video I also used SPCC just as an example of where the background region of interest can be used.  There are numerous processes a user may want a background region of interest.

Frank
Like
CWTauri 22.98
...
· 
·  Share link
Franklin Marek:
Adam Block:
Frank,

And I am confused about your comment "Background neutralization disregards values above some threshold (0.1)..." This isn't what background neutralization in SPCC is doing (please watch my video). An absolute value was discarded a few years ago in favor of the MedADmed.

-adam

 I thought you were referring to the process BackgroundNeutralization which does have an upper limit threshold for the background.  I also agree that stars in the background for SPCC specifically dont matter as they already robustly filter for that.

The script though is intended to avoid nebulosity (which can be a hard thing to find sometimes by eye) and find a good background for use.  The way gradient descent is working it will also avoid stars.  Which is also beneficial for processes like BackgroundNeutralization or ColorCalibration.

In my video I also used SPCC just as an example of where the background region of interest can be used.  There are numerous processes a user may want a background region of interest.

Frank

*That is a bit unfair Frank. I took time to construct my question very carefully to avoid this very issue in my first sentence and I went on to explain why I thought it is the most important process where this matters. SPCC is the standard for color calibration and this instance of  background neutralization  is where the vast majority of users will want to know "Should I use Frank's cool script or not?" "What are the benefits?" People want a workflow...they want steps. I am someone that wants/needs to answer these questions. For example, I understand sometimes "it is hard to avoid nebulosity"- but I also know that sky values typically out number nebula values (unless you are really careless) when a preview is drawn. The mean of the background pixel samples will win. My point is that this is something you can measure and see if it is important. It appears you are leaving it up to me to do the analysis. I am suggesting this could be part of your work when creating tools. (Or delegating this to others such as myself *with* an explanation that helps... which is what I am looking for.)

-adam
Like
seti_v2 19.05
Topic starter
...
· 
·  Share link
Adam

I apologize for my quick response initially and not constructing my response to yours more carefully.  I was very focused on explaining that we were not referring to MAD that PI uses (of which was said in the video and in the tooltip) and was careless of the other parts of my reply.  On images where there is a lot of background, I agree you should be able to easily draw a background.  For images that have a lot of nebulosity it may be easy to accidentally include dim nebulosity in your preview.  This will change the calculated background.  Depending on the person processing the image this may or may not be as important as it is to others.  Part of the niceness with it being a script is the drag and drop ability to put a background ROI without having to do it by eye. 

As to measured changes in balance in the image based on different selected backgrounds that include varying amounts of nebulosity, that is an exercise I could have done as part of the explanation and is really constructive feedback on future projects as to what the community would like to see in the explanation of a script.  I do appreciate the time you spent looking at it and providing the feedback.

Frank
Like
CWTauri 22.98
...
· 
·  Share link
Franklin Marek:
Adam

I apologize for my quick response initially and not constructing my response to yours more carefully.  I was very focused on explaining that we were not referring to MAD that PI uses (of which was said in the video and in the tooltip) and was careless of the other parts of my reply.  On images where there is a lot of background, I agree you should be able to easily draw a background.  For images that have a lot of nebulosity it may be easy to accidentally include dim nebulosity in your preview.  This will change the calculated background.  Depending on the person processing the image this may or may not be as important as it is to others.  Part of the niceness with it being a script is the drag and drop ability to put a background ROI without having to do it by eye. 

As to measured changes in balance in the image based on different selected backgrounds that include varying amounts of nebulosity, that is an exercise I could have done as part of the explanation and is really constructive feedback on future projects as to what the community would like to see in the explanation of a script.  I do appreciate the time you spent looking at it and providing the feedback.

Frank

*Thank you for the reply. I appreciate it.
-adam
Like
seti_v2 19.05
Topic starter
...
· 
·  Share link
All

I made a video going through why your background ROI matters. How it changes the results of BackgroundNeutraluzation, ColorCalibration, and even SPCC

https://youtu.be/NJAGt-Yjyiw
Like
seti_v2 19.05
Topic starter
...
· 
·  1 like
·  Share link
.
Edited ...
Like
seti_v2 19.05
Topic starter
...
· 
·  Share link
Pretty big update in the script.  I have added a User Defined Search Area.  Perfect for those times where you couldn't remove the gradient fully, want to avoid a dark dust mote, avoid a dark nebula, or any other reason the user may want to restrict the search area of the image.  If you have my repository link in PI you already have the update!  If using the User Defined Search Region, I recommend reducing the Number of Starting Points since you are now only looking at a smaller portion of the main image or doing a Slow Search in the new Defined Region. 

I hope this will really help in those very complicated cases!

Screenshot 2024-06-03 085107.jpg

If anyone has any questions please reach out!!

Frank
Edited ...
Like
neverfox 3.32
...
· 
·  Share link
Franklin Marek:
Pretty big update in the script.  I have added a User Defined Search Area.  Perfect for those times where you couldn't remove the gradient fully, want to avoid a dark dust mote, avoid a dark nebula, or any other reason the user may want to restrict the search area of the image.  If you have my repository link in PI you already have the update!  If using the User Defined Search Region, I recommend reducing the Number of Starting Points since you are now only looking at a smaller portion of the main image or doing a Slow Search in the new Defined Region. 

I hope this will really help in those very complicated cases!

Screenshot 2024-06-03 085107.jpg

If anyone has any questions please reach out!!

Frank

Thanks very cool, but one thing I could see wanting is the ability to specify multiple UDSAs rather than one contiguous one e.g. you might choose not just the lower right but the upper left, top, bottom right etc., avoiding the dark target. It's often the case that you can identify likely regions but having to choose limits ones ability somewhat to take maximum advantage of the automation in the context of that knowledge.
Edited ...
Like
seti_v2 19.05
Topic starter
...
· 
·  1 like
·  Share link
Roman Pearah:
Franklin Marek:
Pretty big update in the script.  I have added a User Defined Search Area.  Perfect for those times where you couldn't remove the gradient fully, want to avoid a dark dust mote, avoid a dark nebula, or any other reason the user may want to restrict the search area of the image.  If you have my repository link in PI you already have the update!  If using the User Defined Search Region, I recommend reducing the Number of Starting Points since you are now only looking at a smaller portion of the main image or doing a Slow Search in the new Defined Region. 

I hope this will really help in those very complicated cases!

Screenshot 2024-06-03 085107.jpg

If anyone has any questions please reach out!!

Frank

Thanks very cool, but one thing I could see wanting is the ability to specify multiple UDSAs rather than one contiguous one e.g. you might choose not just the lower right but the upper left, top, bottom right etc., avoiding the dark target. It's often the case that you can identify likely regions but having to choose limits ones ability somewhat to take maximum advantage of the automation.

Great suggestion, not sure how to code that, but not knowing how to code hasnt stopped me yet!  Or maybe have an option to define exclusion areas (like ctrl+click for exclusion, shift+click for inclusion area).  I am all for trying to make these tools the best they can be!

Frank
Like
seti_v2 19.05
Topic starter
...
· 
·  1 like
·  Share link
You asked for it! 

MAJOR UPDATE: Now supports defining multiple user defined areas.  3 options now.  Full Image Search, User Defined Search Areas, User Defined Exclusion Areas.  Depending on your image you may find it easier to define a couple sections you want to exclude from the search or conversely define some sections you exclusively want to search.  There is a reset button next to the checkboxes to clear and reset your areas.

Repository and my website updated for the newest version!

multiarea.png
Like
neverfox 3.32
...
· 
·  Share link
Franklin Marek:
You asked for it! 

MAJOR UPDATE: Now supports defining multiple user defined areas.  3 options now.  Full Image Search, User Defined Search Areas, User Defined Exclusion Areas.  Depending on your image you may find it easier to define a couple sections you want to exclude from the search or conversely define some sections you exclusively want to search.  There is a reset button next to the checkboxes to clear and reset your areas.

Repository and my website updated for the newest version!

multiarea.png

Awesome! That was fast!
Like
drmikevt 0.00
...
· 
·  Share link
As long as you're at it - maybe make exclusion boxes red and inclusion boxes green?  I just tried it out and it looks like you can define both exclusion and inclusion areas on the same image.  However, all of the boxes are red and so there is no way to tell which is which.  

Also, I think the instructions should say 'Shift+Click to define User Defined Areas in the preview image to the right (multiple inclusion and/or exclusion boxes allowed)….

Anyway, thanks for a lovely tool 

Mike
Like
seti_v2 19.05
Topic starter
...
· 
·  Share link
The algorithm only uses the regions as either inclusion or exclusion strictly based on whether the checkbox is selected to User Defined Search Area or User Defined Exclusion Area.  It is either one or the other.  The areas are just that, areas you selected.  The choice of the checkbox is the determining factor.

I can code it if you switch to the other checkbox it just clears the areas.  I can also change the color based on the checkbox.  Doesnt change the function at all though.

Frank
Like
drmikevt 0.00
...
· 
·  Share link
I see - the way it behaves now, it SEEMS like you can add both kinds of boxes since the boxes persist when you change the checkbox.  So, maybe clearing the area if the checkbox is changed is best

Mike
Like
seti_v2 19.05
Topic starter
...
· 
·  Share link
I see - the way it behaves now, it SEEMS like you can add both kinds of boxes since the boxes persist when you change the checkbox.  So, maybe clearing the area if the checkbox is changed is best

Mike

Yes I can make that change.  Clearing it out will emphasize it is one or the other too.  Might as well make the colors green if you are drawing on one and red on the other too

The other things is drawing these areas should be the rarity.  You want the script searching as much of your image as you can

Frank
Like
seti_v2 19.05
Topic starter
...
· 
·  Share link
V1.2.1 updated.  Rectangles clear when switching between search modes.  Green color for inclusion and red for exclusion as a visual reminder for what mode you are in.  Now I need some sleep hahaha.
Like
 
Register or login to create to post a reply.