-
Notifications
You must be signed in to change notification settings - Fork 0
/
Arithmetic_Operations.py
55 lines (40 loc) · 1.78 KB
/
Arithmetic_Operations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt
def add_images():
image_1 = cv.imread("image_1.jpg", cv.IMREAD_COLOR)
image_2 = cv.imread("image_2.jpg", cv.IMREAD_COLOR)
if image_1.shape != image_2.shape:
print("Images are not the same size, resizing...")
image_2 = cv.resize(image_2, (image_1.shape[1], image_1.shape[0]))
result_add_images = cv.add(image_1, image_2)
return result_add_images
def sub_images():
image_1 = cv.imread("image_1.jpg", cv.IMREAD_COLOR)
image_2 = cv.imread("image_2.jpg", cv.IMREAD_COLOR)
if image_1.shape != image_2.shape:
print("Images are not the same size, resizing...")
image_2 = cv.resize(image_2, (image_1.shape[1], image_1.shape[0]))
result_subtract_images = cv.subtract(image_1, image_2)
return result_subtract_images
def mul_images():
image_1 = cv.imread("image_1.jpg", cv.IMREAD_COLOR)
image_2 = cv.imread("image_2.jpg", cv.IMREAD_COLOR)
if image_1.shape != image_2.shape:
print("Images are not the same size, resizing...")
image_2 = cv.resize(image_2, (image_1.shape[1], image_1.shape[0]))
result_multiplied_images = cv.multiply(image_1, image_2)
return result_multiplied_images
def div_images():
image_1 = cv.imread("image_1.jpg", cv.IMREAD_COLOR)
image_2 = cv.imread("image_2.jpg", cv.IMREAD_COLOR)
if image_1.shape != image_2.shape:
print("Images are not the same size, resizing...")
image_2 = cv.resize(image_2, (image_1.shape[1], image_1.shape[0]))
result_divided_images = cv.divide(image_1, image_2)
return result_divided_images
result = mul_images()
result_rgb = cv.cvtColor(result, cv.COLOR_BGR2RGB)
plt.imshow(result_rgb)
plt.axis('off')
plt.show()