summary refs log tree commit diff stats
path: root/opencv/code/a12.py
diff options
context:
space:
mode:
authorSudipto Mallick <smlckz@termux-alpine>2024-02-10 12:49:55 +0000
committerSudipto Mallick <smlckz@termux-alpine>2024-02-10 12:49:55 +0000
commit4182a108a01df3aa28009716472f0ef291704866 (patch)
tree8fabeb2d6ddff80b930c02b3d535b5447bbd41dc /opencv/code/a12.py
parent02884d29e4f5aea71364a203dcaecd53600d8aa4 (diff)
downloadzadania-main.tar.gz
Complete DIP assignments main
Diffstat (limited to 'opencv/code/a12.py')
-rw-r--r--opencv/code/a12.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/opencv/code/a12.py b/opencv/code/a12.py
new file mode 100644
index 0000000..9cf8858
--- /dev/null
+++ b/opencv/code/a12.py
@@ -0,0 +1,26 @@
+import cv2
+import numpy as np
+import matplotlib.pyplot as plt
+
+input_image = cv2.imread("4i.jpg", cv2.IMREAD_GRAYSCALE)
+
+kernel_size = 3
+
+filters = [
+    (input_image, "Original Image"),
+    (cv2.blur(input_image, (kernel_size, kernel_size)), "Mean Filtered"),
+    (cv2.GaussianBlur(input_image, (kernel_size, kernel_size), 0), "Weighted Average Filtered"),
+    (cv2.medianBlur(input_image, kernel_size), "Median Filtered"),
+    (cv2.dilate(input_image, np.ones((kernel_size, kernel_size), np.uint8)), "Max Filtered"),
+    (cv2.erode(input_image, np.ones((kernel_size, kernel_size), np.uint8)), "Min Filtered"),
+]
+
+plt.figure(figsize=(12, 10))
+
+for i, (filtered_image, title) in enumerate(filters, start=1):
+    plt.subplot(3, 3, i)
+    plt.imshow(filtered_image, cmap="gray")
+    plt.title(title)
+    plt.axis("off")
+
+plt.savefig("12.svg")