Normalize an Image in OpenCV Python Last Updated : 07 May, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report Normalization involves adjusting the range of pixel intensity values in an image. Normalization can be beneficial for various purposes, such as improving the contrast or making the image more suitable for processing by other algorithms. In this article, we will explore how to normalize images using OpenCV in Python. What is Image Normalization?Image normalization is the process of adjusting the pixel intensity values of an image to a predefined range. This range is typically between 0 and 255 for images with 8-bit depth, where 0 represents black and 255 represents white. 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. This function allows us to specify the desired range for the pixel intensity values. Normalize an Image in OpenCV PythonBelow are some of the examples by which we can understand about normalizing images in OpenCV Python: Example 1: Normalizing Grayscale ImageIn this example, a grayscale image is read and normalized to enhance contrast using the NORM_MINMAX normalization method. Both the original and normalized images are displayed using OpenCV imshow() function. Python import cv2 # Read grayscale image image = cv2.imread('kl.png', cv2.IMREAD_GRAYSCALE) # Normalize image normalized_image = cv2.normalize( image, None, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX) # Display original and normalized images cv2.imshow('Original Image', image) cv2.imshow('Normalized Image', normalized_image) cv2.waitKey(0) cv2.destroyAllWindows() Output: Example 2: Normalizing Color ImageIn this example, a color image is converted to grayscale, then normalized to enhance contrast. The normalized grayscale image is converted back to color and displayed alongside the original image using OpenCV. Python import cv2 # Read color image image = cv2.imread('kl.png') # Convert image to grayscale gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # Normalize grayscale image normalized_gray_image = cv2.normalize( gray_image, None, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX) # Convert normalized grayscale image back to color normalized_color_image = cv2.cvtColor( normalized_gray_image, cv2.COLOR_GRAY2BGR) # Display original and normalized images cv2.imshow('Original Image', image) cv2.imshow('Normalized Image', normalized_color_image) cv2.waitKey(0) cv2.destroyAllWindows() Output: Comment More infoAdvertise with us Next Article Image Processing in Python R rs736tjxi Follow Improve Article Tags : Computer Vision OpenCV Similar Reads Reading an image in OpenCV using Python Prerequisite: Basics of OpenCVIn this article, we'll try to open an image by using OpenCV (Open Source Computer Vision) library.  Following types of files are supported in OpenCV library:Windows bitmaps - *.bmp, *.dibJPEG files - *.jpeg, *.jpgPortable Network Graphics - *.png WebP - *.webp Sun raste 6 min read Convert OpenCV image to PIL image in Python OpenCV is a huge open-source library for computer vision, machine learning, and image processing. OpenCV supports a wide variety of programming languages like Python, C++, Java, etc. It can process images and videos to identify objects, faces, or even the handwriting of a human. When it is integrate 3 min read How to Display an OpenCV image in Python with Matplotlib? The OpenCV module is an open-source computer vision and machine learning software library. It is a huge open-source library for computer vision, machine learning, and image processing. OpenCV supports a wide variety of programming languages like Python, C++, Java, etc. It can process images and vide 2 min read Image Processing in Python Image processing involves analyzing and modifying digital images using computer algorithms. It is widely used in fields like computer vision, medical imaging, security and artificial intelligence. Python with its vast libraries simplifies image processing, making it a valuable tool for researchers a 7 min read Draw Multiple Rectangles in Image using Python-Opencv In this article, we are going to see how to draw multiple rectangles in an image using Python and OpenCV. Function used:imread(): In the OpenCV, the cv2.imread() function is used to read an image in Python. Syntax: cv2.imread(path_of_image, flag) rectangle(): In the OpenCV, the cv2.rectangle functio 2 min read Python Image Processing Libraries Python offers powerful libraries such as OpenCV, Pillow, scikit-image, and SimpleITK for image processing. They offer diverse functionalities including filtering, segmentation, and feature extraction, serving as foundational tools for a range of computer vision tasks.Python Image Processing Librarie 11 min read Like