Color image histogram equalization python opencv implementation

If an image having all possible gray level, the gray and uniform distribution of pixel values, the pair having a high contrast image is changeable and gray tones. Rich gradation and larger coverage. This image has a richer color in appearance, not too dark or too bright.
The main purpose of histogram equalization is to uniformly gray level of the original image is mapped to the entire range of gray scale, gray scale image to obtain a uniform distribution

Both methods histogram equalization:
a first equalization implemented within the original range. Implemented within the scope of the original histogram equalization is multiplied by the maximum gray level gradation current with the current cumulative probability, a new gray level obtained

The second equalization achieved in a wider range of
implementing the histogram equalization in a wider range, multiplied by the maximum gray level within the broader range of gray levels with the current cumulative probability results in a new gray scale, and as a result of equalization

import cv2
import numpy as np
import matplotlib.pyplot as plt

img = cv2.imread('../data/1.jpg')

img0 = cv2.equalizeHist(img[:, :, 0])  # 各个通道分别均衡化
img1 = cv2.equalizeHist(img[:, :, 1])
img2 = cv2.equalizeHist(img[:, :, 2])

img_e = cv2.merge([img0, img1, img2])

plt.figure('original')
plt.hist(img.ravel(), 256)
plt.figure('after')
plt.hist(img_e.ravel(), 256)
plt.show()

cv2.imshow('img', img)
cv2.imshow('e_img', img_e)
cv2.waitKey()
cv2.destroyAllWindows()
cv2.imwrite('../data/equ.jpg', img_e)

Published 45 original articles · won praise 24 · views 3417

Guess you like

Origin blog.csdn.net/my_name_is_learn/article/details/104036457