How to use the "Subtract background" command from a python script?

I am trying to write my first script using jyton. I have some problems with the “Subtract background” command.
Currently the script looks as follows:

from ij.plugin.filter import BackgroundSubtracter

BackgroundSubtracter().rollingBallBackground(imp, 450, False, False, False, False, False)

In this fragment imp was obtained using the IJ.openImage function. I get the error message “1st arg can’t be coerced to ij.process.ImageProcessor”.
What am I doing wrong?

Hello Dmitry -

IJ.openImage() returns an ImagePlus, while
rollingBallBackground() requires an ImageProcessor as its first


BackgroundSubtracter().rollingBallBackground(imp.getProcessor(), 450, False, False, False, False, False)

(Roughly speaking, ImagePlus is a wrapper for ImageProcessor (and
stacks thereof) that contains various metadata and utility functions.)

Thanks, mm

1 Like