May 14, 2025

Public workspaceInsect Counting in a Thermal Gradient Setup by Analyzing Captured Image

  • Haziqah-Rashid,A. 1,
  • Krzysztof Kuś2,
  • Marcus SC Blagrove1,
  • Ewa Chrostek3,1,
  • Marie Held4
  • 1Department of Evolution, Ecology and Behaviour, Institute of Infection, Veterinary and Ecological Sciences, University of Liverpool, Liverpool, UK;
  • 2Department of Biochemistry, University of Oxford, Oxford, UK;
  • 3Institute of Environmental Sciences, Faculty of Biology, Jagiellonian University, Krakow, Poland;
  • 4Centre for Cell Imaging, University of Liverpool, Liverpool, UK
Icon indicating open access to content
QR code linking to this content
Protocol CitationHaziqah-Rashid,A. , Krzysztof Kuś, Marcus SC Blagrove, Ewa Chrostek, Marie Held 2025. Insect Counting in a Thermal Gradient Setup by Analyzing Captured Image. protocols.io https://dx.doi.org/10.17504/protocols.io.261ge8777g47/v1
License: This is an open access protocol distributed under the terms of the Creative Commons Attribution License,  which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited
Protocol status: Working
We use this protocol and it's working
Created: May 13, 2025
Last Modified: May 14, 2025
Protocol Integer ID: 218178
Keywords: Insect counting, Thermal gradient, thermal preference of the mosquito, thermal gradient apparatus, adult mosquitoes in each zone, adult mosquito, thermal gradient setup, mosquito, images of object, analyzing captured image, image, drosophila melanogaster, thermal preference, captured image this protocol, fly, camera, object, gopro, gradient, insect counting
Abstract
This protocol describes a method to count adult mosquitoes in each zone of a thermal gradient apparatus. These data can be used to determine the thermal preference of the mosquitoes. This protocol is specific to adult mosquitoes and can also be used to analyze images of objects of similar size (e.g., Drosophila melanogaster flies). The images were recorded using a GoPro (camera) placed above the gradient.
Troubleshooting
Mosquito Rearing
Soak filter paper in yeast water (1 tablet of Natures Aid Brewers Yeast, 300 mg in 1L overnight water). Allow the larvae to emerge from eggs for 24 hours.
Upon larval emergence, provide a quarter tablet of fish food (TetraMin Tropical Tablets) every other day.
Once larvae reach the L3 stage, provide a full tablet of fish food every other day until pupation. Replace larval water every 4 days or when it is cloudy.
Pipette pupae into clean plastic containers and place them in BugDorm mosquito cages (W17.5 x D17.5 x H17.5 cm). Provide cotton balls soaked with 10% sucrose to adults ad libitum.
A day before blood feeding, starve adult mosquitoes by removing sugar, then feed them with fresh whole human blood in sodium citrate (Cambridge Biosciences) weekly using Hemotek feeder (SP6W1-1, Hemotek).
Prepare egg dishes by placing 90 mm filter paper (Fisherbrand, Fisher Scientific, QT 270) on wet cotton balls in a small plastic cup. Collect eggs after 5 days and dry them at 27 °C before hatching.
Thermal Gradient Setup
Test thermal preference using the thermal gradient setup inspired by Hague et al., (2020)1. Place a rectangular plate (7 cm height x 33 cm depth x 52 cm width), divided into two chambers (7 cm height x 33 cm depth x 26 cm width) on a heated regulator plate and metal blocks at each end, producing a thermal gradient of 35 °C to 16 °C.
Place a transparent, removable Plexiglas cover (26 cm width) on the chambers.
Embed heat sensors on top of the plate and attach to a monitor to record the temperature throughout the experiments.
Record temperature inside the chambers at 8 different places with a thermometer to ensure consistency.
Position a camera (GoPro) above the setup to capture images throughout the experiment. Adjust the interval for image capture as needed. Place the lights on a metal frame around the gradient setup, with controls attached to a computer to facilitate turning them on and off.

Figure 1 : Test image recorded with a colour camera. Gradient divided into eight zones

