-
Notifications
You must be signed in to change notification settings - Fork 5
Greenness
Information about determining and interpreting the 'greenness' of PhenoCam images. More information to come soon.
The Green Chromatic Coordinate is a widely used measure of greenness in PhenoCam images. GCC represents the proportion of green within an area of interest in a standard RGB PhenoCam image.
GCC is easily calculated:
GCC = Green / (Green + Red + Blue)
The mean GCC for a PhenoCam image can be calculated in Python as follows:
from scipy import misc
# Read a PhenoCam image
img = misc.imread('/path/to/phenocam/image.jpg')
# Extract the mean red, green, and blue values from the image bands:
red = img[:,:,0].mean()
green = img[:,:,1].mean()
blue = img[:,:,2].mean()
# Calculate GCC:
img_gcc = green / (green + red + blue)
Alternatively, one can use the mean_gcc() function included in greenness.py:
from greenness import mean_gcc # greenness.py from PhenoAnalysis/Python/greenness.py
# Calculate mean GCC
img_gcc = mean_gcc(img)
Or, using the phenocam_toolkit's get_dn_means() function:
from PIL import Image
from phenocam_toolkit import get_dn_means
# Open an RGB and roi image
img = Image.open('/path/to/RGB/PhenoCam/image.jpg')
roi = Image.open('/path/to/roi/image.tif')
# Obtain the mean red, green, and blue digital number values of the image within the ROI
[r_mean_roi, g_mean_roi, b_mean_roi] = get_dn_means(img,roi)
# Calculate the mean GCC value
masked_gcc = g_mean_roi / (r_mean_roi + g_mean_roi, + b_mean_roi)
About Per90 and its calculation. Coming soon.
About Excess greenness and its calculation. Coming soon.
The Normalized Difference Vegetation Index (NDVI) is a common measure of vegetation health. The NDVI is calculated using the red and near-infrared parts of the spectrum:
NDVI = (NIR - Red) / (NIR + Red)
For PhenoCams that include an 'IR View,' it is possible to create an NDVI image using the RGB and IR images with the same timestamps.
It should be noted that the 'IR View' available through standard Stardot SC PhenoCam cameras is obtained by removing the IR filter from the CCD, thus exposing the camera to IR radiation that would otherwise be filtered out. The IR image is thus not a perfect comparison to other remote sensing instruments with IR sensors, as the IR image is also sensitive to the RGB portions of the spectrum.
Example:
Given the two PhenoCam images from the ninemileprairie site, create an NDVI image using Python.
from PIL import Image
import numpy as np
from matplotlib import pyplot as plt # For image viewing
# Open an RGB and IR PhenoCam image
rgb_img = Image.open('/path/to/rgb/PhenoCam/image.jpg')
ir_img = Image.open('/path/to/ir/PhenoCam/image.jpg')
# Get the red band from the rgb image, and open it as a numpy matrix
r,_,_ = rgb_img.split()
r = np.asarray(r, datatype=float)
# Get one of the IR image bands (all bands should be same)
ir,_,_ = ir_img.split()
ir = np.asarray(ir, datatype=float)
# Remove the header from the image
header = r[0:85,:]
r = r[85:,:]
ir = ir[85:,:]
# Create a numpy matrix of zeros to hold the calculated NDVI values for each pixel
ndvi = np.zeros(r.size) # The NDVI image will be the same size as the input image
# Calculate NDVI
ndvi = np.true_divide(np.subtract(ir, r), np.add(ir, r))
# Display the results
plt.plot(ndvi)
plt.colorbar()
plt.show() # Results shown below
Alternatively, the create_ndvi function can be utilized to create ndvi images from PhenoCam RGB/IR pairs.
from scipy import misc
from greenness import create_ndvi
# Open the RGB and IR images
rgb = misc.imread('/path/to/rgb/PhenoCam/image.jpg')
ir = misc.imread('/path/to/IR/PhenoCam/image.jpg')
# Get the NDVI image
ndvi = create_ndvi(rgb, ir, saveto = '/path/to/save/ndvi/image.jpg')
Other measures of greenness may include the Simple Vegetation Index, EVI, VARIgreen, etc. Details coming soon.