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

边栏推荐
- Dedecms collects content without writing rules
- Blob object introduction
- Register of assembly language by Wang Shuang
- Pytoch (VI) -- model tuning tricks
- Basic use of CTF web shrink template injection nmap
- LeetCode简单题之判断一个数的数字计数是否等于数位的值
- 漏洞复现-easy_tornado
- [quick start of Digital IC Verification] 13. SystemVerilog interface and program learning
- JS cross browser parsing XML application
- opencv学习笔记四——膨胀/腐蚀/开运算/闭运算
猜你喜欢

复杂网络建模(一)

Jmeter 的使用

CDC (change data capture technology), a powerful tool for real-time database synchronization

opencv学习笔记三——图像平滑/去噪处理

Call pytorch API to complete linear regression

JS copy picture to clipboard read clipboard
![[quick start of Digital IC Verification] 13. SystemVerilog interface and program learning](/img/d8/ffc1b7527f0269cecb2946ab402a2e.png)
[quick start of Digital IC Verification] 13. SystemVerilog interface and program learning

漏洞複現-Fastjson 反序列化

Network learning (II) -- Introduction to socket

CCTV is so warm-hearted that it teaches you to write HR's favorite resume hand in hand
随机推荐
It's too true. There's a reason why I haven't been rich
调用 pytorch API完成线性回归
Full text query classification
Summary of redis functions
Lua 编程学习笔记
互动送书-《Oracle DBA工作笔记》签名版
【雅思口语】安娜口语学习记录 Part3
复杂网络建模(三)
buureservewp(2)
OpenVSCode云端IDE加入Rainbond一体化开发体系
基于Pytorch 框架手动完成线性回归
The element with setfieldsvalue set is obtained as undefined with GetFieldValue
Complex network modeling (II)
Interactive book delivery - signed version of Oracle DBA work notes
Blob object introduction
Easy to understand SSO
贝叶斯定律
央视太暖心了,手把手教你写HR最喜欢的简历
The simple problem of leetcode is to judge whether the number count of a number is equal to the value of the number
发挥创客教育空间的广泛实用性