Author Topic: Dynamic Foreground Extraction  (Read 4227 times)

Offline georg.viehoever

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2132
Dynamic Foreground Extraction
« on: 2014 November 23 11:59:15 »
Hi,

I have a widefield of the Milkyway (see attached). When I process it as usual (Background Neutralization, ColorCalibration, HistogramTransformation), you can see the effect on color and brightness that the atmosphere at the horizon has: everything gets considerably more red and slightly more dark. While I can produce a very nice image that just accepts this effect, I have been experimenting with ways to get rid of the red horizon - basically giving the impression that I dont have the effect of the air mass. Here is what I tried:
  • background neutralization with DBE using subtraction. I use subtraction because all the brightness in the background is caused by atmospheric scattering of star light. Then
  • Calibrate the foreground to be white. Doing this via ColorCalibration works, but it does the same correction over the whole image, not considering the change in atmospheric transparency.
So what I would need in the second step is a ColorCalibration that considers varying color over the area of an image. I would need something like a DynamicForegroundExtraction (DFE) that extract the average color of stars over regions of an image, and creates a foreground map of star colors. Only, I dont have something like this in PI. :-\

I am looking for ideas on how the DFE could be done. Using DBE on a inverted image does not work - it still considers stars to be outliers - I would need them to be inliers and background as outliers. Once I have such a foreground FG image (produced with DFE) and a background BG image (produced with DBE), I believe I could to the color correction with Pixelmath using an expression like
Code: [Select]
off=0.1;
tmb=$T-BG;
fmb=FG-BG;
sum=fmb[0]+fmb[1]+fmb[2];
norm=fmb*3/sum;
norm2=iif(sum==0,1,norm);
norm3=max(0.5,min(2,norm2));
tmb/norm3+off

Anyone with good ideas?

Georg
Georg (6 inch Newton, unmodified Canon EOS40D+80D, unguided EQ5 mount)

Offline cdesselles

  • PixInsight Addict
  • ***
  • Posts: 164
Re: Dynamic Foreground Extraction
« Reply #1 on: 2014 November 23 14:57:56 »
Interesting topic and request. 

I don't believe I've heard of this type of request before.  Unfortunately I don't think I would be of any help, but I am all ears to hear what other may contribute.   :angel:
Celestron CPC1100 - Canon 550D (T2i) and of course, Pixinsight!

Offline oldwexi

  • PixInsight Guru
  • ****
  • Posts: 627
    • Astronomy Pages G.W.
Re: Dynamic Foreground Extraction
« Reply #2 on: 2014 November 24 10:46:34 »
Hi Georg!
I hope i understood your idea properly - i am not sure. Could be also the opposite...
So, using your fomula i started with the original image and not not with the DBE-Output,
as you remove in your formula again with "tmb=$T-bg" the Background.
So did an ABE but used only the resulting bg image and did no subtraction.

