<jupyter_start><jupyter_text><jupyter_code>import cv2
from google.colab.patches import cv2_imshow
import matplotlib.pyplot as plt


image = cv2.imread('/content/Lenna.png', cv2.IMREAD_GRAYSCALE)
image = cv2.resize(image, (256, 256))
print('Original Image:')
cv2_imshow(image)
print("Histogram:")
plt.hist(image.ravel(), 256, [0,256])
plt.show()
import numpy as np 


# cumulative histogram 
hist = cv2.calcHist([image],[0],None,[256],[0,256])
cumulative_hist = np.zeros((256, ))
for i in range(len(hist)):
  cumulative_hist[i] = np.sum(hist[:i])
print("Cumulative Values: ")
plt.plot(cumulative_hist)
plt.show()
mxn = image.shape[0] * image.shape[1]
g = 256
n_p = int(mxn/g)

Equalized_image = np.zeros_like(image)
for row in range(image.shape[0]):
  for column in range(image.shape[1]):
    j = image[row, column] 
    CHj = cumulative_hist[j]
    i = max(0, (round(CHj/n_p)-1) )
    Equalized_image[row, column] = i

print('Equalized Image:')
cv2_imshow(Equalized_image)
print("Histogram:")
plt.hist(Equalized_image.ravel(), 256, [0,256])
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1702127659574468, 'fraction_numerical': 0.04440333024976873, 'mean_word_length': 5.935897435897436, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '413794', 'license': 'MIT', 'n_tokens_mistral': 477, 'n_tokens_neox': 427, 'n_words': 81, 'path': 'ImageEnhancement/Histogram_Equalization.ipynb', 'repo_name': 'alirezash97/Computer-Vision', 'size': '1081'}