Analyzing Stationary Bubble as Size Decreases Over Time


I am running into issues when trying to analyze sets of data consisting of a bubble that decreases in size over time. Most of my issues are due to the poor lighting and contrast of the image, which has made thresholding very hard. I want to be able to threshold the bubble so that I can run it through a MATLAB code which measures the radius over time. I am working with tiff stacks with anywhere from 80-500 images per stack. My current methodology, which does not work well, is as follows:

  1. Preprocessing
  • Adjust Brightness and Contrast
  • Crop to region of interest
  • Try “find edges” but almost never works
  • Have tried converting to an 8-bit image, does not help at all
  1. Thresholding
  • Attempt color thresholding (almost never works)
  • Open image in Trainable Weka Segmentation using FIJI
  • Manually select “bubble” and “background” areas and let WEKA run
  • Repeat WEKA as required
  1. Run tiff stack through a MATLAB code to calculate diameter for every image, giving me a plot of diameter change vs time
  • I use the MATLAB code because “Analyze Particles” was not working well enough for me, but I believe that if I can get accurate thresholding using “Analyze Particles” would be ok

Example Raw Image:

My questions are:

  1. WEKA usually is not robust enough to accurately threshold every image in my dataset. Sometimes it will work for part of the stack, but not all of it. I currently use the “difference of gaussians” and “sobel filter” training features on WEKA with all other default settings. Are there different settings I should use that would work better?

  2. Should I be using WEKA for thresholding / segmentation? Is there anything else you would recommend that is better than WEKA?

  3. Even when using WEKA with only two training features, analyzing one stack takes anywhere from 15-30 minutes. How can I make this faster? I tried increasing the memory and threads available to FIJI, but that did not help.


judging from the raw picture, selecting the bubble looks tricky. I don’t have experience with WEKA, unfortunately. In a recent project, I have used the Matlab Image Processing Toolbox (App Image Segmenter) to do a similar task (outline of poorly lit brain). Worked good enough for me. I see you can convert your selection to a function and apply that to a series of images.
I have played around with Ilastik for segmenting cells - had a very good first impression, but haven’t found the time to delve deeper. Could be worth a try!

Good luck!

For Weka, how many traces did you train with? Would it be possible to post a few more slices so we can see how B&C changes you are talking about?

Thank you for the suggestions. I will definitely look into the image processing toolbox in Matlab!

Hi Andrew,

Here are some more images:

If you would like, I would also be more than happy to email you a tiff stack, which I can’t seem to upload directly.

B&C doesn’t necessarily change much throughout, but as you can see from the image it is very difficult to differentiate the left edge of the bubble, and WEKA even has trouble segmenting other areas of the bubble as well.

I don’t have a lot of experience with WEKA, so I just loaded my whole tiff file into WEKA for training (aka trained with the whole stack). I also tried training with smaller substacks to see if it would make using WEKA faster, but it didn’t help much.

You should be able to upload tiffs; they just don’t display correctly. Regardless, just to make sure I understand correctly, could you verify which part of the image is the bubble?

When you used Weka, how many traces did you make? A trace applies only to the slice it is on; it doesn’t get tracked through the stack.

I keep getting an error saying “Sorry, new users cannot upload attachments” when trying to upload a tiff file. Here is an outlined image of the first picture I sent in my last comment.

I have been training with approximately 10-12 traces, although that is not something I keep consistent between stacks. Generally, I just include traces in which I use the polygon tool to outline the left and right edges of the bubble (the areas hardest to threshold), and then trace some of the background of the bubble as well.

Interesting it will let you upload JPG but not TIF.

To clarify, when you trace “the left and right edges of the bubble”, you are still including the entire bubble? How far apart are the slices from each other? Is what you posted the image you are training on? Are you using 3D or 2D features for Weka?

Regardless, I would suggest trying more traces.

Attached is an example of the traces I would typically do when using WEKA. I only do this on the first image in the stack. I am using 2D features. The images I posted would be an example of images in a stack that I would need to analyze.

To my understanding, the more traces you have, the slower WEKA will be because it analyzes of all the selected area in the trace. One training session already takes 20-30 minutes, so there would be no point in trying more traces because it would be too slow.


If you are trying to segment the entire bubble, you should select the entire bubble in your traces. Yes, doing more than one slice might take longer, but it also might help improve the segmentation. Have you tried more slices and has it actually taken longer? I can see the logic behind why one would think that to be the case. However, that doesn’t seem to be the case with my data sets; at least not noticeably. Weka works off of the histograms of the feature stacks; so I am guessing the actual learning portion would take about the same time regardless. If I may ask, why is 30 min too long?

Yes, it takes a really long time.

30 minutes is just the time for the first training, and generally I need a couple more training sessions after which also take 20-30 minutes, which ends up being over an hour per data set, and I have a lot of data to work with. So waiting 30 minutes is not feasible.

I work with data sets of similar size and I was able to significantly reduce the analysis time per set.
Things that have helped me:

[Disclaimer: I am not familiar with Weka - if the 20-30 min are mostly time spent clicking on outlines, my experience is probably of less help.]

  • Make sure the data is stored on the PC and not on a network drive (loading/saving to drive was the most time consuming part of the algorithm).
  • Avoid saving images again (When I started out, I liked saving processed stacks because I could do a quality check on each stack after analysis. Over time, I went to doing thorough quality checks in the beginning and individual samples at the end. Not saving any images in my analysis at the moment - however I am saving the specific code file that made the analysis.)
  • Think about binning your images. Depending on the magnitude of the bubble size change, you can often reduce the size of the image by 2x2 or 4x4 without losing too much precision (especially in the beginning, when you are trying out parameters, it is not necessary to run the algorithm at full precision).
  • Add more RAM (I went from 8 GB to 32 GB and it’s magic :wink: - the time I saved with the faster processing quickly paid for the investment).

All in all, I was able to go fom 30 min to 2.5 min.