CODICOUNT

CODICOUNT

Tutorial for CODICOUNT (January 2025)

CODICOUNT: ImageJ / FIJI plugin for the automatic counting of insect eggs and parasitism rates

This program was developed in the context of the TriPTIC ANR project (2014-2019) and the PHENOMENE INRA project (2017-2019).

Contact: Vincent Calcagno vincent.calcagno@inrae.fr and Guy Perez guy.perez@inrae.fr 

Installation

Step 1: Install R

Step 2 (Windows only): Update PATH

  • Type “environment variables” in the system search bar.
  • Modify the environment variables, this will redirect you to the system properties panel.
  • Click on “Environment variables”.

In the window that opens, modify the Path variable. Select Path, then click on “Edit”. Next, click on “New”, then “Browse”, and search for the R folder (e.g. C:\Program Files\R\R-4.4.2). Select the bin folder and click “OK”.

Step 3: Install the codicount.jar plugin

  • Download the latest version of codicount.jar
  • Copy it to the plugins folder inside the Fiji or ImageJ folder.
  • Restart Fiji or ImageJ. CODICOUNT should now appear in the “Plugins” menu.

Tutorial

Here is a step-by-step description of how to count egg images in ImageJ / FIJI.

1-Identification of the area-to-be-counted (image preparation)

  • We must begin by identifying the portion that we want to count in the images, excluding any polluting elements (tube edges, pieces of cotton, labels with the sample number, finger stains ...). For this the easiest way is to open the images and crop them ( "Crop"). If the area has a square or rectangular shape, select the area with the Selection Tool "Rectangular". Once the area is correctly defined, use the command "Image, Crop." We can then save the cropped image.
1
  • Another approach is to tell the plugin to ignre certain image portions. This is especially useful when the area to count as a more complex shape (disk, oval...). The way to proceed is to paint all the areas to be ignored with the exact color (r, g, b): (255, 0, 182). One can for example use the "Paintbrush tool" brush. Any pixel having this rgb value will be completely ignored when counting; then it is unnecessary to crop the image. You must first specify the color, which is achieved via the menu "Image> Color> Color Picker ...". Double click in the square on the bottom left of the window Color Picker. A new window "Foreground Color" appears where you can set the values (r, g, b).
  • Obviously, the simplest procedure is still to frame only the area to count when shooting, to have images directly used for counting.

 

2-Plugin calibration (training phase)

  • This step will train the plugin on type of images that will have to deal with, allowing it to determine the best way to proceed for counting. After this step, the plugin will generate an ImageJ macro that can be used to count such images. One macro should be created per image type (background color, lighting, exposure, and host species, age of eggs ...) to ensure maximum performance.
  • We need to select representative samples of pixels from three areas: background (colored), healthy (unparasitized) eggs and parasitized eggs, to be called Background, Healthy and Parasitized, respectively.

To do this, the best method is to select the "Oval" tool with the right mouse button to access the selection tool "Selection Brush tool." A double left click on the button allows to adjust the size of the selection area, which should be neither too small nor too large compared to the size of eggs, thus facilitating selection.

2_1

With this tool, first we'll select image portions belonging to the background (thus having no egg). Try to get a sample of pixels that is as representative as possible of the background color. You can select several disjoint zones, obviously, holding down the "Shift" key while selecting. Once all the desired pixels have been selected, we will store the selection in the ROI Manager, using "Edit> Selection> Add to Manager" from the menu, or by using the keyboard shortcut "Ctrl + T". A window titled "ROI Manager" will open, and the selection appears with an arbitrary name defined by ImageJ. We just have to rename this ROI "Background", using the button "Rename". Note that only the first letter of the name ("B") is required, the rest is optional.

2_2

