New Feature : Background Subtraction

Discussions, Bug Reports and Issues related to Beta versions of SharpCap
ghayduke
Posts: 8
Joined: Thu Dec 28, 2017 7:43 pm

Re: New Feature : Background Subtraction

#41

Post by ghayduke »

Thanks for your prompt reply. Fair enough. You might emphasize that to use this tool images require a good flat correction in addition to dark subtraction, otherwise the algorithm will always read the vignetted part of the image, typically the corners, which is usually not what you want.
User avatar
admin
Site Admin
Posts: 13349
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: New Feature : Background Subtraction

#42

Post by admin »

Hi,

that's a good point, although it may be worth trying the linear gradient option if you have vignetting. That option looks for a 'least absolute deviation' fit to the darkest parts of the background measured in a grid of a few hundred boxes across the frame. The darkening at the edges/corners will not nicely match a linear gradient and should be largely ignored by the background fitting process as it tries to pull all four corners/edges down, but that isn't possible with a linear gradient fit.

cheers,

Robin
ghayduke
Posts: 8
Joined: Thu Dec 28, 2017 7:43 pm

Re: New Feature : Background Subtraction

#43

Post by ghayduke »

how about separate black point sliders for R, G, and B channels in the histogram adjustment window in addition to the global slider? that would essentially be the same thing as background subtraction for the live view and allow the user to adjust them on the fly. Adjusting the color balance sliders on the right is a multiplication, not a subtraction or addition.
Borodog
Posts: 341
Joined: Fri Jan 01, 2021 7:25 pm

Re: New Feature : Background Subtraction

#44

Post by Borodog »

Robin,

Are the linear and nonlinear gradient removal options implemented by division or subtraction? People in the EAA forum at CN have been reporting that sometimes these options cause black clipping, which I have personally observed at well. If they are implemented by division, this should not happen. The fit should essentially become like a synthetic flat.

ghayduke,

What you are looking to do can be done manually, although it will take a couple of minutes to set up. Set up to image as normal, including your flats and darks, and shoot a light. Open that light and your matching dark in GIMP, or another tool like it. Select a small region of the background of the light, copy and paste it to a new image, clone stamp or heal out any stars if there are any, then scale that image down to a 1x1 pixel image. This averages all of the pixels in the small section. Then scale it back up to the size of the light and dark, copy and past it as a layer on top of the dark. Set the layer mode to Addition. Export to a new synthetic dark (make sure to use the right bit depth and format), and change your dark in SharpCap to the new synthetic dark. The background will now be subtracted. If you don't want to subtract all of the background, which you probably don't because it will cause black clipping, use the Colors > Curves tool to linearly scale the background layer Value down somewhat, say to 90% instead of 100%.
ghayduke
Posts: 8
Joined: Thu Dec 28, 2017 7:43 pm

Re: New Feature : Background Subtraction

#45

Post by ghayduke »

Thanks. I have written a script in MaxIM DL to do this for my normal post-processed imaging with LRGB filters and mono camera using the "pixel math" command after getting the median value for a selected area in the frame. I was looking for something simpler for EAA.It seems like your method would work for monochrome (as does mine), but how does it work for a raw (non-debayered) RGB image where the background values are different in each channel?
User avatar
admin
Site Admin
Posts: 13349
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: New Feature : Background Subtraction

#46

Post by admin »

Hi folks,

the background removal is implemented using subtraction. The code is supposed to leave behind a roughly uniform pedestal value (2% or 5% histogram or something) to avoid black clipping, although it may not be enough if you are running at very high gain with a lot of histogram spread at the dark point. If anyone can send me images/settings that reproduce black clipping problems I will do my best to fix as that would be an issue.

I can't quite see how division would be the right thing to do for background removal as it seems to be a fundamentally subtractive operation to remove the light signal from the sky from the image.

