summary refs log tree commit diff stats
path: root/opencv/code/a12.py
diff options
context:
space:
mode:
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")