当前位置:网站首页>Basic operation of OpenCV actual combat image: this effect amazed everyone (with code analysis)
Basic operation of OpenCV actual combat image: this effect amazed everyone (with code analysis)
2022-06-10 23:58:00 【Programmer pear】
Preface
author :“ Programmer pear ”
** The article brief introduction **: This article focuses on Opencv Basic operation binarization 、 Image noise processing .
** Article source code access **: In order to thank everyone who pays attention to me, the project source code of each article is distributed free of charge
Enjoy drops
Welcome friends give the thumbs-up 、 Collection 、 Leaving a message.
Text
One 、 Two valued
1.1 The basic principle of binarization
Image binarization is to set the gray value of pixels on the image to 0 or 255, That is to present the whole image in obvious black and white
The process of effect . In digital image processing , Binary image plays a very important role , The binarization of image makes the amount of data in the image large
In order to reduce , So as to highlight the outline of the target .
1.2 Basic operation of image binarization
We use OpenCV To perform image binarization , Today's lecture OpenCV Image binary is mainly used in this
threshold Function to implement .
1.3 The attached code
image = cv2.imread('nv.png')
image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)# Grayscale the input image
cv2.threshold(image, 140, 255, 0, image)
cv2.namedWindow("Image")
cv2.imshow("Image", image)
cv2.waitKey(0)In this case we are using threshold function , The function prototype is
threshold(src, thresh, maxval, type[, dst])- src Parameter means input image ( Multichannel ,8 Bit or 32 Bit floating point ).
- thresh The parameter represents the threshold .
- maxval Parameter representation and THRESH_BINARY and THRESH_BINARY_INV The threshold type is used together with the maximum value set .
- type The parameter indicates the threshold type .
- retval Parameter indicates the threshold value returned . If it is a global fixed threshold algorithm , Then return to thresh Parameter values . If it is a global adaptive threshold algorithm , Then the appropriate threshold calculated adaptively is returned .
- dst The parameter represents the output and src Images of the same size and type and the same number of channels .
1.4 Effect display
I actually think the binary graph is very nice ~

Two 、 Image denoising
1.1 Introduction of the principle
Add noise -> The picture is not clear .
principle : Randomly replace the prime points with other values .
1.2 The attached code
img = cv2.imread('nv.png')
# Number of noise points
coutn = 100000
for k in range(0,coutn):
# Obtain the random position of image noise points
xi = int(np.random.uniform(0,img.shape[1]))
xj = int(np.random.uniform(0,img.shape[0]))
# Add noise
if img.ndim == 2:
# Grayscale image
img[xj,xi] = 255
elif img.ndim == 3:
# Non grayscale image , Image denoising
img[xj,xi,0] = 25
img[xj,xi,1] = 20
img[xj,xi,2] = 20
cv2.namedWindow('img')
cv2.imshow('img',img)
cv2.waitKey()
cv2.destroyAllWindows()1.2 Effect display
Original picture ——

design sketch ——

summary
Is the result of binarization and noise adding also quite satisfactory Ha ha ha It may be that my buyer shows a good picture ~ Rely on your face
value .jpg Well ~ Then you can ask me to try the code by yourself !
Follow Xiaobian for more wonderful content ! Remember to click on the portal
Remember Sanlian ! If you need packaged source code + Free sharing of materials !! Portal

边栏推荐
- 干货丨MapReduce的工作流程是怎样的?
- Self made app connected to onenet --- realize data monitoring and distribution control (mqtt)
- LabVIEW确定控件在显示器坐标系中的位置
- 【LaTex】latex VS Code snippets(代码片段)
- 给线程池里面线程添加名称的4种方式
- 判等问题:如何确定程序的判断是正确的?
- Hyperleger fabric installation
- Kubernetes 基本介绍及核心组件
- About optimizing API interface response speed
- Fiddler filtering sessions
猜你喜欢

【Pygame合集】回忆杀-“童年游戏”,看看你中几枪?(附五款源码自取)

Difference between oscilloscope and spectrum analyzer

怎么生成自动参考文献(简单 有图)

Solve access denied for user 'root' @ 'localhost' (using password: yes)

It is said that the verification code is a barrier in the crawler. I can break through it with only five lines of code.

【Pygame小游戏】这款“打地鼠”小游戏要火了(来来来)

【颜值检测神器】来,请拿出你们的绝活(这颜值,对得起观众么?)

【Pygame小游戏】“史上最炫酷贪吃蛇”驾到,FUN开玩(不好玩不要钱)

LabVIEW用VISA Read函数来读取USB中断数据

Vs tomato assistant add header comments and usage
随机推荐
csdn每日一练——找出最接近元素并输出下标
Baidu quick collection SEO optimization keyword ranking optimization skills
苹果CMS采集站源码-搭建教程-附带源码-全新源码-开发文档
[opencv practice] this seal "artifact" is awesome, saving time and improving efficiency. It is powerful ~ (complete source code attached)
快速排序
给线程池里面线程添加名称的4种方式
Fiddler creates an autoresponder
LabVIEW error "memory full - Application stopped on node"
Is it safe for CICC Fortune Securities to open an account? Is it reliable?
OpenResty安装
Apple CMS collection station source code - building tutorial - attached source code - new source code - development documents
After deepin20 menu startup option, the self-test indicates that iwlwwifi is stopped
LabVIEW displays the time and date on the waveform chart or waveform chart
[new version] new pseudo personal homepage v2.0- starze V Club
【自动回复小脚本】新年快乐,每一个字都是我亲自手打的,不是转发哦~
LabVIEW用VISA Read函数来读取USB中断数据
C# Tryparse的用法
【Pygame小游戏】剧情流推荐:什么样的游戏才能获得大家的喜欢呢?(魔鬼恋人、霸总娇妻版)
How to remove the blank at the top of listview
Interview questions - written examination
