NEUBIAS / training-resources

Resources for teaching/preparing to teach bioimage analysis
https://neubias.github.io/training-resources
Other
46 stars 21 forks source link

local background subtraction #104

Open manerotoni opened 3 years ago

manerotoni commented 3 years ago

Hello @tischi , I was trying different ways to subtract local background from xy_8bit__spots_local_background_with_noise.

A quick look at the data (using a line profile) indicates that the spot over the brighter background is in fact slightly dimmer than the one on the darker background. If we do a background subtraction using a 40radius median image the results looks quite right (apart the boundary of the bright circle). I display the background subtracted image

image

If I use a background created from an opening (also size 40) I never reach this level of precision. The background generated within the white circle is not even close to what one would expect. I tried to change the radius but I never reach a background within the bright circle close to 170.

image

As I understand the second background subtraction is a top-hat operation. Am I doing something wrong or top-hat filter is not the best choice to subtract a background for this kind of images.

tischi commented 3 years ago

If we do a background subtraction using a 40 radius median image the results looks quite right (apart the boundary of the bright circle). I display the background subtracted image

Yes, median does not work perfectly at round edges (such as the boundaries of a circle). Although what you have there almost feels a bit much...

As I understand the second background subtraction is a top-hat operation. Am I doing something wrong or top-hat filter is not the best choice to subtract a background for this kind of images.

I think this observation is correct! Tophat underestimates the background for noisy images (I can explain you in a zoom call if needed). Median is better for noisy images.

manerotoni commented 3 years ago

Hello @tischi , For the median I think I overdid the radius. You do expect at the boundary of the right circle that the median is lower. This was the radius where the bright dot completely disappeared.

I am happy to understand why tophat work this way. Noisy images is not that uncommon. In fact if I do a gaussian smoothing first (radius 1-2 px) and then subtract the opened image the result looks better (similar to median).

tischi commented 3 years ago

In fact if I do a gaussian smoothing first (radius 1-2 px) and then subtract the opened image the result looks better (similar to median).

This is also what I would recommend. Smooth a bit before the tophat.

Regarding why it fails is essentially this:

open( im ) = max( min ( im ) )

The issue is that the min( im ) finds all the low values in the noisy background and all the high and average values in the noise are gone and thus cannot come back when you do the max. Thus the background is underestimated. For example bg = avgBg +/- sdBg, the opening would probably give you something close to avg - sdBG. Makes sense?

manerotoni commented 3 years ago

See also #116