当前位置:网站首页>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 .
边栏推荐
- 深入探索编译插桩技术(四、ASM 探秘)
- Mujoco produces analog video
- Interface master v3.9, API low code development tool, build your interface service platform immediately
- Quaternion attitude calculation of madgwick
- Memory optimization of Amazon memorydb for redis and Amazon elasticache for redis
- [daily problem insight] prefix and -- count the number of fertile pyramids in the farm
- ActiveReportsJS 3.1中文版|||ActiveReportsJS 3.1英文版
- Advanced learning of MySQL -- basics -- multi table query -- self join
- [yolov5 6.0 | 6.1 deploy tensorrt to torch serve] environment construction | model transformation | engine model deployment (detailed packet file writing method)
- Advanced learning of MySQL -- Fundamentals -- four characteristics of transactions
猜你喜欢

Mujoco Jacobi - inverse motion - sensor

37 pages Digital Village revitalization intelligent agriculture Comprehensive Planning and Construction Scheme

Lombok makes ⽤ @data and @builder's pit at the same time. Are you hit?
![[C language] dynamic address book](/img/e7/ca1030a1099fe1f59f5d8dd722fdb7.jpg)
[C language] dynamic address book

VTK volume rendering program design of 3D scanned volume data

Lombok 同时使⽤ @Data 和 @Builder 的坑,你中招没?

用tkinter做一个简单图形界面

. Bytecode structure of class file

On February 19, 2021ccf award ceremony will be held, "why in Hengdian?"

Attention SLAM:一種從人類注意中學習的視覺單目SLAM
随机推荐
深度学习之环境配置 jupyter notebook
Idea automatically imports and deletes package settings
Interface master v3.9, API low code development tool, build your interface service platform immediately
Alexnet experiment encounters: loss Nan, train ACC 0.100, test ACC 0.100
【vulnhub】presidential1
Equals() and hashcode()
dynamic programming
腾讯云 WebShell 体验
做微服务研发工程师的一年来的总结
Mujoco second order simple pendulum modeling and control
在jupyter中实现实时协同是一种什么体验
Lombok makes ⽤ @data and @builder's pit at the same time. Are you hit?
Advanced learning of MySQL -- basics -- multi table query -- inner join
Telerik UI 2022 R2 SP1 Retail-Not Crack
. Bytecode structure of class file
Mujoco finite state machine and trajectory tracking
Uniapp uploads and displays avatars locally, and converts avatars into Base64 format and stores them in MySQL database
【软件逆向-自动化】逆向工具大全
[Batch dos - cmd Command - Summary and Summary] - String search, find, Filter Commands (FIND, findstr), differentiation and Analysis of Find and findstr
学习光线跟踪一样的自3D表征Ego3RT