From WolframAlpha NormL1 and NormL2:

Given a vector:

Norm L1 is the taxicab (or manhattan) distance (sum of absolute values):

while Norm L2 is the euclidean distance (square root of sum of squares):

The type of norm tells the BFMatcher how to compute the distances between every two features.

The NORM L1 is in general much faster to compute (mostly because you don't compute the square root). The NORM L2 is more accurate.

You can find a nice comparison here.

Answer from Miki on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › computer vision › normalize-an-image-in-opencv-python
Normalize an Image in OpenCV Python - GeeksforGeeks
July 23, 2025 - Normalization can be performed to improve the contrast of an image or to standardize the pixel values for further processing. In OpenCV Python, the normalize() function from the cv2 module is used to normalize images.
🌐
TutorialsPoint
tutorialspoint.com › article › how-to-normalize-an-image-in-opencv-python
How to normalize an image in OpenCV Python?
March 26, 2026 - Image normalization in OpenCV rescales pixel values to a specific range, improving image processing and machine learning model performance. The function provides various normalization techniques to transform pixel intensities.
Discussions

Difference between cv2.NORM_L2 and cv2.NORM_L1 in opencv python - Stack Overflow
I am using sift algorithm from python extra modules for some feature matching. Although one thing I did not understand is the concept behind the normType passed to the BFMatcher. i.e Which ones hav... More on stackoverflow.com
🌐 stackoverflow.com
How do i normalize an image better? - Python - OpenCV
Hi, Im using a python script to recieve images from a depth camera and when i started reading in the values of each pixel i had to normalize it to actually display it with imshow() So i used this command to normalize my image: cv2.normalize(depth_array, depth_array, 0, 1, cv2.NORM_MINMAX) ... More on forum.opencv.org
🌐 forum.opencv.org
0
February 15, 2021
Slow speed using cv2.norm(img1,img2) with opencv > 4.2.0.34
System Information OpencCV python version: 4.7.072 Operating System: Windows 11 pro Python version: 3.8.19 Detailed description I am used to use cv2.norm(img1, img2) to compare images. Using that function got slow with any opencv-python ... More on github.com
🌐 github.com
July 17, 2024
c++ - using opencv norm function to get euclidean distance of two points - Stack Overflow
But if I change the line std::cout ... - b, cv::NORM_L2)<< std::endl; error occurs and it tells me that such function cannot be matched. I don't understand why Point2f type cannot be converted since the only input parameter a-b works well. The opencv norm function given ... More on stackoverflow.com
🌐 stackoverflow.com
People also ask

