I. What Is Normalization
Normalization is about constraining the data to be processed, after processing (via some algorithm), within a certain range. This makes later data processing easier and also helps the program converge faster during runtime. The purpose of normalization is to make incomparable data comparable while preserving the relative relationship between the two data items being compared, such as their ordering; or, for plotting, data that was originally hard to plot on one chart can be normalized so that relative positions on the chart are easy to show.
II. Normalization Methods
2.1 Basic API
void normalize(
InputArray src,
InputOutputArray dst,
double alpha = 1,
double beta = 0,
int norm_type = NORM_L2,
int dtype = -1,
InputArray mask = noArray()
);
| Parameter | Purpose |
|---|---|
| src | Input array |
| dst | Output array |
| alpha | Normalized minimum value |
| beta | Normalized maximum value |
| norm_type | Normalization type |
| dtype | When negative, the output array type matches the input array type |
| mask | Indicator function for whether the operation applies only to specified elements |
norm_type has the following types:
- NORM_MINMAX: Array values are translated or scaled to a specified range; linear normalization, commonly used.
- NORM_INF: No definition found for this type; based on the corresponding entry in OpenCV 1, it may normalize the C-norm of the array (the maximum absolute value)
- NORM_L1 : Normalizes the L1 norm of the array (sum of absolute values)
- NORM_L2: Normalizes the (Euclidean) L2 norm of the array
2.2 Example Program
void MyDemo::normalize_Demo(Mat& image) {
Mat dst;
std::cout << image.type() << std::endl; //CV_8UC3
image.convertTo(image, CV_32F); //像素数据转换为浮点数数据
std::cout << image.type() << std::endl; //CV_32FC3
normalize(image, dst, 0, 1.0, NORM_MINMAX); //归一化
std::cout << dst.type() << std::endl;
imshow("Normalize", dst);
}![[Learning OpenCV 4] Converting and Normalizing Image Pixel Data Types](https://img.mahaofei.com/img/202112231858306-opencv-notes2-12.png)
Comments