python 学习笔记07 图像分割

#图像分割--各个分割算法比较
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('lean.png')
GrayImage= cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

ret, thresh1 = cv2.threshold(GrayImage, 127, 255, cv2.THRESH_BINARY)
ret, thresh2 = cv2.threshold(GrayImage, 127, 255, cv2.THRESH_BINARY_INV)
ret, thresh3 = cv2.threshold(GrayImage, 127, 255, cv2.THRESH_TRUNC)
ret, thresh4 = cv2.threshold(GrayImage, 127, 255, cv2.THRESH_TOZERO)
ret, thresh5 = cv2.threshold(GrayImage, 127, 255, cv2.THRESH_TOZERO_INV)
titles = ['Gray Image', 'BINARY', 'BINARY_INV', 'TRUNC', 'TOZERO', 'TOZERO_INV']
images = [GrayImage, 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()

猜你喜欢

转载自blog.csdn.net/qq_40025335/article/details/81607459
今日推荐