Background subtraction in scikit-image

Does scikit-image have equivalent background subtraction like the one in ImageJ (i.e. Subtract Background…) ?
Thanks.

The latest I’ve seen is this:

For me, background subtraction using a top-hat filter using an area opening is a viable alternative to rolling ball.

I don’t know the rolling ball algorithm, so I don’t know how to assess that statement. Can you help and leave a comment on the issue?

2 Likes

@stefanv , thank you for the discussion link. I’ll evaluate them to see if this is equivalent to my need.

1 Like

I sucessfully implemented background subtraction using a top-hat filter. On my data, the result is visually indistinguishable from ImageJ’s rolling ball algorithm:

def subtract_background(image, radius=50, light_bg=False):
        from skimage.morphology import white_tophat, black_tophat, disk
        str_el = disk(radius) #you can also use 'ball' here to get a slightly smoother result at the cost of increased computing time
        if light_bg:
            return = black_tophat(image, str_el)
        else:
            return = white_tophat(image, str_el)
4 Likes

It would be great to have this included in skimage, if you are willing to make a PR.

1 Like

Just FYI: We had a more detailed discussion on ImageJs background subtraction earlier. At the end, a clean/simple top-hat filter might be the perfect choice compared to ImageJs implementation which is similar, but a bit special :wink:

Cheers,
Robert

2 Likes