Preparing Mosquitoes and Placing Them in the Temperature Gradient Setup
Aspirate 3-5 days old mosquitoes to a 15 cm x 15 cm x 15 cm BugDorm cage.
Once the thermal gradient setup is ready, release mosquitoes into each chamber through the holes in the Plexiglas cover. Allow the mosquitoes to move freely and choose their preferred resting or sitting location.
Capture a single image of the mosquitoes one-hour post-release to allow the adults to acclimatize in the gradient setup.
Divide the gradient into eight zones and count the number of mosquitoes resting in each zone. Calculate the fraction of mosquitoes per each zone.
Automation
The entire image analysis process can be automated using the Fiji macro script: InsectCounting.ijm, available from the Github repository: https://github.com/Marien-kaefer/Insect-counting-in-zones2.
Open the .ijm file by dragging the file from the file explorer into the Fiji®3 status bar. This only needs to be done once per session. Multiple images can be processed sequentially.
Open an image to be processed by dragging the file from the file explorer into the Fiji status bar.
Click “Run” at the bottom left of the Script editor window.
Pre-processing
Reset the ROI Manager in case it contains unrequired ROIs.
Read the file title and remove extension, also reads the file directory/path of the image file.
Image is duplicated and the channels are split into red, green, and blue. Highest contrast is in the blue channel, so the red and green are discarded and only the blue channel is processed further.
Image is rotated by 2.5 °C, determined using the angle tool in the Fiji toolbar. Adjust this parameter if appropriate for other images.
Replace pure black pixels caused by the rotation with white ones. The mosquitoes appear as dark spots on a lighter background. If the pixels were left to be black, they might be considered “objects” in a later step and henceforth interfere with the identification of mosquitoes as objects. Therefore, it is advisable to replace the pixels with white. The insects are not pure black, so it is unlikely that insect pixels are replaced.
Filtering
Top Hat filter. The top hat filter is based on neighborhood ranking, but it uses the ranked value from two different size regions. The darkest value in a circular interior region is compared to the darkest value in a surrounding annular region. If the darkness difference exceeds a threshold level, it is kept (otherwise it is erased). The neighborhood radius is set to 8.
Median filter with a radius of 2 to reduce noise. The median filter is edge preserving.
Segmentation - Object Identification
Segmentation is the process of distinguishing the pixels belonging to the foreground (objects) from the background. Global thresholding is used to classify the pixels: class 1 (white); objects of interest, class 2 (black); background. This is done via a mathematical algorithm called “Otsu”4.
Some insects located in close proximity to one another may be identified as one larger object. To separate touching objects, a watershed separation is performed. Watershed segmentation works best for smooth convex shapes that don’t overlap too much.


Figure 2: Watershed separation


Counting
Once objects have been identified, they can be counted.
To determine the number of insects per zone, a file containing the predefined zones as rectangular regions of interest is required and automatically loaded into the Region of Interest (ROI) manager.
For each zone, the macro calls Analyze Particles with a size filter of 20-500 pixels applied to reject objects that are too small/big to be mosquitoes. The measured parameters are the object count, total area (px), average size (px), % area covered by objects. These parameters are all zone-specific.
Results file opens and is populated as the macro iterates through the regions of interest.



Figure 3: Results file gets populated as the macro iterates through the regions.



Post-processing
Save the results file that has automatically been given the original file title.
Save the segmentation mask “originalFileName-mask” and the reference file “originalFileName-Reference for quality control” for future reference and quality control purposes as .tif files.
Close all the image files and the table if not immediately performing quality control and further files can be processed immediately.
Quality Control
Open the following saved files: a) originalFileName-Reference for quality control.tif b) originalFileName-mask.tif (This file is the pre-processed file prior to segmentation).
Open the ROI Manager if required [Fiji > Analyze > Tools > ROI Manager] or type ROI Manager into the search bar and select the appropriate option.
Load the “zoneROIs.zip” file. Select [Show all] to display all ROIs simultaneously.
Open the synchronize windows utility: [Fiji > Analyze > Tools > Synchronize Windows].
Select the mask and reference files and tick “image scaling”.
As all the ROIs are displayed at the same time, they are numbered and can therefore be correlated between the images.
Activate [Show Label] if they are not numbered.
Activate one of the images by clicking onto its title bar. Then hover the mouse pointer over the area to be inspected. Both, the mask and the reference image should zoom in unison.
Visually compare the count mask and the reference image. Evaluate whether the number in the corresponding line of the summary table is correct. Please note that there might be more white objects displayed in the ROI in the mask than have been counted due to the applied size filters.
Protocol references
1) Hague, M. T., Caldwell, C. N., & Cooper, B. S. (2020). Pervasive effects of Wolbachia on host temperature preference. MBio, 11(5), 10-1128.
2) Marie Held, Insect Counting in Zones, (2022), Github repository, https://github.com/Marien-kaefer/Insect-counting-in-zones.
3) Schindelin J, et al. Fiji: an open-source platform for biological-image analysis. Nat Methods 9, 676–682 (2012). https://doi.org/10.1038/nmeth.2019.
4) Otsu,N. (1975). A threshold selection method from gray-level histograms. Automatica, 11 (285-296), 23-27.
Acknowledgements
We thank the Centre for Cell Imaging (CCI) at the University of Liverpool for the assistance with the image analysis. AHR acknowledges funding from Majlis Amanah Rakyat (MARA).