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

边栏推荐
- 电池、电机技术受到很大关注,反而电控技术却很少被提及?
- Openvscode cloud ide joins rainbow integrated development system
- 漏洞複現-Fastjson 反序列化
- Interactive book delivery - signed version of Oracle DBA work notes
- PVTV2--Pyramid Vision TransformerV2学习笔记
- 面试题(CAS)
- 云原生存储解决方案Rook-Ceph与Rainbond结合的实践
- [IELTS speaking] Anna's oral learning records part2
- [IELTS speaking] Anna's oral learning records Part3
- MES system is a necessary choice for enterprise production
猜你喜欢

Bisenet features

DeiT学习笔记

One click installation of highly available Nacos clusters in rainbow

Fast parsing intranet penetration escorts the document encryption industry

Pvtv2--pyramid vision transformer V2 learning notes

Don't stop chasing the wind and the moon. Spring mountain is at the end of Pingwu

【无标题】

Register of assembly language by Wang Shuang

Caractéristiques de bisenet

Rainbow version 5.6 was released, adding a variety of installation methods and optimizing the topology operation experience
随机推荐
[quick start of Digital IC Verification] 10. Verilog RTL design must know FIFO
积分商城管理系统中应包含的四大项
Leetcode 187 Repeated DNA sequence (2022.07.06)
Register of assembly language by Wang Shuang
[untitled]
打通法律服务群众“最后一公里”,方正璞华劳动人事法律自助咨询服务平台频获“点赞”
rsync远程同步
Pvtv2--pyramid vision transformer V2 learning notes
Automatic upgrading of database structure in rainbow
Using helm to install rainbow in various kubernetes
Splunk查询csv lookup table数据动态查询
解读创客思维与数学课程的实际运用
在 Rainbond 中一键安装高可用 Nacos 集群
Lua 编程学习笔记
Use of any superclass and generic extension function in kotlin
【Go ~ 0到1 】 第七天 获取时间戳,时间比较,时间格式转换,Sleep与定时器
GFS分布式文件系统
BiSeNet的特点
漏洞複現-Fastjson 反序列化
发挥创客教育空间的广泛实用性