当前位置:网站首页>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 .
边栏推荐
- Notes of training courses selected by Massey school
- STM32开发资料链接分享
- Three methods to realize JS asynchronous loading
- 新手如何入门学习PostgreSQL?
- [Batch dos - cmd Command - Summary and Summary] - String search, find, Filter Commands (FIND, findstr), differentiation and Analysis of Find and findstr
- Data processing of deep learning
- 【软件逆向-自动化】逆向工具大全
- Attention SLAM:一种从人类注意中学习的视觉单目SLAM
- 509 certificat basé sur Go
- equals()与hashCode()
猜你喜欢
How to set encoding in idea
Set (generic & list & Set & custom sort)
Deep learning environment configuration jupyter notebook
stm32F407-------SPI通信
48 page digital government smart government all in one solution
Mujoco second order simple pendulum modeling and control
Interface master v3.9, API low code development tool, build your interface service platform immediately
ZYNQ移植uCOSIII
Win10 startup error, press F9 to enter how to repair?
【vulnhub】presidential1
随机推荐
Service asynchronous communication
Advanced learning of MySQL -- Fundamentals -- four characteristics of transactions
Stm32f407 ------- SPI communication
Advanced learning of MySQL -- basics -- basic operation of transactions
JWT signature does not match locally computed signature. JWT validity cannot be asserted and should
接口(接口相关含义,区别抽象类,接口回调)
Leetcode(547)——省份数量
mongodb客户端操作(MongoRepository)
深度学习简史(二)
Notes of training courses selected by Massey school
OSPF configuration command of Huawei equipment
Alexnet experiment encounters: loss Nan, train ACC 0.100, test ACC 0.100
基于SSM框架的文章管理系统
Five different code similarity detection and the development trend of code similarity detection
Slow database query optimization
Configuring the stub area of OSPF for Huawei devices
Learn to use code to generate beautiful interface documents!!!
stm32F407-------SPI通信
2021 SASE integration strategic roadmap (I)
equals()与hashCode()