We then repeat the operation for healthy eggs  (ROI to be renamed "Healthy") and parasitized eggs (ROI to be renamed "Parasitized"). Each time we first deselect all the pixels corresponding to the previous ROI, by simultaneously pressing the keys "Ctrl + Shift + A", or by the menu "Edit, Selection, Select None".

  • There is no need here to try to select precisely the contour of eggs. It is important however when the selections to ensure take points representing all areas of the picture (guideline: about forty points for the background, healthy eggs and black eggs, uniformly distributed over the entire image). It is also important to select all types of pixels that are found in each area. For example, if eggs cast shadows on the background, these must also be included in the selection "Background", so the plugin knows well that the shadows belong to the background, and optimizes the discrimination accordingly.
  • Typically, when a large number of images of the same type are to be counted with the same macro, the ideal is to calibrate the plugin from several images, to obtain appropriate settings for all the images and not overly specific to one of the images.

To do this, simply make a montage of several images. Just open several images, for example using the menu "File> Import> Image Sequence". 

2_3
2_4

Once all the images are open, we can create a montage via the "Image> Stacks> Make Montage" menu (set the scale factor to 1). You can  calibrate the plugin on this image.

3-Egg size calibration (optional)

  • On the same image, it is also possible to calibrate egg size. This requires selecting the tool "Freechand selections", and to surround groups of one or more eggs (if possible isoalted on the background). These areas are to be added individually to the ROI Manager ( "Ctrl + T" as previously) and renamed according to the number of eggs they contain (1,2,3, ...). For example: if one surrounds a single egg, the ROI is to be called "1" in the ROI Manager, if 7 eggs are in it, renames it "7", etc...
3_1

 

  • There is no need to count all of the image, but the ideal is once again to have several areas representative of the distribution of egg size.

 

4-Macro generation

  • Once all areas are stored in the ROI Manager, you can call the plugin "CODICOUNT" available in the dropdown menu "Plugins". It may be useful to save the selected areas in the ROI Manager on disk, using "More> Save". This allows to keep track of the calibration phase, to be able to repeat the procedure later.
4_1

 

  • Following the execution of the plugin (a few seconds), a window opens named "Log" in which the code of the macro is written. This code can be used to count the different images. The macro contains different informations (including the date of creation and the name of the image that was used for calibration). The text of the macro begins with // and ends with CODICOUNT // End of macro.
4_2

 

  • It is useful to save the macro in order to use it later, and to keep track of analyzes. The contents of the macro can be copied and pasted from the Log window. Just create a new macro window via "Plugins> New> Macro", and paste to it the text of the macro. At the end of this operation, we can save the macro ( "File> Save As ...").
4_3

 

5-Image counting

  • You will now be able to perform automatic counting of your pictures, by running the macro generated by the plugin ( "Macro> Run" in the window of the macro or keyboard shortcut "Ctrl + R"). To run a macro that was previously saved to disk, simply use the "Plugins> Macros> Run ...".
  • After running the macro, two things happen.
    • First, a new image appears, corresponding to the image such that the program has seen it: the healthy eggs are shown in orange, parasitized eggs in black
5_1
    • Second, the results window appears on the screen, with the following columns:
      • Picture: the name of the image
      • Total area: total number of pixels (excluding color pixels (255, 0, 182)) - Column B: "Background", the number of background pixels
      • Column H: "Healthy" number of pixels of healthy eggs
      • Column P "Parasitized" number of pixels of parasitized eggs
      • Column #H  (if the size of the eggs was calibrated): number of healthy eggs
      • Column # P(if the size of the eggs was calibrated): number of parasitized eggs
      • Column %P:      percentage of parasitized eggs (parasitism rate).

Typically, we have many pictures to count. The macro can of course be applied to each image individually, but the most effective method is to apply it on an entire folder of images. To do this you must click on "Process> Batch> Macro". A batch process window opens, in which you must select the "Imput" folder where the images are located. Then select the target folder "output" in which will be stored the analyzed images. After you click on "Open", to select the file containing the macro. At the end of this procedure, you click "Process" to start the counting operation. The results will be presented as a table (one line per frame counted). It can be saved in Excel format for subsequent statistical analysis.

5_2
5_3