Change language

Aligning histograms in OpenCV

| |

Histogram alignment — it is a method of processing the contrast of an image using an image histogram.

This method usually increases the overall contrast of many images, especially when the usable image data is represented by similar contrast values. By this setting, intensities can be better distributed over the histogram. This allows areas of lower local contrast to receive higher contrast. Histogram flattening does this by effectively distributing the most frequent intensity values. This method is useful for background and foreground images that are bright or dark.

OpenCV has a function for this, cv2.equalizeHist () . Its input is just a grayscale image, and the output is — histogram aligned image.

Input image:

Below is the Python3 code that implements histogram alignment:

# Opencv import

import cv2

# Numpy import

import numpy as np

# read image using imread

img = cv2.imread ( ’ F: do_nawab .png’ , 0 )

# create histogram alignment
# images using cv2.equalizeHist ()

equ = cv2.equalizeHist (img)

# stacking images side by side

res = np.hstack ((img, equ))

# show input images versus display

cv2.imshow ( ’image’ , res)


cv2.waitKey ( 0 )

cv2.destroyAllWindows () 




Learn programming in R: courses


Best Python online courses for 2022


Best laptop for Fortnite


Best laptop for Excel


Best laptop for Solidworks


Best laptop for Roblox


Best computer for crypto mining


Best laptop for Sims 4


Latest questions


psycopg2: insert multiple rows with one query

12 answers


How to convert Nonetype to int or string?

12 answers


How to specify multiple return types using type-hints

12 answers


Javascript Error: IPython is not defined in JupyterLab

12 answers



Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method