March 2018
Beginner to intermediate
306 pages
9h 54m
English
To complete this recipe, we need to perform the following steps:
import cv2import numpy as npimport matplotlib.pyplot as plt
image = cv2.imread('../data/Lena.png', 0)
otsu_thr, otsu_mask = cv2.threshold(image, -1, 1, cv2.THRESH_BINARY | cv2.THRESH_OTSU)print('Estimated threshold (Otsu):', otsu_thr)
plt.figure()plt.subplot(121)plt.axis('off')plt.title('original')plt.imshow(image, cmap='gray')plt.subplot(122)plt.axis('off')plt.title('Otsu threshold')plt.imshow(otsu_mask, cmap='gray')plt.tight_layout()plt.show()