当前位置:网站首页>Explain in detail the matrix normalization function normalize() of OpenCV [norm or value range of the scoped matrix (normalization)], and attach norm_ Example code in the case of minmax
Explain in detail the matrix normalization function normalize() of OpenCV [norm or value range of the scoped matrix (normalization)], and attach norm_ Example code in the case of minmax
2022-07-07 00:52:00 【Haohong image algorithm】
function normalize() There are two prototypes :
Prototype one :
void cv::normalize( InputArray src,
InputOutputArray dst,
double alpha = 1,
double beta = 0,
int norm_type = NORM_L2,
int dtype = -1,
InputArray mask = noArray()
)
Prototype two :
void cv::normalize( const SparseMat & src,
SparseMat & dst,
double alpha,
int normType
)
The applicable object of prototype 1 is dense matrix , Usually our matrices are dense matrices .
The applicable object of prototype 2 is sparse matrix , Sparse matrices are not very common , So prototype 2 will not be introduced in this blog post .
Before introducing the meaning of each parameter , Let's talk about the function first normalize() The role of .
function normalize() It does two things :
The first function is to normalize the norm of the matrix ;
The second function is to normalize the value range of the matrix , The value range of normalized matrix is usually what we call normalization .
The second function is that we often use , So this blog post focuses on its second function , The first function will not be introduced in detail .
When it is used to normalize the norm of a matrix , namely norm_type = NORM_MINMAX when , It achieves the following goals through linear zoom and pan operations :
∥ dst ∥ L p = alpha \| \texttt{dst} \| _{L_p}= \texttt{alpha} ∥dst∥Lp=alpha
On the type of dst Represents the objective matrix . ∥ dst ∥ L p \| \texttt{dst} \| _{L_p} ∥dst∥Lp Represents the norm value of the objective matrix .
In the above formula p The value of can be Inf、1、2, Corresponding to three different norms .
When p=Inf when , The corresponding parameter normType The value is NORM_INF;
When p=1 when , The corresponding parameter normType The value is NORM_L1;
When p=2 when , The corresponding parameter normType The value is NORM_L2.
When it is used to normalize the value range of the matrix , It achieves the following goals through linear zoom and pan operations :
That is, the function normalize() Will range the values in the original matrix from [min(src), max(src)] Scale linearly to [alpha, beta] The scope of the .
According to the above goal , It can be seen that the specific mathematical expression of the implementation is as follows :
d s t ( i , j ) − a l p h a b e t a − a l p h a = s r c ( i , j ) − m i n ( s r c ) m a x ( s r c ) − m i n ( s r c ) \frac{dst(i,j)-alpha}{beta-alpha}=\frac{src(i,j)-min(src)}{max(src)-min(src)} beta−alphadst(i,j)−alpha=max(src)−min(src)src(i,j)−min(src)
According to the above formula , You can get dst(i,j) The expression of , as follows :
d s t ( i , j ) = ( b e t a − a l p h a ) ∗ s r c ( i , j ) − m i n ( s r c ) m a x ( s r c ) − m i n ( s r c ) + a l p h a dst(i,j)=(beta-alpha)*\frac{src(i,j)-min(src)}{max(src)-min(src)}+alpha dst(i,j)=(beta−alpha)∗max(src)−min(src)src(i,j)−min(src)+alpha
Next , Start to introduce the significance of its prototype I parameters , Here, copy the prototype again .
void cv::normalize( InputArray src,
InputOutputArray dst,
double alpha = 1,
double beta = 0,
int norm_type = NORM_L2,
int dtype = -1,
InputArray mask = noArray()
)
- src— Input matrix
- dst— The output matrix .
- alpha— In the case of the first action of this function , It said norm value; In the case of the second function , function normalize() Will range the values in the original matrix from [min(src), max(src)] Scale linearly to [alpha, beta] The scope of the .
- beta— In the case of the first action of this function , It doesn't work , Is an invalid parameter . In the case of the second function , function normalize() Will range the values in the original matrix from [min(src), max(src)] Scale linearly to [alpha, beta] The scope of the .
- norm_type— This parameter determines the function normalize() What is the specific operation . Its values are shown in the following table :
The most commonly used is the last enumerated value , namely NORM_MINMAX, At this time, the goal and specific principle of this function have been made clear before introducing the parameter meaning of this function .
Last , Attach a pawn norm_type = NORM_MINMAX At the time of the Python Sample code .
# Blogger WeChat /QQ 2487872782
# If you have any questions, you can contact the blogger
# Please contact the blogger if you need image processing
# Image processing technology exchange QQ Group 271891601
# !/usr/bin/env python
# -*- coding: utf-8 -*-
# OpenCV The version is 4.4.0
import cv2 as cv
import numpy as np
A = np.array([[1, 2, 3, 4, 5],
[6, 7, 8, 9, 10],
[11, 12, 13, 14, 15],
[16, 17, 18, 19, 20],
[21, 22, 23, 24, 25]], dtype='uint8')
B = A.copy()
cv.normalize(A, B, alpha=100, beta=200, norm_type=cv.NORM_MINMAX)
The operation results are as follows :
so , By function normalize() The operation of , The matrix A The values of the elements in range from [1,25] The linearity is scaled to [100,200] The scope of the .
边栏推荐
- Levels - UE5中的暴雨效果
- alexnet实验偶遇:loss nan, train acc 0.100, test acc 0.100情况
- The way of intelligent operation and maintenance application, bid farewell to the crisis of enterprise digital transformation
- Model-Free Control
- 深度学习之环境配置 jupyter notebook
- 509 certificat basé sur Go
- Leetcode (547) - number of provinces
- 第四篇,STM32中断控制编程
- 集合(泛型 & List & Set & 自定义排序)
- Advanced learning of MySQL -- Fundamentals -- four characteristics of transactions
猜你喜欢
ZYNQ移植uCOSIII
【vulnhub】presidential1
Learn to use code to generate beautiful interface documents!!!
Configuring OSPF basic functions for Huawei devices
Mujoco Jacobi - inverse motion - sensor
第四篇,STM32中断控制编程
If the college entrance examination goes well, I'm already graying out at the construction site at the moment
随时随地查看远程试验数据与记录——IPEhub2与IPEmotion APP
【批处理DOS-CMD命令-汇总和小结】-字符串搜索、查找、筛选命令(find、findstr),Find和findstr的区别和辨析
pyflink的安装和测试
随机推荐
Dr selection of OSPF configuration for Huawei devices
MySQL learning notes (mind map)
【批处理DOS-CMD命令-汇总和小结】-字符串搜索、查找、筛选命令(find、findstr),Find和findstr的区别和辨析
Amazon MemoryDB for Redis 和 Amazon ElastiCache for Redis 的内存优化
深度学习之环境配置 jupyter notebook
The difference between redirectto and navigateto in uniapp
Web project com mysql. cj. jdbc. Driver and com mysql. jdbc. Driver differences
uniapp中redirectTo和navigateTo的区别
Telerik UI 2022 R2 SP1 Retail-Not Crack
一行代码实现地址信息解析
代码克隆的优缺点
Understand the misunderstanding of programmers: Chinese programmers in the eyes of Western programmers
Advanced learning of MySQL -- basics -- multi table query -- joint query
Attention SLAM:一种从人类注意中学习的视觉单目SLAM
深度学习简史(一)
String comparison in batch file - string comparison in batch file
AI super clear repair resurfaces the light in Huang Jiaju's eyes, Lecun boss's "deep learning" course survival report, beautiful paintings only need one line of code, AI's latest paper | showmeai info
Chapter II proxy and cookies of urllib Library
再聊聊我常用的15个数据源网站
Advantages and disadvantages of code cloning