summary refs log tree commit diff stats
path: root/opencv/code/a10.py
diff options
context:
space:
mode:
Diffstat (limited to 'opencv/code/a10.py')
-rw-r--r--opencv/code/a10.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/opencv/code/a10.py b/opencv/code/a10.py
new file mode 100644
index 0000000..f54a024
--- /dev/null
+++ b/opencv/code/a10.py
@@ -0,0 +1,39 @@
+import cv2
+import numpy as np
+import matplotlib.pyplot as plt
+
+images = [cv2.imread(path, cv2.IMREAD_GRAYSCALE) for path in ["9i1.jpg", "9i2.jpg"]]
+assert all(
+    image.shape == images[0].shape for image in images
+), "Input images must have the same dimensions"
+
+operations = [
+    ("Addition", lambda x, y: cv2.add(x, y)),
+    ("Subtraction", lambda x, y: cv2.subtract(x, y)),
+    ("Multiplication", lambda x, y: cv2.multiply(x, y)),
+    (
+        "Division",
+        lambda x, y: cv2.divide(
+            x.astype(np.float32), np.where(y == 0, 1, y).astype(np.float32)
+        ),
+    ),
+]
+
+plt.figure(figsize=(8, 6))
+
+for i, image in enumerate(images, start=1):
+    plt.subplot(3, 2, i)
+    plt.imshow(image, cmap="gray")
+    plt.title(f"Image {i}")
+    plt.axis("off")
+
+for i, (operation_name, operation_function) in enumerate(
+    operations, start=len(images) + 1
+):
+    result_image = operation_function(*images)
+    plt.subplot(3, 2, i)
+    plt.imshow(result_image, cmap="gray")
+    plt.title(operation_name)
+    plt.axis("off")
+
+plt.savefig("10.svg")