In this recipe, you will learn how to convert a grayscale image into a binary image using different thresholding approaches.
Processing images with different thresholds
Getting ready
Install the OpenCV 3.x Python API package and the matplotlib package.
How to do it...
Perform the following steps:
- Import the packages:
import cv2
import numpy as np
import matplotlib.pyplot as plt
- Read the test image:
image = cv2.imread('../data/Lena.png', 0)
- Apply a simple binary threshold:
thr, mask = cv2.threshold(image, 200, 1, cv2.THRESH_BINARY)
print('Threshold used...