标签:格式 平滑 images http mic opencv jpg 根据 输出
import cv2 #opencv读取的格式是BGR import numpy as np import matplotlib.pyplot as plt#Matplotlib是RGB %matplotlib inline img=cv2.imread(‘cat.jpg‘) img_gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) img_gray.shape
type:二值化操作的类型,包含以下5种类型: cv2.THRESH_BINARY; cv2.THRESH_BINARY_INV; cv2.THRESH_TRUNC; cv2.THRESH_TOZERO;cv2.THRESH_TOZERO_INV
cv2.THRESH_BINARY 超过阈值部分取maxval(最大值),否则取0
ret, thresh1 = cv2.threshold(img_gray, 127, 255, cv2.THRESH_BINARY) ret, thresh2 = cv2.threshold(img_gray, 127, 255, cv2.THRESH_BINARY_INV) ret, thresh3 = cv2.threshold(img_gray, 127, 255, cv2.THRESH_TRUNC) ret, thresh4 = cv2.threshold(img_gray, 127, 255, cv2.THRESH_TOZERO) ret, thresh5 = cv2.threshold(img_gray, 127, 255, cv2.THRESH_TOZERO_INV) titles = [‘Original Image‘, ‘BINARY‘, ‘BINARY_INV‘, ‘TRUNC‘, ‘TOZERO‘, ‘TOZERO_INV‘] images = [img, thresh1, thresh2, thresh3, thresh4, thresh5] for i in range(6): plt.subplot(2, 3, i + 1), plt.imshow(images[i], ‘gray‘) plt.title(titles[i]) plt.xticks([]), plt.yticks([]) plt.show()
标签:格式 平滑 images http mic opencv jpg 根据 输出
原文地址:https://www.cnblogs.com/exciting/p/10383737.html