What is the difference between NORM_MINMAX and NORM_L2?
NORM_MINMAX maps observed values to bounds, while NORM_L2 scales according to the Euclidean norm; they serve different data contracts.
🌐
pythonpool.com
pythonpool.com › home › opencv › cv2.normalize() in python: scale images and arrays
cv2.normalize() in Python: Scale Images and Arrays
Can cv2.normalize() use a mask?
Yes. A mask limits which elements participate, so inspect the mask shape and verify whether the output outside the mask should remain unchanged or be handled separately.
🌐
pythonpool.com
pythonpool.com › home › opencv › cv2.normalize() in python: scale images and arrays
cv2.normalize() in Python: Scale Images and Arrays
What does cv2.normalize() do?
It transforms an input array to a requested range or norm and writes the result using the selected output and dtype policy.
🌐
pythonpool.com
pythonpool.com › home › opencv › cv2.normalize() in python: scale images and arrays
cv2.normalize() in Python: Scale Images and Arrays
🌐
Python Pool
pythonpool.com › home › opencv › cv2.normalize() in python: scale images and arrays
cv2.normalize() in Python: Scale Images and Arrays
July 13, 2026 - Normalize OpenCV images and arrays by choosing the right range or norm, then validating masks, channels, dtype, and the purpose of the result.
🌐
Jancy Standard Library
vovkos.github.io › doxyrest-showcase › opencv › sphinx_rtd_theme › enum_cv_NormTypes.html
enum cv::NormTypes — OpenCV Documentation
\[norm = \forkthree{\|\texttt{src1}\|_{L_{\infty}} = \max _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) } { \| \texttt{src1} \| _{L_1} = \sum _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_L1}\) } { \| \texttt{src1} \| _{L_2} = \sqrt{\sum_I \texttt{src1}(I)^2} }{if \(\texttt{normType} = \texttt{NORM_L2}\) }\]
🌐
OpenCV
docs.opencv.org › 4.13.0 › d2 › de8 › group__core__array.html
OpenCV: Operations on arrays
This version of cv::norm calculates the absolute difference norm or the relative difference norm of arrays src1 and src2.
Find elsewhere
🌐
CodeSpeedy
codespeedy.com › home › normalizing an image in opencv python
Normalize an Image in OpenCV Python - CodeSpeedy
March 16, 2020 - We can also use cv.NORM_INF, cv.NORM_L1 or cv.NORM_L2 in place of cv.NORM_MINMAX.
🌐
OpenCV
forum.opencv.org › python
How do i normalize an image better? - Python - OpenCV
February 15, 2021 - Hi, Im using a python script to recieve images from a depth camera and when i started reading in the values of each pixel i had to normalize it to actually display it with imshow() So i used this command to normalize my image: cv2.normalize(depth_array, depth_array, 0, 1, cv2.NORM_MINMAX) depth_array is a 2D numpy array that contains the values for each pixel.
🌐
EDUCBA
educba.com › home › software development › software development tutorials › programming languages tutorial › opencv normalize
OpenCV Normalize | Working of normalize() function in OpenCV
April 19, 2023 - The process in which we modify ... image and in order to perform image normalization, we make use of a function called normalize() function in OpenCV which returns the normalized image as the output based on the normalization ...
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Delft Stack
delftstack.com › home › howto › python › opencv normalize
How to Normalize Images in Python OpenCV | Delft Stack
March 11, 2025 - By normalizing images, we can ensure that the intensity values are consistent, which can lead to better performance in image analysis tasks. OpenCV provides a straightforward way to normalize images using the normalize() function, which can ...
🌐
Finxter
blog.finxter.com › home › learn python blog › 5 best ways to normalize an image in opencv python
5 Best Ways to Normalize an Image in OpenCV Python - Be on the Right Side of Change
February 27, 2024 - It then performs min-max scaling and scales the pixel values to a new range specified by new_min and new_max. This method allows for more control over the normalization process. OpenCV offers a built-in function cv2.normalize for normalization, which can be a quick and easy one-liner solution.
🌐
GitHub
github.com › opencv › opencv › issues › 25928
Slow speed using cv2.norm(img1,img2) with opencv > 4.2.0.34 · Issue #25928 · opencv/opencv
July 17, 2024 - I tested various opencv-python versions (4.10.0.84, 4.8.0.76, 4.7.072 with python 3.8.19 and also tested python 3.10.14 without any improvement. But I need to stay with python 3.8.19 and opencv version >= 4.7 for compatibility reasons with other libs. cv2.norm(img1 - img2) works faster than cv2.norm(img1, img2) on opencv-python v > 4.2.0.34 but is still slower than 4.2.0.34 with cv2.norm(img1, img2)
🌐
GitHub
github.com › JimmyHHua › opencv_tutorials › blob › master › python › code_011 › opencv_011.py
opencv_tutorials/python/code_011/opencv_011.py at master · JimmyHHua/opencv_tutorials
# scale and shift by NORM_L1 · dst = np.zeros(gray.shape, dtype=np.float32) cv.normalize(gray, dst=dst, alpha=1.0, beta=0, norm_type=cv.NORM_L1) print(dst) cv.imshow("NORM_L1", np.uint8(dst*10000000)) · # scale and shift by NORM_L2 · dst = np.zeros(gray.shape, dtype=np.float32) cv.normalize(gray, dst=dst, alpha=1.0, beta=0, norm_type=cv.NORM_L2) print(dst) cv.imshow("NORM_L2", np.uint8(dst*10000)) ·
Author: JimmyHHua
Top answer
1 of 3
2

Note that, sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) ) is the same as saying sqrt( (a - b).x * (a - b).x + (a - b).y * (a - b).y ), so you can call cv::norm(a - b).

However, according to this (albeit old) link, performance is poor for single point pairs.

I just ran the test code on my machine. It generates 15,000 points and calculates the distance from each to the remaining points.

a : [0, 0] - b : [2.14748e+09, 2.14748e+09]

euclideanDist : 3.037e+09
distanceBtwPoints : 3.037e+09
cv::norm : 3.037e+09

max_distance euclideanDist : 3.02456e+09 time passed :0.165179
max_distance distanceBtwPoints : 3.02456e+09 time passed :0.259471
max_distance cv::norm : 3.02456e+09 time passed :0.26728

Surprising. The fastest code is

float euclideanDist(cv::Point2f& a, cv::Point2f& b)
{
    cv::Point2f diff = a - b;
    return cv::sqrt(diff.x*diff.x + diff.y*diff.y);
}

Using cv::norm(a - b) and the code below are nearly equal:

static double distanceBtwPoints(const cv::Point2f &a, const cv::Point2f &b)
{
    double xDiff = a.x - b.x;
    double yDiff = a.y - b.y;

    return std::sqrt((xDiff * xDiff) + (yDiff * yDiff));
}

But that's evidently because of the casts to double. If left as float, distanceBtwPoints is as fast as eucledianDist.

2 of 3
1

As you can read in the doc, the norm() set of functions all operate on the generic InputArray datatype. So, from here, you can see that this can be either a cv::Mat or std::vector but certainly not cv::Point2f.

