Automatic color correction with OpenCV and Python Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report Colour correction is an important aspect of image processing and is used to correct any colour imbalances in an image. OpenCV is an open-source library for computer vision and image processing tasks that provides several functions and tools to analyze and manipulate images. In this tutorial, we will explore how to perform automatic colour correction using OpenCV and Python. The following concepts will be covered in this tutorial: Histogram Equalization: This technique is used to enhance the contrast of an image by adjusting the intensity distribution of the image.Colour Space Conversion: Images are usually represented in RGB colour space, but other colour spaces such as HSV and LAB can be used for colour correction.Image Filtering: Different filters can be applied to an image to enhance the colour balance and remove any colour casts. Now, let's look at some examples of how to perform automatic colour correction using OpenCV and Python. Example 1: Histogram Equalization STEPS: Load the image using cv2.imread function.Convert the image to grayscale using cv2.cvtColor function with COLOR_BGR2GRAY parameter.Apply histogram equalization using cv2.equalizeHist function.Display the equalized image using cv2.imshow function.Wait for a keyboard event using cv2.waitKey function. Python3 import cv2 # Load the image img = cv2.imread('image.jpg') # Convert the image to grayscale gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # Apply histogram equalization equalized = cv2.equalizeHist(gray) # Display the result cv2.imshow('Equalized Image', equalized) cv2.waitKey(0) Output: histogram equalized image Example 2: Colour Space Conversion STEPS: Import necessary libraries including OpenCV.Load the input image using cv2.imread function.Convert the input image from BGR color space to LAB colour space using cv2.cvtColor function.Split the LAB image into three separate channels using cv2.split function.Create a CLAHE object using cv2.createCLAHE function.Apply CLAHE to the L channel using the apply method of the class object.Merge the LAB channels back together using cv2.merge function.Convert the corrected LAB image from LAB colour space to BGR colour space using cv2.cvtColor function.Display the output image using cv2.imshow function and wait for a key press using cv2.waitKey function. Python3 import cv2 # Load the image img = cv2.imread('image.jpg') # Convert the image to LAB color space lab = cv2.cvtColor(img, cv2.COLOR_BGR2LAB) # Split the LAB image into separate channels l, a, b = cv2.split(lab) # Apply CLAHE to the L channel clahe = cv2.createCLAHE(clipLimit=3.0, tileGridSize=(8,8)) l = clahe.apply(l) # Merge the LAB channels back together lab = cv2.merge((l,a,b)) # Convert the LAB image back to RGB color space output = cv2.cvtColor(lab, cv2.COLOR_LAB2BGR) # Display the result cv2.imshow('Color space conversion ', output) cv2.waitKey(0) Output:color space conversion Example 3: Image Filtering STEPS: Import the OpenCV library.Load the input image using the cv2.imread function.Apply a bilateral filter to the image using the cv2.bilateralFilter function with the parameters 15, 75, and 75.Display the output image using the cv2.imshow function and wait for a key press using the cv2.waitKey function. Python3 import cv2 # Load the image img = cv2.imread('image.jpg') # Apply a bilateral filter to the image filtered = cv2.bilateralFilter(img, 15, 75, 75) # Display the result cv2.imshow('Color Corrected Image', filtered) cv2.waitKey(0) Output: colour corrected image Comment More infoAdvertise with us Next Article Automatic color correction with OpenCV and Python R rahulmeen0vvz Follow Improve Article Tags : Computer Vision AI-ML-DS Image-Processing Python-OpenCV Similar Reads Feature detection and matching with OpenCV-Python In this article, we are going to see about feature detection in computer vision with OpenCV in Python. Feature detection is the process of checking the important features of the image in this case features of the image can be edges, corners, ridges, and blobs in the images. In OpenCV, there are a nu 5 min read Convert BGR and RGB with Python - OpenCV Prerequisites: OpenCV 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 2 min read Camera Calibration with Python - OpenCV Prerequisites: OpenCV A camera is an integral part of several domains like robotics, space exploration, etc camera is playing a major role. It helps to capture each and every moment and helpful for many analyses. In order to use the camera as a visual sensor, we should know the parameters of the cam 4 min read White and black dot detection using OpenCV | Python Image processing using Python is one of the hottest topics in today's world. But image processing is a bit complex and beginners get bored in their first approach. So in this article, we have a very basic image processing python program to count black dots in white surface and white dots in the blac 4 min read Python OpenCV - BFMatcher() Function In this article, we will be going to implement Python OpenCV - BFMatcher() Function. Prerequisites: OpenCV, matplotlib What is BFMatcher() Function? BFMatcher() function is used in feature matching and used to match features in one image with other image. BFMatcher refers to a Brute-force matcher th 3 min read Find and Draw Contours using OpenCV | Python Contours are edges or outline of a objects in a image and is used in image processing to identify shapes, detect objects or measure their size. We use OpenCV's findContours() function that works best for binary images.There are three important arguments of this function:Source Image: This is the ima 3 min read Python OpenCV | cv2.cvtColor() method OpenCV-Python is a library of Python bindings designed to solve computer vision problems. cv2.cvtColor() method is used to convert an image from one color space to another. There are more than 150 color-space conversion methods available in OpenCV. We will use some of color space conversion codes be 4 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 Python OpenCV - Smoothing and Blurring In this article, we are going to learn about smoothing and blurring with python-OpenCV. When we are dealing with images at some points the images will be crisper and sharper which we need to smoothen or blur to get a clean image, or sometimes the image will be with a really bad edge which also we ne 7 min read Histogram matching with OpenCV, scikit-image, and Python Histogram matching is used for normalizing the representation of images, it can be used for feature matching, especially when the pictures are from diverse sources or under varied conditions (depending on the light, etc). each image has a number of channels, each channel is matched individually. His 3 min read Like