diff options
author | Sudipto Mallick <smlckz@termux-alpine> | 2024-02-10 12:49:55 +0000 |
---|---|---|
committer | Sudipto Mallick <smlckz@termux-alpine> | 2024-02-10 12:49:55 +0000 |
commit | 4182a108a01df3aa28009716472f0ef291704866 (patch) | |
tree | 8fabeb2d6ddff80b930c02b3d535b5447bbd41dc /opencv/code/a6.py | |
parent | 02884d29e4f5aea71364a203dcaecd53600d8aa4 (diff) | |
download | zadania-main.tar.gz |
Complete DIP assignments main
Diffstat (limited to 'opencv/code/a6.py')
-rw-r--r-- | opencv/code/a6.py | 43 |
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") |