Trait and color analysis for top-down images of pitcher plants, built with ilastik, OpenCV, and Deep Plant Phenomics. Developed for images obtained from an experiment performed by Mason McNair at the University of Georgia.
This repository does a few things:
- pixel classification
- plant segmentation
- color distribution analysis
Pixel Classification | Plant Segmentation | Color Analysis |
---|---|---|
Some sample images and data are included in samples
. The Python module and CLI are defined in pytcherplants
. Analysis is in notebooks
.
Pixel classification (via Ilastik) adapted from Peter Pietrzyk's DIRTmu. Segmentation and analysis adapted from SMART by Suxing Liu.
Docker or Singularity are recommended to run this project. The Ilastik pixel classification model necessary for certain commands is baked into the Docker image definition.
The Docker image is available on Docker Hub at wbonelli/pytcherplants
. To open an interactive shell with your current working directory mounted to /opt/dev
inside the container:
docker run -it -v $(pwd):/opt/dev -w /opt/dev wbonelli/pytcherplants bash
To open an interactive shell:
singularity shell wbonelli/pytcherplants
Note that Singularity automatically mounts the current working directory; there is no need to manually load a volume.
The pytcherplants
Python package can be installed with pip, e.g. pip install pytcherplants
. Note that the pixel classification commands expect Ilastik to be installed at /opt/ilastik/ilastik-1.4.0b21-gpu-Linux/
.
To run a local Jupyter notebook server from a suitable python environment (i.e., with jupyter
and all the dependencies in requirements.txt
installed; see below):
jupyter notebook --allow-root
The Jupyter UI should automatically open. Then navigate to the notebooks
directory to open a notebook.
Clone the repo with git clone https://github.com/w-bonelli/pitcherplants.git
.
The Docker image can be built from the project root with docker build -t <image tag> -f Dockerfile .
.
Alternatively, a virtual environment can be used.
First use python3 -m venv
to create a virtual environment. Then activate it with source bin/activate
and install dependencies with pip: pip install -r requirements.txt
. Deactivate the environment with source deactivate
.
First create an environment:
conda create --name <environment name> --file requirements.txt python=3.8 anaconda
Any Python3.6+ should support the dependencies in requirements.txt
. The environment can be activated with source activate <your environment name>
and deactivated with source deactivate
.
The Python CLI includes commands for processing individual image files, directories of images, and CSV files containing aggregate data.
The various CLI commands expect image file names to conform to date.treatment.name.ext
, where dates are _
-delimited triples %m_%d_%y
. For instance:
10_14_19.Calmag.p003.jpg
1_14_19.Control.p008.JPG
There are two commands:
classify
segment
analyze
To classify foreground (plant tissue) and background pixels in an image (i.e. to segment the plant from its surroundings), use the classify
command:
pypl classify -i <image file> -o <output directory>
By default JPG, PNG, and TIFF files are supported. You can select one or the other by passing e.g. png
or jpg
to the --filetypes
flag (shorthand -ft
).
pypl segment -i <image file> -o <output directory>
You can specify the number of plants per image by providing an integer argument -c (--count)
, as well as the minimum contour area argument -m (--min_area)
. The former defaults to 1. If the latter is absent, no minimum is applied.
This will produce an output image <output directory>/<image file stem>.plants.jpg
with each contour labelled, as well as one or more output images e.g. <output directory>/<image file stem>.plant.0.jpg
, as many as there were plants detected in the input image.
Use the analyze
command to analyze an image's distribution. The image is assumed to have already been segmented and cropped, with background pixels either white or black. The image may contain any number of foreground contours (individual plants).
pypl analyze -i <masked image file> -o <output directory>
To explicitly set the number of clusters for k-means clustering, use the -k (--clusters)
flag.