This chapter focused on how to extract color histograms from images and then apply a Random Forest classifier to recognize plant species in images.

To accomplish this, we leveraged a subset of the popular Flowers-17 dataset.

Mask generation

When going through this chapter, you may have noticed that we had the masks for each flower, allowing us to determine where in the image the flower is:

plant_classification_mask_example

How did we obtain these masks?

The masks actually came from the creators of the dataset — the creators manually segmented the flowers from the image, giving us a nice representation of the foreground and background.

That’s all fine, but how do we obtain masks of our own for custom datasets?

Great question — and for that, I would suggest referring back to the later chapters of Practical Python and OpenCV.

Consider your dataset:

Can you apply thresholding to segment the object from the background?

What about edge detection? Is that a viable option?

Even if thresholding or edge detection do not give you perfect segmentations, that may be okay.

You can actually take the output of these less-than-perfect operations and pipe them into an algorithm called GrabCut.

GrabCut for segmentation

The GrabCut algorithm is a very popular algorithm used to segment foregrounds from complex backgrounds.

This algorithm requires an input image along with either:

  1. The approximate bounding box of the object of interest in the image.
  2. An approximate mask of the object of interest in the image.

From there, the GrabCut algorithm uses this information to segment complex objects from the image.

Whenever possible, consider applying GrabCut to aid you in more complex segmentations that simple thresholding and/or edge detection cannot handle.

Only scratching the surface

This chapter was a great introduction to the concept of classifying image contents — but in all honestly, we are only scratching the surface of what’s possible.

If you’re interested in learning more about image classification, consider joining the PyImageSearch Gurus course where I have over 60+ lessons dedicated to classifying and recognizing the contents of images. I also cover Deep Learning and Convolutional Neural Network methods as well.

To learn more about the PyImageSearch Gurus course, just use this link:

https://www.pyimagesearch.com/pyimagesearch-gurus/

0% Complete
0/18 Steps