Skip to content

geezacoleman/LentilFlowerDetection

Repository files navigation

Lentil Flower Detection

A recent post on Twitter about detecting purple flowers in crop had me thinking how that might look in practice. So I put together this rough code that swaps the green channel for an additional blue channel and then uses the HSV colour space to threshold based on saturation and value.

Colour Spaces

Colour spaces are methods for representing colours in different ways. The standard one you might be familiar with is Red Green Blue or RGB. Others include HSV (hue saturation value), L*a*b* and Y'CbCr. In the end, a type of ExB (to pick out the purple flowers) worked quite well, splitting the RGB image into channels, then merging them back together as (B, B, R) to remove the green. Blue then became oversaturated and a subsequent transforation to HSV meant thresholding on saturation worked well.

There are a couple of mis detections in the darker regions. Initially I tried straight HSV, Lab and YCrCb colour spaces for thresholding, however, none had any decent performance. This technique rapidly stops working if conditions/lighting change, so it's more of a coding exercise for my PhD than anything.

As you can see, when the parameters (threshold values) are tuned specifically for the image, it performs quite well: Bight image  of tares

But as soon as the values of brightness, colour are changed (this could be from moving to a different crop, sunlight changing etc) then the performance drops considerably: Raw image from Twitter of tares

Some interesting colour space resources:

  1. PyImageSearch Colour Detection
  2. Rubix Cube Colour Detection
  3. or a fantastic video from Captain Disillusion on colour.

Sliding Windows

The code for the sliding windows is adapted from Adrian Rosebrock's PyImageSearch tutorial on "Sliding Windows for Object Detection with Python and OpenCV". I would highly recommend his tutorials and blog posts on all sorts of computer vision related material!

Reference

Adrian Rosebrock, Sliding Windows for Object Detection with Python and OpenCV, PyImageSearch, https://www.pyimagesearch.com/2015/03/23/sliding-windows-for-object-detection-with-python-and-opencv/, accessed on 12 September 2020.

About

Picking out purple tares flowers in a lentil crop

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages