当前位置:网站首页>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 .
边栏推荐
- stm32F407-------SPI通信
- Mujoco Jacobi - inverse motion - sensor
- mongodb客户端操作(MongoRepository)
- 深度学习之线性代数
- OSPF configuration command of Huawei equipment
- Stm32f407 ------- DAC digital to analog conversion
- Win10 startup error, press F9 to enter how to repair?
- alexnet实验偶遇:loss nan, train acc 0.100, test acc 0.100情况
- C9 colleges and universities, doctoral students make a statement of nature!
- 学习光线跟踪一样的自3D表征Ego3RT
猜你喜欢

Configuring OSPF basic functions for Huawei devices

集合(泛型 & List & Set & 自定义排序)

【vulnhub】presidential1

基於GO語言實現的X.509證書

Data processing of deep learning

JS+SVG爱心扩散动画js特效

第四篇,STM32中断控制编程

三维扫描体数据的VTK体绘制程序设计

【YoloV5 6.0|6.1 部署 TensorRT到torchserve】环境搭建|模型转换|engine模型部署(详细的packet文件编写方法)

Basic information of mujoco
随机推荐
[software reverse automation] complete collection of reverse tools
深入探索编译插桩技术(四、ASM 探秘)
Model-Free Control
uniapp中redirectTo和navigateTo的区别
Lombok makes ⽤ @data and @builder's pit at the same time. Are you hit?
Learning notes 5: ram and ROM
[Niuke classic question 01] bit operation
509 certificat basé sur Go
深度学习简史(二)
Distributed cache
New feature of Oracle 19C: automatic DML redirection of ADG, enhanced read-write separation -- ADG_ REDIRECT_ DML
腾讯云 WebShell 体验
Jenkins' user credentials plug-in installation
JS+SVG爱心扩散动画js特效
[Batch dos - cmd Command - Summary and Summary] - String search, find, Filter Commands (FIND, findstr), differentiation and Analysis of Find and findstr
37頁數字鄉村振興智慧農業整體規劃建設方案
如何判断一个数组中的元素包含一个对象的所有属性值
uniapp实现从本地上传头像并显示,同时将头像转化为base64格式存储在mysql数据库中
ActiveReportsJS 3.1中文版|||ActiveReportsJS 3.1英文版
Advanced learning of MySQL -- basics -- multi table query -- external connection