summary refs log tree commit diff stats
path: root/opencv/code/a6.py
diff options
context:
space:
mode:
Diffstat (limited to 'opencv/code/a6.py')
-rw-r--r--opencv/code/a6.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/opencv/code/a6.py b/opencv/code/a6.py
new file mode 100644
index 0000000..a72d103
--- /dev/null
+++ b/opencv/code/a6.py
@@ -0,0 +1,43 @@
+import cv2
+import matplotlib.pyplot as plt
+
+image = cv2.imread("4i.jpg", cv2.IMREAD_GRAYSCALE)
+
+# Perform histogram equalization
+equalized_image = cv2.equalizeHist(image)
+
+# Calculate histograms
+hist_original = cv2.calcHist([image], [0], None, [256], [0, 256])
+hist_equalized = cv2.calcHist([equalized_image], [0], None, [256], [0, 256])
+
+# Plot original and equalized images and their histograms
+plt.figure(figsize=(10, 8))
+
+# Original image and histogram
+plt.subplot(2, 2, 1)
+plt.imshow(image, cmap="gray")
+plt.title("Original Image")
+plt.xticks([])
+plt.yticks([])
+
+plt.subplot(2, 2, 2)
+plt.plot(hist_original, color="black")
+plt.title("Histogram of Original Image")
+plt.xlabel("Pixel Value")
+plt.ylabel("Frequency")
+
+# Equalized image and histogram
+plt.subplot(2, 2, 3)
+plt.imshow(equalized_image, cmap="gray")
+plt.title("Equalized Image")
+plt.xticks([])
+plt.yticks([])
+
+plt.subplot(2, 2, 4)
+plt.plot(hist_equalized, color="black")
+plt.title("Histogram of Equalized Image")
+plt.xlabel("Pixel Value")
+plt.ylabel("Frequency")
+
+plt.tight_layout()
+plt.savefig("6.svg")