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/a10.py | |
parent | 02884d29e4f5aea71364a203dcaecd53600d8aa4 (diff) | |
download | zadania-main.tar.gz |
Complete DIP assignments main
Diffstat (limited to 'opencv/code/a10.py')
-rw-r--r-- | opencv/code/a10.py | 39 |
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") |