I was trying to use the Background Per Object thresholding method in an IdentifyPrimaryObjects module, based on a cropped image using objects from a previous IdentifyPrimaryObjects module. The first identified yeast cells, and the current module was to find the DAPI-stained nuclei inside each cell. There was one cell with a particularly dim and small nucleus that I noticed wasn’t being picked up, despite being a blob of 0.02-0.05 intensities in a sea of 0-0.02. It will only pick it up if I set the threshold modifier to ~0.1.
Wondering why it would do this, I looked into the source code, which I assume is up-to-date (svn.broadinstitute.org/CellProf … reshold.py) in the get_background_threshold procedure and discovered that it wasn’t behaving as documented. The documentation says that it clips above 0.95. However, what it actually does is clip both above 0.98 and below 0.02 by setting them to 0. I couldn’t find the code for the ndimage.histogram function, but I assume it creates exclusive minimum/inclusive maximum bins, so that these “0” values are then discarded as they don’t fall within any of the bins. But my poor dim cell needs those lower values .
Another part of this code that I wasn’t sure about is how the cutoff was calculated. I would have assumed you would want to find the maximum value of the bin containing the mode, which would be “(index + 1) / nbins” (assuming the histogram is a 0-indexed array). However, the cutoff is currently given by “index / (nbins - 1)”, which returns a value slightly lower. Is this intentional?
I also see that it is limiting itself to 256 bins, which seems to presuppose 8-bit images? I have 12-bit images, so if the threshold determination is only done with 8-bit color resolution, there’s a danger of it over- or under-shooting objects in 12-bit images.
Finally (whew!), I see that the real difference between Background and Robust Background is that the former ostensibly uses “2 * Mode”, while the latter uses “Mean + 2 * SD”. In that case, assuming it is decided to change Background’s cutoff to just be the upper 5%, why not make the lower cutoff in Robust Background be a user-editable parameter?
I’ve attached a paired DIC and DAPI image with the pipeline I’ve been using and a reference JPEG indicating the cell I have been focusing on, in case you want to try it yourselves.
EDIT: Corrected wrong variable name.
BackgroundTest.7z (1.39 MB)