当前位置:网站首页>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()

边栏推荐
- Vulnerability recurrence easy_ tornado
- Dedecms collects content without writing rules
- Réplication de vulnérabilité - désrialisation fastjson
- 提高企业产品交付效率系列(1)—— 企业应用一键安装和升级
- Niu Mei's mathematical problem --- combinatorial number
- Qinglong panel -- Huahua reading
- Empire CMS collection Empire template program general
- Use of any superclass and generic extension function in kotlin
- 调用 pytorch API完成线性回归
- 轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
猜你喜欢
![[quick start of Digital IC Verification] 12. Introduction to SystemVerilog testbench (svtb)](/img/dc/a809f2ec5f9e85a02e68c88bdcdb5e.png)
[quick start of Digital IC Verification] 12. Introduction to SystemVerilog testbench (svtb)

game攻防世界逆向

Rainbond 5.6 版本发布,增加多种安装方式,优化拓扑图操作体验

【踩坑系列】uniapp之h5 跨域的问题

【数字IC验证快速入门】12、SystemVerilog TestBench(SVTB)入门

漏洞複現-Fastjson 反序列化

提高企业产品交付效率系列(1)—— 企业应用一键安装和升级

Network learning (III) -- highly concurrent socket programming (epoll)

Notes on PHP penetration test topics

Hisense TV starts the developer mode
随机推荐
解析创新教育体系中的创客教育
Example of file segmentation
复杂网络建模(三)
Empire CMS collection Empire template program general
Recursive construction of maximum binary tree
[step on the pit series] H5 cross domain problem of uniapp
【数字IC验证快速入门】13、SystemVerilog interface 和 program 学习
Full text query classification
青龙面板-今日头条
Hisense TV starts the developer mode
LeetCode简单题之找到一个数字的 K 美丽值
Vulnerability recurrence easy_ tornado
轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
贝叶斯定律
[quick start of Digital IC Verification] 12. Introduction to SystemVerilog testbench (svtb)
Function extension, attribute extension and non empty type extension in kotlin
【雅思口语】安娜口语学习记录 Part3
JS copy picture to clipboard read clipboard
电池、电机技术受到很大关注,反而电控技术却很少被提及?
eBPF Cilium实战(2) - 底层网络可观测性