PixInsight Forum (historical)

PixInsight => Tutorials and Processing Examples => Topic started by: Salvatore Giambruno on 2017 November 07 21:04:58

Title: Star Removal Using StarMask and DefectMap
Post by: Salvatore Giambruno on 2017 November 07 21:04:58
I'm not sure if this technique has been covered by anyone before or if I am a the first, but a brief search of this forum and Google turn up nothing as far as I can tell, so I thought I'd share it here in any case.

Briefly, you create a good star mask from your final image (or any of its derivations) using the StarMask process (or by whatever method you prefer), invert the resulting star mask (stars to black), then use that star mask as a map in the DefectMap process to and apply it to the image. 

This technique works VERY well and results in very little degradation to image detail.  The larger stars usually require additional touch-up because as a large "defect" they are replaced with a wide average of the background which is apparent even after the application of the star removal process.

The key to using this technique effectively is to create an accurate star mask to begin with.  If one mask doesn't remove all the stars, simply create another star mask at the scale required to get all the stars you need at a particular scale.


(https://pixinsight.com/forum/index.php?action=dlattach;topic=11794.0;attach=14336;image)


Title: Re: Star Removal Using StarMask and DefectMap
Post by: pfile on 2017 November 08 10:02:06
very interesting technique! i will have to try this out.

thanks for sharing that.

rob
Title: Re: Star Removal Using StarMask and DefectMap
Post by: oldwexi on 2017 November 08 12:12:25
Hi Salvatore!
Interesting idea. Thanks for sharing it.
It took me some time to get the mask working as expected.
Couldnt get such a clean image as you got. Will have to test the variations of masks...

Did you do more than one step by using different masks?
See attached my try with linear image to get the stars removed from the molecular clouds.
But could not get the large stars proper removed.
Any tricks from your side for this available?
(http://www.werbeagentur.org/oldwexi/starless.jpg)

Gerald
Title: Re: Star Removal Using StarMask and DefectMap
Post by: starhopper on 2017 November 08 13:26:35
Thanks Salvatore for sharing this
Title: Re: Star Removal Using StarMask and DefectMap
Post by: mricard on 2017 November 08 21:08:12
Hi Salvatore,

I had a bit of trouble getting it to work at first but I found that if I had great results when I selected aggregate and binarize when I created my star mask and then binarized  the star mask

thanks for sharing!

Marc
Title: Re: Star Removal Using StarMask and DefectMap
Post by: pfile on 2017 November 08 21:17:57
yes i have been playing with this and it seems that the blacks really have to be pretty near 0 for the defectmap to do anything. the results were remarkably good when i forced the cores of the stars to be 0.0.

rob
Title: Re: Star Removal Using StarMask and DefectMap
Post by: Salvatore Giambruno on 2017 November 09 22:23:07
I'm happy to see that this technique is proving useful to some.  I've never been so clever as this, and it feels great to have come up with something original that even seasoned pros find useful.  ;D

I did mention in my original post that the trick to getting this technique to work correctly is in getting the mask just right.  And that means getting the stars to be the right size, and BINARIZING your values as Marc has stated.  DefectMap only works with BINARIZED pixels.  A pixel is either BAD (black, zero) or it is is not bad (anything other than zero).

Star masks can be tweaked using whatever techniques you like.  I've used intensity transformations, convolution and morphology tricks to get my masks to work best.  But remember, whatever processes you use, the last process should be a Binarize process.

If the problem with star removal is one of scale, you can always generate multiple masks at different scales and apply the DefectMap several times (I've done this).

Unfortunately, big stars cover a wide area and therefore a DefectMap fix will not be perfect.  Therefore, I believe it is best to remove your stars in the linear state, when stars are as small as possible.

Last but not least, CloneStamp is always a last resort . . .
Title: Re: Star Removal Using StarMask and DefectMap
Post by: pfile on 2017 November 09 23:25:54
i wonder if it makes sense to apply the DefectMask process thru a mask (perhaps a different one with smoother star edges) since all DM can do is treat pixels as good or bad with no "nuance". this might mitigate some of the harsh edges around large stars. need to try.

rob
Title: Re: Star Removal Using StarMask and DefectMap
Post by: Salvatore Giambruno on 2017 November 10 13:00:48
Hi Rob,

That's a great idea.  It's anyone's guess as to how it will work as far as filling in the large space for removed large stars, but I imagine that, at the very least, it will soften the edges of those removals . . .
Title: Re: Star Removal Using StarMask and DefectMap
Post by: GJL on 2017 November 11 01:48:09
Hi,

by the way, Defect Map. It takes hours to execute this tool, although I have an I7 PC. What´s my fault?

Regards   Gerhard
Title: Re: Star Removal Using StarMask and DefectMap
Post by: ngc1535 on 2017 November 11 07:17:15
Hi Salvatore,

For the past few years Fabian Neyer has been demonstrating a technique of star removal that is based on practices that professionals use. He cites this paper of showing the intragalactic glow between members of the virgo cluster:

http://iopscience.iop.org/article/10.1088/0004-637X/720/1/569/pdf

The technique you demonstrate is something like a first order approximation of the idea. The full technique employs some other clever steps including using MLT to calculate the local sky value of stars at different scales. When you use the defect map, you are only using those pixels that are immediate neighbors to your regions. But varying the scale of MLT you can properly get better sky values (and therefore substitution) for the stars. In addition, and this is really clever- you can create a sky subtracted star images that you blur and then subtract from the real data in order to get rid of stellar halos and the wings of PSFs. This takes care of OldWexi's question.

(on a note of computing, Fabian's technique does not require the computational overhead of what the defect map does by looking at each neighbor pixel.)

I just completed an image that uses Fabian's technique. Below is a version of SH2-68 before and after star removal. (I did not see the black levels the same...just quickly grabbed). If there is interest, I can post my version of this tutorial (I will ask Fabian... but I think it isn't a problem). I added a few variations to Fabian's technique. It is a longer process, but the results are commensurate with the effort.

(http://www.caelumobservatory.com/mlsc/sh2_68_stars.jpg)
(http://www.caelumobservatory.com/mlsc/starless_ha.jpg)


-adam
Title: Re: Star Removal Using StarMask and DefectMap
Post by: avastro on 2017 November 11 09:50:18
Hi Adam,
I'm interested to learn your technique to remove the stars using Rudick approach.
regards
Antoine
Title: Re: Star Removal Using StarMask and DefectMap
Post by: sleshin on 2017 November 11 09:59:39
+1

Steve
Title: Re: Star Removal Using StarMask and DefectMap
Post by: Geoff on 2017 November 11 11:59:48
+2
Geoff
Title: Re: Star Removal Using StarMask and DefectMap
Post by: kolec on 2017 November 11 12:18:28
+3
kolec
Title: Re: Star Removal Using StarMask and DefectMap
Post by: MikeOates on 2017 November 11 15:23:20
Adam,

Quote
If there is interest, I can post my version of this tutorial

You bet there is +4

Mike
Title: Re: Star Removal Using StarMask and DefectMap
Post by: ngc1535 on 2017 November 11 16:26:26
Great...I will work on creating a video. I will demonstrate Fabian Neyer's approach.
THanks,
Adam
Title: Re: Star Removal Using StarMask and DefectMap
Post by: kolec on 2017 November 11 23:34:23
Super
Title: Re: Star Removal Using StarMask and DefectMap
Post by: pscammp on 2017 November 12 07:24:22
Super +1

Paul
Title: Re: Star Removal Using StarMask and DefectMap
Post by: Salvatore Giambruno on 2017 November 17 12:49:58
Gerhard,

It sounds like you forgot to INVERT the star mask.  The mask stars should be black, the background white.

Sal

Hi,

by the way, Defect Map. It takes hours to execute this tool, although I have an I7 PC. What´s my fault?

Regards   Gerhard
Title: Re: Star Removal Using StarMask and DefectMap
Post by: Salvatore Giambruno on 2017 November 17 12:53:57
Rob,

If I recall correctly, I recently tried to apply the DefectMap to an image that had an active mask and got an error message.  I think the DefectMap process can only be applied to "maskless" images.

i wonder if it makes sense to apply the DefectMask process thru a mask (perhaps a different one with smoother star edges) since all DM can do is treat pixels as good or bad with no "nuance". this might mitigate some of the harsh edges around large stars. need to try.

rob
Title: Re: Star Removal Using StarMask and DefectMap
Post by: Salvatore Giambruno on 2017 November 17 13:05:06
Thanks for sharing, adam. 

Fabian's sounds like an interesting technique - I'll be sure to check it out as soon as I get a chance. 

I think you tried to explain why the sky background levels are different in the before/after images you posted as an example, but I'm not sure I understand the explanation.  Correct me if I am mistaken, but I believe you were trying to explain that the difference was not a shortcoming of Fabian's process, but that it turned out that way as a result of you rushing to prepare the example.

Hi Salvatore,

For the past few years Fabian Neyer has been demonstrating a technique of star removal that is based on practices that professionals use. He cites this paper of showing the intragalactic glow between members of the virgo cluster:

http://iopscience.iop.org/article/10.1088/0004-637X/720/1/569/pdf

The technique you demonstrate is something like a first order approximation of the idea. The full technique employs some other clever steps including using MLT to calculate the local sky value of stars at different scales. When you use the defect map, you are only using those pixels that are immediate neighbors to your regions. But varying the scale of MLT you can properly get better sky values (and therefore substitution) for the stars. In addition, and this is really clever- you can create a sky subtracted star images that you blur and then subtract from the real data in order to get rid of stellar halos and the wings of PSFs. This takes care of OldWexi's question.

(on a note of computing, Fabian's technique does not require the computational overhead of what the defect map does by looking at each neighbor pixel.)

I just completed an image that uses Fabian's technique. Below is a version of SH2-68 before and after star removal. (I did not see the black levels the same...just quickly grabbed). If there is interest, I can post my version of this tutorial (I will ask Fabian... but I think it isn't a problem). I added a few variations to Fabian's technique. It is a longer process, but the results are commensurate with the effort.


-adam
Title: Re: Star Removal Using StarMask and DefectMap
Post by: pfile on 2017 November 17 14:33:57
Rob,

If I recall correctly, I recently tried to apply the DefectMap to an image that had an active mask and got an error message.  I think the DefectMap process can only be applied to "maskless" images.

i wonder if it makes sense to apply the DefectMask process thru a mask (perhaps a different one with smoother star edges) since all DM can do is treat pixels as good or bad with no "nuance". this might mitigate some of the harsh edges around large stars. need to try.

rob

hmm, it seems to have worked for me, but it seemed that i needed to tune the mask... it needs to have much softer edges than the mask i produced for DefectMap.

rob
Title: Re: Star Removal Using StarMask and DefectMap
Post by: GJL on 2017 November 18 01:18:11
+4

Gerhard
Title: Re: Star Removal Using StarMask and DefectMap
Post by: mbel on 2017 November 22 12:02:51
If there is interest, I can post my version of this tutorial (I will ask Fabian... but I think it isn't a problem). I added a few variations to Fabian's technique. It is a longer process, but the results are commensurate with the effort.

I am also interested to try it.
Title: Re: Star Removal Using StarMask and DefectMap
Post by: ngc1535 on 2017 November 22 14:57:29
Hi Salvatore,

Thanks for writing. By the way, I felt a little bad about bringing up Fabian's example in your thread. I somewhat hijacked your post. Sorry about that.
Concerning the background, yes you are correct. The dark background was just my non-linear stretch that I actually used when I blended in the data. The background is unchanged in process of removing stars. I just didn't have the non-linear image of the stars removed with a lighter background that is all.

To everyone that might read this- I connected with Fabian...and I am working on making the video. However, he is in the process of reviewing my work (it is his implementation of this technique in PI after all)- and he is a busy guy! So it is still a work in progress... but very much in play.

-adam


Thanks for sharing, adam. 

Fabian's sounds like an interesting technique - I'll be sure to check it out as soon as I get a chance. 

I think you tried to explain why the sky background levels are different in the before/after images you posted as an example, but I'm not sure I understand the explanation.  Correct me if I am mistaken, but I believe you were trying to explain that the difference was not a shortcoming of Fabian's process, but that it turned out that way as a result of you rushing to prepare the example.

Hi Salvatore,

For the past few years Fabian Neyer has been demonstrating a technique of star removal that is based on practices that professionals use. He cites this paper of showing the intragalactic glow between members of the virgo cluster:

http://iopscience.iop.org/article/10.1088/0004-637X/720/1/569/pdf

The technique you demonstrate is something like a first order approximation of the idea. The full technique employs some other clever steps including using MLT to calculate the local sky value of stars at different scales. When you use the defect map, you are only using those pixels that are immediate neighbors to your regions. But varying the scale of MLT you can properly get better sky values (and therefore substitution) for the stars. In addition, and this is really clever- you can create a sky subtracted star images that you blur and then subtract from the real data in order to get rid of stellar halos and the wings of PSFs. This takes care of OldWexi's question.

(on a note of computing, Fabian's technique does not require the computational overhead of what the defect map does by looking at each neighbor pixel.)

I just completed an image that uses Fabian's technique. Below is a version of SH2-68 before and after star removal. (I did not see the black levels the same...just quickly grabbed). If there is interest, I can post my version of this tutorial (I will ask Fabian... but I think it isn't a problem). I added a few variations to Fabian's technique. It is a longer process, but the results are commensurate with the effort.


-adam
Title: Re: Star Removal Using StarMask and DefectMap
Post by: kolec on 2017 November 23 04:09:49
hi

I know that it is not perfekt , but I try Fabians metod ( from CEDIC 2015 + 2017)

http://astrofotky.cz/gallery.php?show=kolec/1511168392.jpg

kolec

Title: Re: Star Removal Using StarMask and DefectMap
Post by: pfile on 2017 November 23 09:03:13
since PI can model star profiles with DynamicPSF, i wonder if there is a star removal method that could at least use PSFs to figure out what pixels need to be replaced. it seems like that could lead to a pretty accurate star removal.

rob
Title: Re: Star Removal Using StarMask and DefectMap
Post by: msmythers on 2017 November 23 09:08:54
rob

That's an interesting thought ::)


Mike
Title: Re: Star Removal Using StarMask and DefectMap
Post by: msmythers on 2017 November 23 09:58:03
Just for fun I took my 45mm shot of Cygnus and decided to see what the DefectMap could do. So first this is a simple image processing. ABE and then extract the red channel from the RGB. I use STF with HistogramTransformation for the stretch. Now the decided to try the ClassicStarMask script to generate the star mask. I then inverted the mask. Next I used Binarize with a very high setting of 0.97. This is the mask for the DefectMap to use.

I think it turned out very well for such a low resolution image. On the left is the full image and on the right is a 3:1 scaling of the section with Sadr.

Mike
Title: Re: Star Removal Using StarMask and DefectMap
Post by: msmythers on 2017 November 23 10:06:38
And from the same image the section of the NGC7000.



Mike
Title: Re: Star Removal Using StarMask and DefectMap
Post by: Dimitris Platis on 2017 November 24 06:27:10
Really looking forward for the video-demonstration of Fabian's method!
Title: Re: Star Removal Using StarMask and DefectMap
Post by: pscammp on 2017 November 24 11:36:56
Me Too
Title: Re: Star Removal Using StarMask and DefectMap
Post by: MikeOates on 2017 November 24 13:47:45
Hi Mike,

I wanted to try your method using ClassicStarMask (not used it before) but when I ran it, I got the following error.

Code: [Select]
Processing script file: C:/Program Files/PixInsight/src/scripts/ClassicStarMask.js
*** Error [001]: C:/Program Files/PixInsight/src/scripts/ClassicStarMask.js, line 50: ReferenceError: HDRWaveletTransform is not defined

Does this work in 1.8.5 ?

Mike
Title: Re: Star Removal Using StarMask and DefectMap
Post by: msmythers on 2017 November 24 14:47:45
Hi Mike

Yep that's what I'm running. This is the script so you can do a quick compare of the beginning code if you want. Also what console should look like while executing.


Mike
Title: Re: Star Removal Using StarMask and DefectMap
Post by: MikeOates on 2017 November 24 15:08:37
Thanks for that Mike,

My script at line 50 says:
var HDRW = new HDRWaveletTransform;

While yours has:
var HDRW = new HDRMultiscaleTransform;

The same code is used a few times, so perhaps I have the wrong version, but I don't see any other to download. I got it from:
https://pixinsight.com/forum/index.php?topic=3410.5

Mike
Title: Re: Star Removal Using StarMask and DefectMap
Post by: msmythers on 2017 November 24 15:32:48
Not Sure Mike. I know many years ago I changed the lines in the code to HDRMultiscale to make it work but this install of 1.8.5 is completely fresh I thought. You can search the code and change the instances of HDRWaveletTransform to HDRMultiscaleTransform and everything should work. I can't remember when HDRWaveletTransform was retired but the parameters seemed to be the same as HDRMultiscale but I'm sure the math is different and better. The script with Multiscale produces a mask and with a little extra help seemed to work for my 45mm needs. I don't think there are any other bombs in the code :surprised: 

I do like PI for fact that we can make changes in the scripts or for that matter the real code. I'm not a programmer or someone who could write a script from scratch but PI provides enough info in the console that I can hack my way through issues. 


Mike
Title: Re: Star Removal Using StarMask and DefectMap
Post by: Salvatore Giambruno on 2017 November 24 21:56:59
No worries about hijacking, Adam - except for the explosive keyword itself, lol.

Looking forward to seeing the video.

-Sal


Hi Salvatore,

Thanks for writing. By the way, I felt a little bad about bringing up Fabian's example in your thread. I somewhat hijacked your post. Sorry about that.
Concerning the background, yes you are correct. The dark background was just my non-linear stretch that I actually used when I blended in the data. The background is unchanged in process of removing stars. I just didn't have the non-linear image of the stars removed with a lighter background that is all.

To everyone that might read this- I connected with Fabian...and I am working on making the video. However, he is in the process of reviewing my work (it is his implementation of this technique in PI after all)- and he is a busy guy! So it is still a work in progress... but very much in play.

-adam


Thanks for sharing, adam. 

Fabian's sounds like an interesting technique - I'll be sure to check it out as soon as I get a chance. 

I think you tried to explain why the sky background levels are different in the before/after images you posted as an example, but I'm not sure I understand the explanation.  Correct me if I am mistaken, but I believe you were trying to explain that the difference was not a shortcoming of Fabian's process, but that it turned out that way as a result of you rushing to prepare the example.

Hi Salvatore,

For the past few years Fabian Neyer has been demonstrating a technique of star removal that is based on practices that professionals use. He cites this paper of showing the intragalactic glow between members of the virgo cluster:

http://iopscience.iop.org/article/10.1088/0004-637X/720/1/569/pdf

The technique you demonstrate is something like a first order approximation of the idea. The full technique employs some other clever steps including using MLT to calculate the local sky value of stars at different scales. When you use the defect map, you are only using those pixels that are immediate neighbors to your regions. But varying the scale of MLT you can properly get better sky values (and therefore substitution) for the stars. In addition, and this is really clever- you can create a sky subtracted star images that you blur and then subtract from the real data in order to get rid of stellar halos and the wings of PSFs. This takes care of OldWexi's question.

(on a note of computing, Fabian's technique does not require the computational overhead of what the defect map does by looking at each neighbor pixel.)

I just completed an image that uses Fabian's technique. Below is a version of SH2-68 before and after star removal. (I did not see the black levels the same...just quickly grabbed). If there is interest, I can post my version of this tutorial (I will ask Fabian... but I think it isn't a problem). I added a few variations to Fabian's technique. It is a longer process, but the results are commensurate with the effort.


-adam
Title: Re: Star Removal Using StarMask and DefectMap
Post by: Salvatore Giambruno on 2017 November 24 22:02:20
Mike,

That came out well.  It's all about getting the starmask and binarizing tweaked just right.  Works great on small to medium stars - it's always the large stars that are difficult to remove/replace.  Thanks for posting your effort.

Just for fun I took my 45mm shot of Cygnus and decided to see what the DefectMap could do. So first this is a simple image processing. ABE and then extract the red channel from the RGB. I use STF with HistogramTransformation for the stretch. Now the decided to try the ClassicStarMask script to generate the star mask. I then inverted the mask. Next I used Binarize with a very high setting of 0.97. This is the mask for the DefectMap to use.

I think it turned out very well for such a low resolution image. On the left is the full image and on the right is a 3:1 scaling of the section with Sadr.

Mike
Title: Re: Star Removal Using StarMask and DefectMap
Post by: MikeOates on 2017 November 25 04:32:17
Thanks Mike, did as you suggested and that worked fine.

Mike
You can search the code and change the instances of HDRWaveletTransform to HDRMultiscaleTransform and everything should work.   
 
Mike
Title: Re: Star Removal Using StarMask and DefectMap
Post by: msmythers on 2017 November 25 08:11:07
Salvatore

Thanks. I've been trying to find a decent method since 1.8.5 came out. In 1.8.4 I used Carlo's TGVInpaint with great success but that module no longer works in 1.8.5


Mike
Title: Re: Star Removal Using StarMask and DefectMap
Post by: msmythers on 2017 November 25 08:12:19
Mike

Good to hear you've got the script working :smiley:


Mike