In this recipe, you will learn how to apply basic morphological operations to binary images.
Morphological operators
Getting ready
Install the OpenCV Python API package and the matplotlib package.
How to do it...
Follow these steps:
- Import the packages:
import cv2
import numpy as np
import matplotlib.pyplot as plt
- Read the test image and build a binary image using Otsu's method:
image = cv2.imread('../data/Lena.png', 0)
_, binary = cv2.threshold(image, -1, 1, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
- Apply erosion and dilatation 10 times using a 3x3 rectangle...