After checking in the sources (of 3.0, but I doubt it was different in 2.4 series), I see that that function has 9 overloads, but the only ones with cv::Point<> only have one argument.

So you will need to to convert your points to cv::Mat. This can be done easily, as there is a constructor for cv::Mat that takes a point as argument. So just do:

std::cout << cv::norm( cv::Mat(a), cv::Mat(b) ) << std::endl;

But as a side comment, I am not sure that this is the best solution: it implies additional memory allocation, and it is probably faster to compute the distance directly (i.e.: sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) ). It seems harsh, but you can rely on the compiler to optimize that.

Top answer
1 of 3
84

If you want to change the range to [0, 1], make sure the output data type is float.

image = cv2.imread("lenacolor512.tiff", cv2.IMREAD_COLOR)  # uint8 image
norm_image = cv2.normalize(image, None, alpha=0, beta=1, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_32F)
2 of 3
25

The other answers normalize an image based on the entire image. But if your image has a predominant color (such as black), it will mask out the features that you're trying to enhance since it will not be as pronounced. To get around this limitation, we can normalize the image based on a subsection region of interest (ROI). Essentially we will normalize based on the section of the image that we want to enhance instead of equally treating each pixel with the same weight. Take for instance this earth image:

Input image -> Normalization based on entire image

If we want to enhance the clouds by normalizing based on the entire image, the result will not be very sharp and will be over saturated due to the black background. The features to enhance are lost. So to obtain a better result we can crop a ROI, normalize based on the ROI, and then apply the normalization back onto the original image. Say we crop the ROI highlighted in green:

This gives us this ROI

The idea is to calculate the mean and standard deviation of the ROI and then clip the frame based on the lower and upper range. In addition, we could use an offset to dynamically adjust the clip intensity. From here we normalize the original image to this new range. Here's the result:

Before -> After

Code

import cv2
import numpy as np

# Load image as grayscale and crop ROI
image = cv2.imread('1.png', 0)
x, y, w, h = 364, 633, 791, 273
ROI = image[y:y+h, x:x+w]

# Calculate mean and STD
mean, STD  = cv2.meanStdDev(ROI)

# Clip frame to lower and upper STD
offset = 0.2
clipped = np.clip(image, mean - offset*STD, mean + offset*STD).astype(np.uint8)

# Normalize to range
result = cv2.normalize(clipped, clipped, 0, 255, norm_type=cv2.NORM_MINMAX)

cv2.imshow('image', image)
cv2.imshow('ROI', ROI)
cv2.imshow('result', result)
cv2.waitKey()

The difference between normalizing based on the entire image vs a specific section of the ROI can be visualized by applying a heatmap to the result. Notice the difference on how the clouds are defined.

Input image -> heatmap

Normalized on entire image -> heatmap

Normalized on ROI -> heatmap

Heatmap code

import matplotlib.pyplot as plt
import numpy as np
import cv2

image = cv2.imread('result.png', 0)
colormap = plt.get_cmap('inferno')
heatmap = (colormap(image) * 2**16).astype(np.uint16)[:,:,:3]
heatmap = cv2.cvtColor(heatmap, cv2.COLOR_RGB2BGR)

cv2.imshow('image', image)
cv2.imshow('heatmap', heatmap)
cv2.waitKey()

Note: The ROI bounding box coordinates were obtained using how to get ROI Bounding Box Coordinates without Guess & Check and heatmap code was from how to convert a grayscale image to heatmap image with Python OpenCV

🌐
OpenCV Q&A Forum
answers.opencv.org › question › 92716 › finding-norm-l2-python
finding norm L2 python - OpenCV Q&A Forum
April 14, 2016 - opencv2.4.9 · image-processing · asked 2016-04-14 04:18:48 -0600 · akki 6 ●1 ●3 · How to find cv2 norm L2 in python i am able to do this: cv2.norm(img1, img2) but I am not sure which norm is this · edit retag flag offensive close merge delete · add a comment ·
🌐
GitHub
github.com › opencv › opencv › issues › 25521
python cv2.norm() on any images hangs - deadlock? · Issue #25521 · opencv/opencv
May 1, 2024 - OpenCV python version: 4.5.4+dfsg-9ubuntu4 (system) / 4.9.0.80 (pip) Operating System / Platform: Ubuntu 22.04.4 Python version: 3.10.12 · Running cv2.norm(img1, img2) on two images hangs indefinitely.
🌐
GitHub
github.com › opencv › opencv › issues › 11426
norm with NORM_HAMMING returns strange results · Issue #11426 · opencv/opencv
April 29, 2018 - System information (version) OpenCV => 3.4.0 Operating System / Platform => Windows 10 64 bit Compiler => Visual Studio 2015 Detailed description when using cv2.norm in python using NORM_HAMMING, the results are strange. For instance the...
Author: opencv