Automatic color correction with OpenCV and Python Last Updated : 23 Jul, 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 R rahulmeen0vvz Follow Improve Article Tags : Computer Vision AI-ML-DS Image-Processing Python-OpenCV Explore Introduction to Computer VisionComputer Vision - Introduction 4 min read A Quick Overview to Computer Vision 3 min read Applications of Computer Vision 6 min read Fundamentals of Image Formation 7 min read Satellite Image Processing 2 min read Image Formats 5 min read Image Processing & TransformationDigital Image Processing Basics 7 min read Difference Between RGB, CMYK, HSV, and YIQ Color Models 3 min read Image Enhancement Techniques using OpenCV - Python 15+ min read Image Transformations using OpenCV in Python 5 min read How to find the Fourier Transform of an image using OpenCV Python? 5 min read Python | Intensity Transformation Operations on Images 5 min read Histogram Equalization in Digital Image Processing 5 min read Python - Color Inversion using Pillow 4 min read Image Sharpening using Laplacian, High Boost Filtering in MATLAB 3 min read Wand sharpen() function - Python 2 min read Python OpenCV - Smoothing and Blurring 7 min read Python PIL | GaussianBlur() method 1 min read Apply a Gauss filter to an image with Python 2 min read Spatial Filtering and its Types 3 min read Python PIL | MedianFilter() and ModeFilter() method 1 min read Python | Bilateral Filtering 2 min read Python OpenCV - Morphological Operations 5 min read Erosion and Dilation of images using OpenCV in Python 3 min read Introduction to Resampling methods 8 min read Python | Image Registration using OpenCV 3 min read Feature Extraction and DescriptionFeature Extraction Techniques - NLP 10 min read SIFT Interest Point Detector Using Python - OpenCV 4 min read Feature Matching using Brute Force in OpenCV 13 min read Feature detection and matching with OpenCV-Python 5 min read Feature matching using ORB algorithm in Python-OpenCV 3 min read Mahotas - Speeded-Up Robust Features 2 min read Create Local Binary Pattern of an image using OpenCV-Python 5 min read Deep Learning for Computer VisionImage Classification using CNN 5 min read What is Transfer Learning? 8 min read Top 5 PreTrained Models in Natural Language Processing (NLP) 7 min read ML | Introduction to Strided Convolutions 2 min read Dilated Convolution 5 min read Continuous Kernel Convolution 6 min read CNN | Introduction to Pooling Layer 5 min read CNN | Introduction to Padding 5 min read What is the difference between 'SAME' and 'VALID' padding in tf.nn.max_pool of tensorflow? 14 min read Convolutional Neural Network (CNN) Architectures 11 min read Deep Transfer Learning - Introduction 8 min read Introduction to Residual Networks 4 min read Residual Networks (ResNet) - Deep Learning 9 min read ML | Inception Network V1 4 min read Understanding GoogLeNet Model - CNN Architecture 3 min read Image Recognition with Mobilenet 4 min read VGG-16 | CNN model 6 min read Autoencoders in Machine Learning 8 min read How Autoencoders works ? 6 min read Difference Between Encoder and Decoder 9 min read Implementing an Autoencoder in PyTorch 4 min read Generative Adversarial Network (GAN) 12 min read Deep Convolutional GAN with Keras 9 min read StyleGAN - Style Generative Adversarial Networks 5 min read Object Detection and RecognitionDetect an object with OpenCV-Python 4 min read Haar Cascades for Object Detection - Python 3 min read R-CNN - Region-Based Convolutional Neural Networks 8 min read YOLO v2 - Object Detection 7 min read Face recognition using Artificial Intelligence 15+ min read Deep Face Recognition 8 min read ML | Face Recognition Using Eigenfaces (PCA Algorithm) 4 min read Emojify using Face Recognition with Machine Learning 7 min read Object Detection with Detection Transformer (DETR) by Facebook 7 min read Image SegmentationImage Segmentation Using TensorFlow 5 min read Thresholding-Based Image Segmentation 7 min read Region and Edge Based Segmentation 4 min read Image Segmentation with Watershed Algorithm - OpenCV Python 9 min read Mask R-CNN | ML 9 min read 3D ReconstructionPython OpenCV - Depth map from Stereo Images 2 min read Top 7 Modern-Day Applications of Augmented Reality (AR) 10 min read Virtual Reality, Augmented Reality, and Mixed Reality 3 min read Camera Calibration with Python - OpenCV 4 min read Python OpenCV - Pose Estimation 7 min read 40+ Top Computer Vision Projects [2025 Updated] 4 min read Like