-
Notifications
You must be signed in to change notification settings - Fork 0
/
Set_Operations.py
56 lines (40 loc) · 1.82 KB
/
Set_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
56
import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt
def union_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.bitwise_or(image_1, image_2)
return result_add_images
def intersection_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.bitwise_and(image_1, image_2)
return result_subtract_images
def negation_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.bitwise_not(image_1, image_2)
return result_multiplied_images
def inverter_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.bitwise_xor(image_1, image_2)
return result_divided_images
result = negation_images()
result_rgb = cv.cvtColor(result, cv.COLOR_BGR2RGB)
plt.imshow(result_rgb)
plt.axis('off')
plt.show()