opencv中归一化函数normalize()的原理讲解

1. 归一化

归一化就是要把需要处理的数据经过处理后(通过某种算法)限制在你需要的一定范围内。

首先归一化是为了后面数据处理的方便,其次是保证程序运行时收敛加快。归一化的具体作用是归纳统一样本的统计分布性。归一化在0-1之间是统计的概率分布,归一化在某个区间上是统计的坐标分布。归一化有同一、统一和合一的意思。

归一化的目的,是使得没有可比性的数据变得具有可比性,同时又保持相比较的两个数据之间的相对关系,如大小关系;或是为了作图,原来很难在一张图上作出来,归一化后就可以很方便的给出图上的相对位置等。


2. opencv中的归一化函数normalize()

opencv文档中的介绍如下:

C++:  void  normalize (InputArray  src, InputOutputArray  dst, double  alpha=1, double  beta=0, int  norm_type=NORM_L2, int  dtype=-1, InputArray  mask=noArray()  )
C++:  void  normalize (const SparseMat&  src, SparseMat&  dst, double  alpha, int  normType )
Python:   cv2. normalize (src [, dst [, alpha [, beta [, norm_type [, dtype [, mask ] ] ] ] ] ] ) → dst
Parameters:
  • src – input array.
  • dst – output array of the same size as src .
  • alpha – norm value to normalize to or the lower range boundary in case of the range normalization.
  • beta – upper range boundary in case of the range normalization; it is not used for the norm normalization.
  • normType – normalization type (see the details below).
  • dtype – when negative, the output array has the same type as src; otherwise, it has the same number of channels as src and the depth =CV_MAT_DEPTH(dtype).
  • mask – optional operation mask.

The functions normalize scale and shift the input array elements so that

\| \texttt{dst} \| _{L_p}= \texttt{alpha}

(where p=Inf, 1 or 2) when normType=NORM_INFNORM_L1, or NORM_L2, respectively; or so that

\min _I  \texttt{dst} (I)= \texttt{alpha} , \, \, \max _I  \texttt{dst} (I)= \texttt{beta}

when normType=NORM_MINMAX (for dense arrays only). The optional mask specifies a sub-array to be normalized. This means that the norm or min-n-max are calculated over the sub-array, and then this sub-array is modified to be normalized. If you want to only use the mask to calculate the norm or min-max but modify the whole array, you can use norm() and Mat::convertTo().

In case of sparse matrices, only the non-zero values are analyzed and transformed. Because of this, the range transformation for sparse matrices is not allowed since it can shift the zero level.

从上面可以看成,opencv提供了四种不同的归一化方式,分别为NORM_INFNORM_MINMAX,NORM_L1NORM_L2。下面分别解释一下各自代表的含义及归一化公式。

NORM_MINMAX:数组的数值被平移或缩放到一个指定的范围,线性归一化。

比如归一化到(min,max)范围内:


NORM_INF: 归一化数组的(切比雪夫距离)L范数(绝对值的最大值)


NORM_L1 :  归一化数组的(曼哈顿距离)L1-范数(绝对值的和)

opencv中归一化函数normalize()的原理讲解_第1张图片

NORM_L2: 归一化数组的(欧几里德距离)L2-范数

opencv中归一化函数normalize()的原理讲解_第2张图片

而其中的dtype为负数时,输出数组的type与输入数组的type相同;

否则,输出数组与输入数组只是通道数相同,而tpye=CV_MAT_DEPTH(dtype).




你可能感兴趣的:(opencv,数字图像处理基础)