Finally, let's take a quick look at the Watershed algorithm. The algorithm is called Watershed because its conceptualization involves water. Imagine areas with low density (little to no change) in an image as valleys, and areas with high density (lots of change) as peaks. Start filling the valleys with water to the point where water from two different valleys is about to merge. To prevent the merging of water from different valleys, you build a barrier to keep them separated. The resulting barrier is the image segmentation.
As an example, let's segment an image of a playing card. We want to separate the pips (the large, countable symbols) from the background:
- Once more, we begin our script by importing numpy, cv2, and matplotlib. Then, we load our image of a playing card from file:
import numpy as np
import cv2
from matplotlib...