/nematode_egg_counting

This application reads a high resolution scanner images and tracks and counts stained nematode eggs using OpenCV and Python

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

Nematode Egg Counting

This application reads an high resolution image file, extracts objects and gets the total count of them.

Environment Setup

  • Download & Install Python using Anaconda or Miniconda (Recommended)

  • Open a terminal or command prompt and clone this repository. Then cd into the directory

    git clone https://github.com/ukalwa/nematode_egg_counting
    cd nematode_egg_counting
  • Now, you can run the following commands to install required packages in an isolated conda environment

    conda env create -f environment.yaml

It is compatible with both Python 2.7 and Python 3.5, however installing Python 3.5 or greater is recommended.

It was tested on Windows and Mac OS X.

Usage

Configuration file src/config.ini contains all the settings for blob identification, fig sizes and so on. Before running the script, update it accordingly.

  • Before running the application, cd to the cloned directory and activate the conda environment by running activate egg_counting

Paths specified as command line arguments (file_path, dir_path) below should be enclosed in quotes('' or "")

  • To process a single file with its known absolute file path

    python run.py -f <file_path>
  • To process a directory full of images with known path

    python run.py -d <dir_path>
  • To process only some files in a directory with known path

    python run.py -d <dir_path> -p <pattern string>
  • To process a single file using file dialog GUI

    python run.py
    (or)
    python run.py -uf
  • To process a directory full of image using file dialog GUI

    python run.py -ud

Steps involved

The code performs these following steps:

  1. It extracts the configuration parameters related to blob identification, figure sizes, bounding box parameters and so on
  2. Read the image file as a 3-d numpy array and splits it into various blocks and stores them as a list of numpy arrays.
  3. It then loops though each block and detects any eggs based on parameters set in the config file and records the count and adds it to the total count
  4. After all the blocks are completed, total egg counts, blocks with bounding boxes around eggs, egg params are all saved in text files for reference and debugging purposes

Here are some snapshots

The one on the left is a block of the original image and the one on the right is the processed image with eggs identified and labelled with bounding boxes

Top layer

image1

Interface layer

image2

Bottom layer

image3

Documentation

For generating documentation, please follow these steps:

  • Make sure you have sphinx installed, you can install it like this
pip install sphinx sphinx_rtd_theme
  • Move to the docs directory and run make. It takes couple of minutes to generate the build files.
cd docs
make html
explorer build\html\index.html

License

This code is GNU GENERAL PUBLIC LICENSED.

Contributing

If you have any suggestions or identified bugs please feel free to post them!