当前位置:网站首页>opencv学习笔记二——图像基本操作
opencv学习笔记二——图像基本操作
2022-07-07 05:19:00 【我是一个小稻米】
1. POI区域:感兴趣区域
2. 边缘填充
3. 数值运算
import cv2
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
from PIL import Image
image1 = mpimg.imread('1.jpg')
image2 = mpimg.imread('2.jpg')
plt.imshow(image1)
plt.imshow(image2)
图像加法
image3 = image1+image2
plt.imshow(image3)
图像裁剪
plt.imshow(image1[100:-100, 100:-100, :]);
图像缩放
fx和fy表示缩放倍数
image4 = cv2.resize(image1, (0, 0), fx=3, fy=1)
plt.imshow(image4);
4. 图像阈值
ret, dst = cv2.threshold(src, thresh, maxval, type)
- src: 输入图像,只能是单通道图像
- dst:输出图
- thresh:阈值
- maxval:当像素值超过了阈值或小于阈值时的取值
- type:二值化的类型
- cv2.THRESH_BINARY 超过阈值取maxval,否则取0
- cv2.THRESH_BINARY_INV THRESH_BINARY的反转
- cv2.THRESH_TRUNC 大于阈值设置阈值,其余不变
- cv2.THRESH_TOZERO 大于阈值不变,其余设为0
- cv2.THRESH_TOZERO_INV THRESH_TOZERO的反转
image1_gray = image1[:,:,0]
res, thresh1 = cv2.threshold(image1_gray, 127, 255, cv2.THRESH_BINARY)
res, thresh2 = cv2.threshold(image1_gray, 127, 255, cv2.THRESH_BINARY_INV)
res, thresh3 = cv2.threshold(image1_gray, 127, 255, cv2.THRESH_TRUNC)
res, thresh4 = cv2.threshold(image1_gray, 127, 255, cv2.THRESH_TOZERO)
res, thresh5 = cv2.threshold(image1_gray, 127, 255, cv2.THRESH_TOZERO_INV)
titles = ['Original Image', 'BINARY', 'BINARY_INV', 'TRUNC', 'TOZERO', 'TOZERO_INV']
images = [image1_gray, 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()
边栏推荐
- Function extension, attribute extension and non empty type extension in kotlin
- [quick start of Digital IC Verification] 13. SystemVerilog interface and program learning
- Easy to understand SSO
- Zsh shell adds automatic completion and syntax highlighting
- 【Go ~ 0到1 】 第七天 获取时间戳,时间比较,时间格式转换,Sleep与定时器
- eBPF Cilium实战(2) - 底层网络可观测性
- 追风赶月莫停留,平芜尽处是春山
- LeetCode中等题之我的日程安排表 I
- 使用 Nocalhost 开发 Rainbond 上的微服务应用
- 【无标题】
猜你喜欢
柯基数据通过Rainbond完成云原生改造,实现离线持续交付客户
[quick start of Digital IC Verification] 11. Introduction to Verilog testbench (VTB)
快解析内网穿透为文档加密行业保驾护航
Network learning (III) -- highly concurrent socket programming (epoll)
Avatary的LiveDriver试用体验
buureservewp(2)
Rainbond 5.7.1 支持对接多家公有云和集群异常报警
Network learning (I) -- basic model learning
Niu Mei's mathematical problem --- combinatorial number
Vulnerability recurrence easy_ tornado
随机推荐
[quick start of Digital IC Verification] 12. Introduction to SystemVerilog testbench (svtb)
【数字IC验证快速入门】10、Verilog RTL设计必会的FIFO
DNS server configuration
Dedecms collects content without writing rules
Openjudge noi 2.1 1752: chicken and rabbit in the same cage
Use of any superclass and generic extension function in kotlin
Call pytorch API to complete linear regression
一文了解如何源码编译Rainbond基础组件
解析机器人科技发展观对社会研究论
Summary of redis functions
让Livelink初始Pose与动捕演员一致
Introduction à l'objet blob
CCTV is so warm-hearted that it teaches you to write HR's favorite resume hand in hand
Uniapp mobile terminal forced update function
Myabtis_Plus
Unityhub cracking & unity cracking
【雅思口语】安娜口语学习记录 Part2
力扣(LeetCode)187. 重复的DNA序列(2022.07.06)
Use of JMeter
Application of slip ring of shipborne radar antenna