Creates a binary image from a gray image based on the threshold values. The object target can be specified as dark or light.
plantcv.threshold.binary(gray_img, threshold, object_type="light")
returns thresholded/binary image
- Parameters:
- gray_img - Grayscale image data
- threshold - Threshold value (0-255)
- object_type - "light" or "dark" (default: "light"). If object is lighter than the background then standard thresholding is done. If object is darker than the background then inverse thresholding is done.
- Context:
- Used to help differentiate plant and background
- Example use:
Original image
Grayscale image (saturation channel)
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 = "plot"
# Create binary image from a gray image based on threshold values,
# targeting light objects in the image.
threshold_light = pcv.threshold.binary(gray_img=gray_img, threshold=36, object_type='light')
Thresholded image
# Create binary image from a gray image based on threshold values,
# targeting dark objects in the image.
threshold_dark = pcv.threshold.binary(gray_img=gray_img, threshold=36, object_type='dark')
Thresholded image (inverse)
Source Code: Here