Histogram equalization
Histogram equalization is used to enhance the visibility and the contrast of images. It is performed by varying the image intensities. These procedures are clearly described here.
How to do it…
- Import the necessary packages:
import sys import cv2 import numpy as np
- Load the input image:
in_file = sys.argv[1] image = cv2.imread(in_file)
- Convert the RGB image into grayscale:
image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) cv2.imshow('Input grayscale image', image_gray)
- Regulate the histogram of the grayscale image:
image_gray_histoeq = cv2.equalizeHist(image_gray) cv2.imshow('Histogram equalized - grayscale image', image_gray_histoeq)
- Regulate the histogram of the RGB image:
image_yuv = cv2.cvtColor(image, cv2.COLOR_BGR2YUV) image_yuv[:,:,0] = cv2.equalizeHist(image_yuv[:,:,0]) image_histoeq = cv2.cvtColor(image_yuv, cv2.COLOR_YUV2BGR)
- Display the output image:
cv2.imshow('Input image', image) cv2.imshow('Histogram equalized - color image', image_histoeq) cv2.waitKey...