Written by Jakob Johnson for the USU Crop Physiology Laboratory.
This program analyzes images and counts the number of green pixels in the image. It reads image files from the chosen directory and outputs a csv containing summary information to the parent directory.
The image files in test-img
are given as sample images to demonstrate the code.
Used in "Substituting Far-Red for Traditionally Defined Photosynthetic Photons Results in Equal Canopy Quantum Yield for CO2 Fixation and Increased Photon Capture During Long-Term Studies: Implications for Re-Defining PAR" by Shuyang Zhen and Bruce Bugbee
Requires Python 3.x.x
Install dependancies numpy
and Pillow
using PowerShell/Terminal with the commands
pip install numpy
pip install Pillow
To run the program, either open main.py
with Python or in PowerShell/Terminal using
python `.\path\to\directory\main.py`
Note, for macOS you'll need to use python3
instead of python
Select a directory in the popup window and click 'Run Analysis'. The terminal window gives information about the running program.
The 'Create Analyzed Images' checkbox lets you save an image showing where the program detected green pixels. This option slows down analysis.
The 'Fuzz Factor' slider determines the algorithm's green sensitivity. Increase it if necessary to eliminate background noise.
Install numpy
and Pillow
using the terminal commands
sudo apt install python3-numpy
sudo apt install python3-pil
Follow the above steps to install the dependencies, then in your python program, import the gpix.py
file and run the analysis with
gpix.countPix('file/path/to/images', save = T/F, fuzzFactor).writeCsv('/dir/to/write/to/')
countPix()
returns an object that contains summary information about the analyzed photos. Run its .writeCsv()
method to export the stored data as a .csv
file.
Reading the file RB 300 FR 50 June 6 630pm.jpg
,
returns the image RB 300 FR 50 June 6 630pm-ANALYZED.jpg
,
and the summary statistics,
Image Name | Total Green Pixels | Percent of Total |
---|---|---|
RB 300 FR 50 June 6 630pm | 940635 | 0.313545 |
On a second pass, the program will ignore the *-ANALYZED.jpg
file and overwrite the csv table.
Install libcamera
with the following command
sudo apt install libcamera-apps