Thresholding dark images

Hi Hannah and Eric

I’m finally on to some real data analysis but am running into some trouble.
I’m screening biofilm on an old Opera high-content screening system which handles dark images by increasing the contrast of the image accordingly. This creates some problems for me, when trying to threshold in BiofilmQ, where the automatic thresholding methods have a real hard time thresholding the dark images (i.e. they include all of the noise).
I’ve tried to adjust both the convolution and the top hat filtering, both the problem challenge persists, also with any auto thresholding method.

These are MaxInt Z-projections with auto B/C (ImageJ - similar to BiofilmQ). From left to right: Blank well (no contents), planktonic cells, biofilm.
Below are the ortho views of a segmentation of these images with Otsu sens = 0.2, conv. kernel = 5, 3, median filtering, and top hat size = 25 vox.


As you can see, the low-contrast images (dark images) are thresholded to include a lot more information than the images with biofilm (which kind of screws up my downstream analysis :grimacing: )

Do you have any suggestions for how I can improve BiofilmQs thresholding of images like these?
I have found thresholding methods in ImageJ that are able to threshold the dark images correctly (MaxEntropy and RenyiEntropy) - can I somehow supply binary images to BiofilmQ and just do the segmentation and parameter calculations?
Or do I simply need to use a different imaging system to acquire better images?

Original tifs for BiofilmQ:
https://files.dtu.dk/u/tvszF3p7Mxak-zMQ/opera_problems.7z?l

Hi Mark,

these images are very diverse and I am not sure if there exists a thresholding method in BiofilmQ that serves your purpose. However, regarding each one of them individually, I think a solution can be found.

  • The first image is very dark, in fact I cannot see any cells in there. In those cases, RobustBackground typically works fine, will however still detect some false positive objects. Of course, you could define a manual threshold, but depending on your research question, I understand that this might not be possible.

  • The second image contains some cells. RobustBackground with the Standard sensitivity of 1 works quite well here. I can see that you chose a relatively small sensitivity, which might have caused the issue. For me, the segmentation looks like this:

  • The challenging aspect for the last image is that such a large part of the image is fluorescent. To capture it all, the sensitivity has to be decreased to quite a low value. I agree that this is not optimal.

The good news is that you can import segmentation results:

If you have a binary image, include it as an additional channel (so in your case you could include it as channel 3) by using the same file names as you have for your tif files right now, except that you change the channel number given by _ch. Be aware that you need one additional slice (the BiofilmQ “overview” slice) at the bottom of your stack. It does not matter what exactly this slice contains, BiofilmQ usually performs a projection to optimize visualization, but it can be anything else as well.

Now, segment this new channel using manual thresholding with the threshold set to 0.5. Depending on how your images were saved, double-check that this is the correct threshold. Perform the segmentation using no filters, choose the cube size that you would like for your image.

Finally, you can transfer the segmentation to your original channel (option 2.7 in the Segmentation tab). You can afterwards delete the binary channel or keep it, as you wish.

All of these steps are also described in more detail in our documentation (Segmentation — BiofilmQ @ Drescher lab). Since this features was released only a couple of months ago, you might need to update your BiofilmQ version to use it.

Let me know if this helped or if you need anything else.

Best,

Hannah

Hi Hannah,

Thanks a lot for the input. I agree with your take on the difference in the images. They are like that on purpose (blank controls and samples).
I’ll try importing segmentations when I’m back at my work station. I’m guessing that I would need an additional binary stack for each channel I want to import to, correct?

Again, thanks for the help!
/Mark

Alright, I’ve segmented my images and imported the binary images into BiofilmQ and that works really well, but now, I’m encountering a different problem.
Some of the images are very dark (as the one I sent you here) because they are blank control wells. I want to use these wells to compare the biofilm samples to, but BiofilmQ can’t segment them because it doesn’t find any objects (obviously - there aren’t any).

I imagine I have to go through the files myself to find the files with no data and then manually insert a “blank value”, correct?
This probably sounds dumb, but is there a way to force BiofilmQ to do parameter calculation with no objects? So as to put zeros/NAs into all variables?

/Mark

Hi Mark,

this is an interesting question. You can in principle still perform the segmentation and it will generate an output file (which I think you already found out), but this file is skipped during the parameter calculation. I can´t think of a quick fix to write NaN values or something equivalent in there. What is the type of plot that you had in mind for this? If it is for example just plotting the number of objects (therefore showing that the control is empty), that is possible already via the globall property Cell_Number. Something more complex like mean intensity is always going to be difficult because you can´t really visualize NaN numbers in a plot. What would your preferred outcome be in this case?

Best,

Hannah

Hi Hannah,

Well, when I performed the segmentation, I just end up with a “not segmented” in the file browser, and of course, the parameter calculations are skipped.

I’m not necessarily thinking of a plot. I want to compare two different sample types to determine if one produces more biofilm than the other (I’m only interested in biovolume, currently).
The control samples sometimes do not produce biofilm, but sometimes do. I would like to average the amount of biofilm produced (also when they don’t produce anything), and possibly also normalize to them.
If I get NaNs, that I know are just extremely low values, I would just arbitrarily give them a low value in the downstream analysis.

Hope that made sense
/Mark

Hi Mark,

so if you´re not doing any plotting, how are you extracting data from BiofilmQ? Mabye we can insert a modification at this level. Also, are you using the .exe version or the folder with .mat files and open BiofilmQ in Matlab? In the second case, we can probably add some custom code for you to make it work.

Best,

Hannah

I pull out the data from the parameter calculation and import it into R. Currently, I’m only using the files with the global parameters. My BiofilmQ runs through matlab with the .mat-files.

/Mark

Hi Mark,

I tried to reproduce your situation, but in my case when using a threshold higher than the image value and therefore ending up with no objects at all, an output file is still generated and in the file list the segmented-box is ticked. I downloaded the current version of BiofilmQ from the website to ensure that have I have the same code.

Can you check if in the “data” folder in your directory there exists a .mat file corresponding to your image? In that case, the segmentation worked, even if there is no information in the file other than that there are no objects.

What does not work for an empty image is the generation of a .csv output of global properties (because there are no properties for a non-existing biofilm). Maybe this is the problem? In that case, you could check the existence of this global property file in R, and if it does not exist just fill your numbers with zeros or NaNs as required. Or are you directly reading the .mat file (in which case you will be able to tell that the image is empty because the number of objects is zero)? I feel like filling the values in R before continuing the analysis might be the easiest option here.

Best,

Hannah

Hi Hannah,

I’m using version 0.2.2 - haven’t checked if there is a newer version, recently - and this is what I’m getting (with an example of the binary image to the right):
image image

And in the data folder, ch3 segmentation data is also missing (notice A1_rep3_ch3 is missing):
image

I repeated the analysis with fresh data I collected over the night, and didn’t have the problem anymore. You’re probably right about filling the values in R, I’ll have to figure that out. Thanks for all the help!

/Mark