-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhistogram_equalization.py
More file actions
51 lines (37 loc) · 1.63 KB
/
Copy pathhistogram_equalization.py
File metadata and controls
51 lines (37 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#description: https://dl.ebooksworld.ir/motoman/Digital.Image.Processing.3rd.Edition.www.EBooksWorld.ir.pdf pdf sayfa:145 kitap sayfa:122
#reference code for histogram_equalization : https://docs.opencv.org/4.x/d5/daf/tutorial_py_histogram_equalization.html
import cv2
import numpy as np
import matplotlib.pyplot as plt
image_path = 'images/ottocat.PNG'
#reference code for histogram_equalization: https://docs.opencv.org/4.x/d5/daf/tutorial_py_histogram_equalization.html
def histogram_equalization_gray():
# Read the image in grayscale
img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
# Apply histogram equalization
equalized_img = cv2.equalizeHist(img)
plt.subplot(1, 2, 1)
plt.imshow(img, cmap='gray')
plt.title('Original Image')
plt.subplot(1, 2, 2)
plt.imshow(equalized_img, cmap='gray')
plt.title('Equalized Image')
plt.show()
#reference code for histogram_equalization_colorful: https://docs.opencv.org/4.x/d5/daf/tutorial_py_histogram_equalization.html
def histogram_equalization_colorful():
img = cv2.imread(image_path)
lab_img = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
l, a, b = cv2.split(lab_img)
equ = cv2.equalizeHist(l)
updated_lab_img = cv2.merge((equ, a, b))
hist_eq_img = cv2.cvtColor(updated_lab_img, cv2.COLOR_LAB2BGR)
plt.subplot(1, 2, 1)
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
plt.title('Original Image')
plt.subplot(1, 2, 2)
plt.imshow(cv2.cvtColor(hist_eq_img, cv2.COLOR_BGR2RGB))
plt.title('Histogram Equalized Image')
plt.show()
if __name__ == '__main__':
histogram_equalization_gray()
histogram_equalization_colorful()