To create a fg image with mainly stars i use the Blend Script from Hartmut Bornemann
Extended by me with the attached formula. Very simple it looks for the edges in an Image
and based on the edge Parameter value it gets mor or less stars or foreground objects.
This formula is based on an idea of "Edoardo" ! ( i made it only "Script-Usable).

Than created with RangeMask a mask for the "ground".
Than your PixelMath Expression slightly changed to
off=0.15;
tmb=(iif($T<0.0001,0,$T-bg));
fmb=(iif(fg>bg,$T-bg,$T));
sum=fmb[0]+fmb[1]+fmb[2];
norm=fmb*3/sum;
norm2=iif(sum==0,1,norm);
norm3=max(0.5,min(2,norm2));
iif($T<0.0005,0,tmb/norm3+off)

Than using the fg Image as a mask did the colorcalibration
and some Satincrease of the stars with Curves S.

This resulted in the following Image which in my opinion shows some changes but i am
not sure if this are the changes you wanted to achieve:


Basically the Script uses this formula to achieve what i understand under fg Image.

var P = new PixelMath;
P.expression = "  IMG1 = Image05; IMG2 = Image05; MEDD = med(Image05);0.000 * IMG1 + 1.000 * (iif((x()==0||x()==w()-1 || y()==0 || y()==h()-1),0,iif((((sqrt((mean(-(pixel($T,x(),y())-pixel($T,x()-1,y())),(pixel($T,x(),y())-pixel($T,x()+1,y()))))^2+(mean(-(pixel($T,x(),y())-pixel($T,x(),y()-1)),(pixel($T,x(),y())-pixel($T,x(),y()+1))))^2))>edge)||($T>Fill)),1,0)))";
P.symbols = "IMG1, IMG2, MEDD, edge=0.07, Fill=0.8";

I could provide to you the Blend Script from Hartmut which i adapted.
So you could Play around if the results are "fg" as you mean it.
The Blend script allows also many 2 layer operations with masks.

Gerald

Offline Carlos Milovic

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2172
  • Join the dark side... we have cookies
    • http://www.astrophoto.cl
Re: Dynamic Foreground Extraction
« Reply #3 on: 2014 November 24 11:18:18 »
Geor, have you tried MorphologicalTransform to enlarge the size of the stars, and then make them more prominent? This way, DBE should detect them as valid samples, in the inverted image. Also increase the Tolerance and Shadows Relaxation parameters.

Regards,

Carlos Milovic F.
--------------------------------
PixInsight Project Developer
http://www.pixinsight.com

Offline vicent_peris

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 988
    • http://www.astrofoto.es/
Re: Dynamic Foreground Extraction
« Reply #4 on: 2014 November 24 14:57:12 »
Hi Georg,

Here you have an icon set. There are two DBE processes. The idea is to use one of them to correct the color and another to correct the illumination gradient of the background sky.

First apply the usual BN and CC processes to adjust the color of the image. Then clone the image and apply the first icon to correct the reddening of the objects. Then apply the second DBE process to the other image.

After correcting the DBE processes, delinearize both images in the same way, extract the lightness from the image where you applied the second DBE icon, and import this lightness into the image where you corrected the reddening.

These icons work with the image in horizontal position, having the horizon to the right.

Hope this helps.
Best regards,
Vicent.


Offline georg.viehoever

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2132
Re: Dynamic Foreground Extraction
« Reply #5 on: 2014 November 28 10:07:35 »

I hope i understood your idea properly - i am not sure. Could be also the opposite......
Gerald,
thanks for the proposal. I think you got the idea correctly. However, Vicent's method appears to work better  :'( , see below.
Georg
Georg (6 inch Newton, unmodified Canon EOS40D+80D, unguided EQ5 mount)

Offline georg.viehoever

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2132
Re: Dynamic Foreground Extraction
« Reply #6 on: 2014 November 28 10:37:51 »
Georg, have you tried MorphologicalTransform to enlarge the size of the stars, and then make them more prominent? This way, DBE should detect them as valid samples, in the inverted image. Also increase the Tolerance and Shadows Relaxation parameters.
Yes, I did try this, but I was not really happy with the result. I think some way to tell DBE to reverse its notion of foreground and background would be the best path.
Georg
Georg (6 inch Newton, unmodified Canon EOS40D+80D, unguided EQ5 mount)

Offline georg.viehoever

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2132
Re: Dynamic Foreground Extraction
« Reply #7 on: 2014 November 28 10:55:25 »
Hi Georg,

Here you have an icon set. There are two DBE processes. The idea is to use one of them to correct the color and another to correct the illumination gradient of the background sky.  ....
Hi Vicent,

this procedure works amazingly well. For the benefit of others, let me summarize how it works:

- after BN and CC, I clone and apply the first icon to correct the redening by DBE with division. You placed the samples on the background, chose a high tolerance and enabled "Unweight". This basically picks up pixels from both stars and background for the color correction.
- the original image sees the second icon, doing a DBE on the background with subtraction.
- the final steps combine the background corrected lightness with the equalized color.

Nice procedure, and the result is good - see screenshot (left corrected, right uncorrected - the horizon redening is much more visible than in the left image). I think the color correction in step 1 works because the background haze exhibits the same "average" color as the actual stars.

I still wonder if DBE it would be useful to extend DBE to detect structure and foreground, and then use it as a color correction tool doing BN and CC in a dynamic way. This would be relevant for wide field shots that approach the horizon, such as my Milkyway.

Maybe an idea for Juan to pick up at some point.

Thanks for the icons!

Georg
Georg (6 inch Newton, unmodified Canon EOS40D+80D, unguided EQ5 mount)