import cv2
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
img = cv2.imread('dargon.JPG',1)
GrayImage = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#GrayImage = np.array(dst).reshape(800,800).astype(np.uint8)
ret,thresh1=cv2.threshold(GrayImage,10,255,cv2.THRESH_BINARY)
ret,thresh2=cv2.threshold(GrayImage,10,255,cv2.THRESH_BINARY_INV)
ret,thresh3=cv2.threshold(GrayImage,10,255,cv2.THRESH_TRUNC)
ret,thresh4=cv2.threshold(GrayImage,10,255,cv2.THRESH_TOZERO)
ret,thresh5=cv2.threshold(GrayImage,10,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()
06_OpenCV二值化处理
A_lvvx2024-10-03 14:59
相关推荐
WeeJot嵌入式9 分钟前
卷积神经网络:深度学习中的图像识别利器脆皮泡泡18 分钟前
Ultiverse 和web3新玩法?AI和GameFi的结合是怎样机器人虎哥22 分钟前
【8210A-TX2】Ubuntu18.04 + ROS_ Melodic + TM-16多线激光 雷达评测码银29 分钟前
冲破AI 浪潮冲击下的 迷茫与焦虑何大春33 分钟前
【弱监督语义分割】Self-supervised Image-specific Prototype Exploration for WSSS 论文阅读uncle_ll40 分钟前
PyTorch图像预处理:计算均值和方差以实现标准化宋1381027972041 分钟前
Manus Xsens Metagloves虚拟现实手套SEVEN-YEARS1 小时前
深入理解TensorFlow中的形状处理函数世优科技虚拟人1 小时前
AI、VR与空间计算:教育和文旅领域的数字转型力量cloud studio AI应用1 小时前
腾讯云 AI 代码助手:产品研发过程的思考和方法论