What's My Shape? Assessing Plant Morphology From Photos Using PlantCV

R package build

2022/03/03

Motivation

I am starting a new project looking at phenotypic plasticty in R. aquatica plants!

THIS POST IS VERY MUCH A WORK IN PROGRESS! Tune in next time for the completed product :)

# When grown in submerged conditions vs. when grown in terrestrial conditions...
# When grown in 25°C vs. 20°C....
# 
# This is a super cool system because these plants are clonal and easy to propagate. You just 
# 
# 
# # Introducing PlantCV
# 
# [PlantCV](https://plantcv.danforthcenter.org/) is an open-source image analysis software package targeted for plant phenotyping. We use it to measure dissection index, which calculates and quantifies leaf complexity from the leaf's area and perimeter values. 
# 
# # Installation
# 
# There are [a lot](https://plantcv.readthedocs.io/en/latest/installation/) of options for installation, but I chose to use a Conda-based installation procedure. 
# 
# First download and install whatever version of conda (Anaconda or Miniconda) that is appropriate for your system. 
# 
# Then clone or download PlantCV from GitHub: 
# 
# ```{bash}
# # Clone PlantCV if you did not use the GitHub Desktop application
# git clone https://github.com/danforthcenter/plantcv.git
# 
# # Enter the PlantCV directory (if you cloned with GitHub Desktop your path may be different than below)
# cd plantcv
# ```
# 
# Make sure the folder (named miniconda3 in my case) is located in the same directory as "plantcv" (home directory in my case). 
# 
# ```{bash}
# 
# # Create a conda environment named "plantcv" (or whatever you like) and automatically install the dependencies
# conda env create -n plantcv -f environment.yml
# 
# # Activate the plantcv environment (you will have to do this each time you start a new session)
# conda activate plantcv
# 
# # Install PlantCV in editable mode so that it updates as you work on new features/updates
# pip install -e .
# ```
# 
# The last few lines will create a python environment for PlantCV that includes the Python dependencies and install PlantCV. 
# 
# 
# # White Balance
# 
# We used little white stickers on each tray/shown in each photo to perform [white balance](https://plantcv.readthedocs.io/en/latest/white_balance/) in PlantCV. The purpose of this is to correct the exposure of an image and standardize exposure of images before thresholding. 
# 
# The description of the main function is here: 
# 
# -- plantcv.white_balance(img, mode='hist', roi=None)
# 
# -- returns corrected_img
# 
# 
# First, if PlantCV is installed in the global Python search path, you can import the PlantCV library like normal:
# 
# ```{bash}
# # Import libraries
# from plantcv import plantcv as pcv
# 
# # Set global debug behavior to None (default), "print" (to file), or "plot" (Jupyter Notebooks or X11)
# pcv.params.debug = "print"
# 
# # Normalize the white color so you can later
# # compare color between images.
# 
# # Inputs:
# #   img = image object, RGB color space
# #   roi = region for white reference, if none uses the whole image,
# #         otherwise (x position, y position, box width, box height)
# 
# # Corrects image based on color standard and stores output as corrected_img
# corrected_img = pcv.white_balance(img=img, mode='hist', roi=[5, 5, 80, 80])
# ```
# 
# 
# 
# 
# # Analyze Shape
# 
# [Shape analysis](https://plantcv.readthedocs.io/en/latest/analyze_shape/) outputs numeric properties for an input object (contour or grouped contours), works best on grouped contours.
# 
# The description of the main function is here: 
# 
# -- plantcv.analyze_object(img, obj, mask, label="default")
# 
# -- returns analysis_image
# 
# ```{bash}
# 
# ```
# 
# What we're interested in is "area" (the area of object in pixels) and "perimeter" (perimeter around object in pixels).