Prey capture assay for zebrafish larvae ~ Counting the number of the paramecia

To quantitatively describe the ability of prey capture in zebrafish larvae, I need to count the number of paramecia consumed by the larva. Here is a frame from the time-lapse recording of the prey capture behavior. In a typical assay, I put one zebrafish larva and about 30 paramecia in a recording chamber and record for 11 minutes at 10 fps (exposure time: 5msec). The larva will eat most of the paramecia during recording. This prey capture behavior can be used as an assay to test how an experimental manipulation affects the prey capturing ability.


How can I count the paramecia in ImageJ? First, I obtain a background image by making an averaged image. To do this, call Image > Stacks > Z Project… > Average Intensity.

AVG_20150826_155851 (Note that embedded image is in JPEG just for the sake of reducing the file size on this blog).

Now I divide the movie by this background image. Process > Image Calculator… > Divide (check both “Create new window” and “32-bit (float) result”).  Whether we need background subtraction or not depends on the image. In some cases, background subtraction does not give a better result.

Image > Adjust > Brightness/Contrast… > Auto, then Image > Type > 8-bit . Now you can clearly see the paramecia in a uniform background.

Result of 20150826_155851a-1

Image > Adjuts > Threshold… > Upper Threshold Level:94, Apply.

Edit > Invert (Process all images) 

Result of 20150826_155851a-2

Now I set a oval ROI on the circular chamber and analyze particles. Analyze > Analyze Particles… > size (pixel^2): 18-72, Circularity:0.50-1.00, Show:Masks, Check “Display results”, “Clear results”, “Summarize”, “Exclude on edges”, and click OK (Process all images).

As a result, the paramecia are extracted. This is the “Mask of ..” image (Different frame from the above).

Mask of Result of 20150826_155851a-1

The text window named “Summary of ..” gives the “Count”. The numbers fluctuates among frames because some paramecia may be missed because they were near the edge of the chamber or there happened to be some noises in each frame. Because I don’t need exact paramecium count frame-by-frame, I average for 1-min interval (moving average for 600 frame time bin on Excel). What I need in this experiment is to know how many paramecia are consumed over minutes. A typical result looks like this (after averaging). On average, this zebrafish larva captured one paramecium in every 15 seconds.



Automating the paramecium counting

Particle analysis is a slow process (depending on how many particles are present in the image). In my case, one file takes about 30 min. So, it will take 15 hours to process 30 recordings. It is exhausting if I need to do it manually. Spending some time on writing an ImageJ macro can save a huge amount of time and energy.

The size of a recording file is 6.4GB ( 1024 x 1024 pixels x 6600 frames). My desktop PC has 32GB memory, not enough memory to do division of the 6.4GB images. So I have to work on a half of the movie at one time. I wrote an ImageJ macro (which worked in ImageJ 1.49v on my data files  on Windows7).

This macro will:

  1. obtain file names in a specified folder and works on each AVI file.
  2. It opens one AVI file,
  3. makes an averaged image,
  4. duplicates the 1st and 2nd half of the movie
  5. and closes the original movie,
  6. does image division to subtract background
  7. and saves the resulted images for the future use (in RAW fromat),
  8. thresholds to make binary images,
  9. particle analyzes,
  10. and saves the result as a text file.
  11. Then it moves on to the next AVI file in the folder
  12. and repeats processing until all are done.

Note: I found that a large (>6GB) stack could not be saved properly in AVI or TIFF format. Only RAW format worked in my macro for unknown reason.

By the way, you do not need to write a macro from scratch. Macro recording is available. Plugins > Macros > Record…  This does not do everything that I want but it helps a lot.