当前位置:网站首页>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 .
边栏推荐
- C9 colleges and universities, doctoral students make a statement of nature!
- Explain in detail the implementation of call, apply and bind in JS (source code implementation)
- 509 certificat basé sur Go
- Stm32f407 ------- DAC digital to analog conversion
- What is time
- STM32开发资料链接分享
- Advanced learning of MySQL -- Fundamentals -- four characteristics of transactions
- Telerik UI 2022 R2 SP1 Retail-Not Crack
- uniapp中redirectTo和navigateTo的区别
- 随时随地查看远程试验数据与记录——IPEhub2与IPEmotion APP
猜你喜欢
[software reverse automation] complete collection of reverse tools
Mujoco finite state machine and trajectory tracking
alexnet实验偶遇:loss nan, train acc 0.100, test acc 0.100情况
【批处理DOS-CMD命令-汇总和小结】-字符串搜索、查找、筛选命令(find、findstr),Find和findstr的区别和辨析
Trace tool for MySQL further implementation plan
Zynq transplant ucosiii
Win10 startup error, press F9 to enter how to repair?
Lombok makes ⽤ @data and @builder's pit at the same time. Are you hit?
学习使用代码生成美观的接口文档!!!
ZYNQ移植uCOSIII
随机推荐
[software reverse automation] complete collection of reverse tools
Trace tool for MySQL further implementation plan
Js+svg love diffusion animation JS special effects
AI超清修复出黄家驹眼里的光、LeCun大佬《深度学习》课程生还报告、绝美画作只需一行代码、AI最新论文 | ShowMeAI资讯日报 #07.06
【批处理DOS-CMD命令-汇总和小结】-查看或修改文件属性(ATTRIB),查看、修改文件关联类型(assoc、ftype)
第四篇,STM32中断控制编程
Advanced learning of MySQL -- basics -- multi table query -- external connection
【YoloV5 6.0|6.1 部署 TensorRT到torchserve】环境搭建|模型转换|engine模型部署(详细的packet文件编写方法)
mongodb客户端操作(MongoRepository)
第六篇,STM32脉冲宽度调制(PWM)编程
深入探索编译插桩技术(四、ASM 探秘)
Dr selection of OSPF configuration for Huawei devices
Policy Gradient Methods
[yolov5 6.0 | 6.1 deploy tensorrt to torch serve] environment construction | model transformation | engine model deployment (detailed packet file writing method)
Chapter 5 DML data operation
第七篇,STM32串口通信编程
Markov decision process
The way of intelligent operation and maintenance application, bid farewell to the crisis of enterprise digital transformation
Quaternion attitude calculation of madgwick
【vulnhub】presidential1