Interesting the mention of the idea of individual R/G/B sliders to set black points per channel - I was thinking the other day that adding that sort of adjustment to the colour balance of live stacking might be useful - R/G/B offset sliders to equalize backgrounds of the channels and then the existing colour gains in live stacking to balance the image. But... for non-live stack situations why not just use the 'blended offset' background subtraction? That finds the darkest parts of the frame in each channel (which we presume to be the background) and uses those brightnesses for the subtraction.

cheers,

Robin
ghayduke
Posts: 8
Joined: Thu Dec 28, 2017 7:43 pm

Re: New Feature : Background Subtraction

#47

Post by ghayduke »

Thank you for explaining the blended offset, that is what I was looking for. I had assumed that the simple offset was doing that.
When post-processing in something like photoshop, I always set the individual channel black levels FIRST to give a neutral background, the idea being that, if the RGB camera is correctly color balanced to begin with (with a color chart or daylight image), removing color from the background by subtraction will effectively put the camera "above the atmosphere" and give a true rendering of the color of astronomical objects WITHOUT any monkeying with multiplicative color balance controls, or applying different curves to each channel. The only reason to do that would be to make a "prettier picture" emphasizing red nebulae or green nebulae, or whatever in the image, but that is not a natural color, it becomes "false color", or as an unimpressed non-Astronomy enthusiast friend of mine says, "so it is a fake." For EAA I believe it is best to try to show the natural color.
ghayduke
Posts: 8
Joined: Thu Dec 28, 2017 7:43 pm

Re: New Feature : Background Subtraction

#48

Post by ghayduke »

Brilliant! Works good on sample files (test camera 1), but simple offset and blended offset seem to do the same thing, see attached. One image with blue white light pollution, one with green airglow. If I can get this to work in live stacking it will be an excellent tool. Cloudy here for many days now...
Attachments
background subtraction tests.png
background subtraction tests.png (997.95 KiB) Viewed 672 times
Borodog
Posts: 341
Joined: Fri Jan 01, 2021 7:25 pm

Re: New Feature : Background Subtraction

#49

Post by Borodog »

Robin,

There's 2 things going on that people may be trying to correct with the "background subtraction" tool. There's subtracting light pollution, which will usually be at most a more or less linear gradient (there will be exceptions with higher order light pollution, such as exceptionally large fields of view), but then there's fixing non-uniform sensor illumination, either from skipping flats or having your flats not quite correct properly, yielding vignetting or anti-vignetting. The latter is more properly corrected by division. If you try to correct that by subtraction, it seems you are very likely to create black clipping.

It seems like the proper order of operations would be to do a division-based artificial flat correction first based on the higher-order fit of the background, and then subtract off a uniform background level to remove the light pollution.
User avatar
admin
Site Admin
Posts: 13349
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: New Feature : Background Subtraction

#50

Post by admin »

Hi,

for the blended/simple offset difference, the only change is how they affect pixels nearer maximum brightness. Simple offset might affect star colours if there is a lot of change to make to one channel, since it will affect all pixels by the same offset. Blended offset makes smaller adjustments to brighter pixels than it does to dim ones, meaning that the background correction is less likely to give odd star colours for saturated stars.

Mike, I must admit that I didn't realise people were trying to use background subtraction for vignetting correction/as a flat substitute. Yuck! It wasn't ever designed to do that and because it's purely subtractive then it won't do a great job at all. Still, I suppose it might be better than nothing for some situations. I don't want to change background subtraction in a way to make it work for that role, as it would make the subtraction more complex for all those sensible folk who use it for what it was designed for! If there was going to be something to solve that problem, it would end up being in the flat correction control as a special option in the same way that 'hot pixel removal' is there for darks. Interestingly, I suspect that vignetting may be modellable based on three parameters - x and y locations of the center of illumination and the radius of the fully illuminated area of the image. A solid theoretical model like that may make it possible to 'fit' a synthetic flat via Least-Absolute-Deviation to an image providing there is a good bit of uniform background...

cheers,

Robin
Post Reply