OpenCV中的归一化函数normalize()

当范数(数值)归一化时:默认的alpha=1是范数归一化的值,默认的beta=0在范数归一化时不会使用。
当范围归一化:alpha=0是下限,beta=255是上限,这里举得例子是范围为(0,255)。

详细介绍请参考博客https://blog.csdn.net/cosmispower/article/details/64457406

然后可以配合OpenCV源码看,源码如下:

/** @brief Normalizes the norm or value range of an array.

The function cv::normalize normalizes scale and shift the input array elements so that
\f[\| \texttt{dst} \| _{L_p}= \texttt{alpha}\f]
(where p=Inf, 1 or 2) when normType=NORM_INF, NORM_L1, or NORM_L2, respectively; or so that
\f[\min _I  \texttt{dst} (I)= \texttt{alpha} , \, \, \max _I  \texttt{dst} (I)= \texttt{beta}\f]

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.

Possible usage with some positive example data:
@code{.cpp}
    vector<double> positiveData = { 2.0, 8.0, 10.0 };
    vector<double> normalizedData_l1, normalizedData_l2, normalizedData_inf, normalizedData_minmax;

    // Norm to probability (total count)
    // sum(numbers) = 20.0
    // 2.0      0.1     (2.0/20.0)
    // 8.0      0.4     (8.0/20.0)
    // 10.0     0.5     (10.0/20.0)
    normalize(positiveData, normalizedData_l1, 1.0, 0.0, NORM_L1);

    // Norm to unit vector: ||positiveData|| = 1.0
    // 2.0      0.15
    // 8.0      0.62
    // 10.0     0.77
    normalize(positiveData, normalizedData_l2, 1.0, 0.0, NORM_L2);

    // Norm to max element
    // 2.0      0.2     (2.0/10.0)
    // 8.0      0.8     (8.0/10.0)
    // 10.0     1.0     (10.0/10.0)
    normalize(positiveData, normalizedData_inf, 1.0, 0.0, NORM_INF);

    // Norm to range [0.0;1.0]
    // 2.0      0.0     (shift to left border)
    // 8.0      0.75    (6.0/8.0)
    // 10.0     1.0     (shift to right border)
    normalize(positiveData, normalizedData_minmax, 1.0, 0.0, NORM_MINMAX);
@endcode

@param src input array.
@param dst output array of the same size as src .
@param alpha norm value to normalize to or the lower range boundary in case of the range
normalization.
@param beta upper range boundary in case of the range normalization; it is not used for the norm
normalization.
@param norm_type normalization type (see cv::NormTypes).
@param 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).
@param mask optional operation mask.
@sa norm, Mat::convertTo, SparseMat::convertTo

翻译:

/** @brief规范化数组的范数或值范围。

函数cv::normalize规格化缩放和移动输入数组元素
\f[\| \texttt{dst} \| _{L_p}= \texttt{alpha} f]
(其中p=Inf, 1或2)当normType分别=NORM_INF, NORM_L1或NORM_L2时;
左右,
f \[\分钟_I \ texttt { dst }(I)= \ texttt {α},\ \,马克斯_I \ \ texttt { dst }(I)= \ texttt {β} \ f]

当normType=NORM_MINMAX(仅适用于密集数组)时。
可选掩码指定要的子数组
归一化。
这意味着模或min-n-max是在子数组上计算的,然后这个
将子数组修改为规范化。
如果你只想用蒙版来计算范数或
但是修改整个数组,可以使用norm和Mat::convertTo。

对于稀疏矩阵,只分析和变换非零值。
由于这个原因,
稀疏矩阵的范围变换是不允许的,因为它可以改变零级。

可能的用法与一些积极的例子数据:

@code { . cpp }
向量<double> positiveData = {2.0, 8.0, 10.0};
向量<double> normalizedData_l1, normalizedData_l2, normalizedData_inf, normalizedData_minmax;

//概率范数(总数)
//和(数字)= 20.0
// 2.0 0.1 (2.0/20.0)
// 8.0 0.4 (8.0/20.0)
// 10.0 0.5 (10.0/20.0)
normalize(positiveData, normalizedData_l1, 1.0, 0.0, NORM_L1);

//单位向量的范数:||positiveData|| = 1.0
/ / 2.0 - 0.15
/ / 8.0 - 0.62
/ / 10.0 - 0.77
normalize(positiveData, normalizedData_l2, 1.0, 0.0, NORM_L2);

//对max元素赋范
// 2.0 0.2 (2.0/10.0)
// 8.0 0.8 (8.0/10.0)
// 10.0 1.0 (10.0/10.0)
normalize(positiveData, normalizedData_inf, 1.0, 0.0, NORM_INF);

//规范到范围[0.0;1.0]
// 2.0 0.0(左移)
// 8.0 0.75 (6.0/8.0)
// 10.0 1.0(右移)
normalize(positiveData, normalizedData_minmax, 1.0, 0.0, NORM_MINMAX);

@endcode

@param src输入数组。
与src大小相同的param dst输出数组。
@param规范值,以便在范围的情况下规范化到或更低的范围边界
规范化。
@param beta在距离归一化情况下的上限边界;
它不用于规范
规范化。
@param norm_type规范化类型(参见cv::NormTypes)。
@param dtype为负时,输出数组与src类型相同;
否则,它是一样的
通道数,如src和depth =CV_MAT_DEPTH(dtype)。
@param可选操作掩码。
@sa norm, Mat::convertTo, SparseMat::convertTo

猜你喜欢

转载自blog.csdn.net/Young__Fan/article/details/82992944