06_OpenCV二值化处理

复制代码
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() 
相关推荐
roman_日积跬步-终至千里几秒前
【人工智能导论】05-学习-机器学习基础:从数据到智能决策
人工智能·学习·机器学习
nice_lcj5201 分钟前
【AI进阶】拒绝“人工智障”:掌握提示词工程(Prompt Engineering)的6大核心技巧
人工智能·prompt
万俟淋曦3 分钟前
【论文速递】2025年第40周(Sep-28-Oct-04)(Robotics/Embodied AI/LLM)
人工智能·深度学习·ai·机器人·大模型·论文·具身智能
jiayong234 分钟前
Spring AI Alibaba 深度解析(一):框架概述与核心功能
java·人工智能·spring
亚马逊云开发者19 分钟前
基于Amazon Q Developer实现IoT设备的Amazon Timestream性能与成本优化
人工智能
cyyt22 分钟前
深度学习周报(12.15~12.21)
人工智能·深度学习·最优传输
Blossom.11822 分钟前
大模型推理优化实战:连续批处理与PagedAttention性能提升300%
大数据·人工智能·python·神经网络·算法·机器学习·php
陈天伟教授27 分钟前
人工智能训练师认证教程(1)数据标注-Labelimg的使用教程
人工智能·神经网络·机器学习
Hcoco_me32 分钟前
Seq2Seq:Encoder-Decoder架构详解
人工智能·rnn·深度学习
江上鹤.14840 分钟前
Day44 训练和测试的规范写法
人工智能·深度学习·机器学习