当前位置:网站首页>Opencv learning notes II - basic image operations
Opencv learning notes II - basic image operations
2022-07-07 08:23:00 【I am a little rice】
1. POI Area : Region of interest
2. Edge fill
3. Numerical operation
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)

Image addition
image3 = image1+image2
plt.imshow(image3)

Image cropping
plt.imshow(image1[100:-100, 100:-100, :]);

Image zoom
fx and fy Represents the zoom factor
image4 = cv2.resize(image1, (0, 0), fx=3, fy=1)
plt.imshow(image4);

4. Image threshold
ret, dst = cv2.threshold(src, thresh, maxval, type)
- src: The input image , Only single channel images
- dst: Output chart
- thresh: threshold
- maxval: The value when the pixel value exceeds or is less than the threshold
- type: The type of binarization
- cv2.THRESH_BINARY Over threshold value maxval, Otherwise take 0
- cv2.THRESH_BINARY_INV THRESH_BINARY The reversal of
- cv2.THRESH_TRUNC Greater than the threshold set the threshold , The rest remains the same
- cv2.THRESH_TOZERO Greater than the threshold unchanged , The rest is set to 0
- cv2.THRESH_TOZERO_INV THRESH_TOZERO The reversal of
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()

边栏推荐
- PVTV2--Pyramid Vision TransformerV2学习笔记
- Open3d ISS key points
- The use of generics and vararg variable parameters in kotlin
- Full text query classification
- Understanding of out covariance, in inversion and invariance in kotlin
- 解读创客思维与数学课程的实际运用
- 使用SwinUnet训练自己的数据集
- Rainbond 5.7.1 支持对接多家公有云和集群异常报警
- 雅思考试自己的复习进度以及方法使用【日更版】
- Standard function let and generic extension function in kotlin
猜你喜欢

CTF-WEB shrine模板注入nmap的基本使用

单场带货涨粉10万,农村主播竟将男装卖爆单?

Improve the delivery efficiency of enterprise products (1) -- one click installation and upgrade of enterprise applications

使用 Nocalhost 开发 Rainbond 上的微服务应用

Explore creativity in steam art design

Obsidan之数学公式的输入

Easy to understand SSO

Rainbow version 5.6 was released, adding a variety of installation methods and optimizing the topology operation experience

Ebpf cilium practice (1) - team based network isolation

Call pytorch API to complete linear regression
随机推荐
【无标题】
Basic use of CTF web shrink template injection nmap
Coquette data completes the cloud native transformation through rainbow to realize offline continuous delivery to customers
XCiT学习笔记
Qinglong panel -- Huahua reading
Domain specific language / DSL in kotlin
Open3d ISS key points
Call pytorch API to complete linear regression
拓维信息使用 Rainbond 的云原生落地实践
Zcmu--1396: queue problem (2)
Open3D ISS关键点
在Rainbond中一键部署高可用 EMQX 集群
柯基数据通过Rainbond完成云原生改造,实现离线持续交付客户
BiSeNet的特點
Lua programming learning notes
发挥创客教育空间的广泛实用性
JS copy picture to clipboard read clipboard
Myabtis_ Plus
Leetcode 187 Repeated DNA sequence (2022.07.06)
opencv学习笔记四——膨胀/腐蚀/开运算/闭运算