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() 
相关推荐
zhangfeng11332 小时前
国家超算中心 scnet.cn 跨用户文件分享流程总结 多个用户之间 文件共享 不需要反复下载上传
人工智能·语言模型·大模型
ting94520005 小时前
Tornado 全栈技术深度指南:从原理到实战
人工智能·python·架构·tornado
果汁华5 小时前
Browserbase Skills:让 Claude Agent 真正“看见“网页世界
人工智能·python
ZhengEnCi5 小时前
04-缩放点积注意力代码实现 💻
人工智能·python
HackTwoHub6 小时前
AI大模型网关存在SQL注入、附 POC 复现、影响版本LiteLLM 1.81.16~1.83.7(CVE-2026-42208)
数据库·人工智能·sql·网络安全·系统安全·网络攻击模型·安全架构
段一凡-华北理工大学6 小时前
【高炉炼铁领域炉温监测、预警、调控智能体设计与应用】~系列文章08:多模态数据融合:让数据更聪明
人工智能·python·高炉炼铁·ai赋能·工业智能体·高炉炉温
网络工程小王7 小时前
【LangChain 大模型6大调用指南】调用大模型篇
linux·运维·服务器·人工智能·学习
HIT_Weston7 小时前
63、【Agent】【OpenCode】用户对话提示词(示例)
人工智能·agent·opencode
CV-杨帆7 小时前
Phi-4-mini-flash-reasoning 部署安装与推理测试完整记录
人工智能
MediaTea7 小时前
AI 术语通俗词典:C4.5 算法
人工智能·算法