You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
2.1 KiB
62 lines
2.1 KiB
2 years ago
|
import cv2
|
||
|
import numpy as np
|
||
|
|
||
|
|
||
|
class logicalAlgorithm:
|
||
|
def __init__(self, img_path1, img_path2):
|
||
|
self.path1 = img_path1
|
||
|
self.path2 = img_path2
|
||
|
|
||
|
def alAnd(self):
|
||
|
x = cv2.imread(self.path1, 1)
|
||
|
y = cv2.imread(self.path2, 1)
|
||
|
rows, cols = x.shape[:2]
|
||
|
y_dst = cv2.resize(y, (cols, rows), interpolation=cv2.INTER_CUBIC)
|
||
|
result = (x & y_dst)
|
||
|
cv2.imwrite("saved Img/And.bmp", result)
|
||
|
|
||
|
def alOr(self):
|
||
|
x = cv2.imread(self.path1, 1)
|
||
|
y = cv2.imread(self.path2, 1)
|
||
|
rows, cols = x.shape[:2]
|
||
|
y_dst = cv2.resize(y, (cols, rows), interpolation=cv2.INTER_CUBIC)
|
||
|
result = (x | y_dst)
|
||
|
cv2.imwrite("saved Img/Or.bmp", result)
|
||
|
|
||
|
def alNegation(self):
|
||
|
x = cv2.imread(self.path1, 1)
|
||
|
result = (~x)
|
||
|
cv2.imwrite("saved Img/Negation.bmp", result)
|
||
|
|
||
|
def alAdd(self):
|
||
|
x = cv2.imread(self.path1, 1)
|
||
|
y = cv2.imread(self.path2, 1)
|
||
|
rows, cols = x.shape[:2]
|
||
|
y_dst = cv2.resize(y, (cols, rows), interpolation=cv2.INTER_CUBIC)
|
||
|
result = cv2.add(x, y_dst)
|
||
|
cv2.imwrite("saved Img/Add.bmp", result)
|
||
|
|
||
|
def alSubtract(self):
|
||
|
x = cv2.imread(self.path1, 1)
|
||
|
y = cv2.imread(self.path2, 1)
|
||
|
rows, cols = x.shape[:2]
|
||
|
y_dst = cv2.resize(y, (cols, rows), interpolation=cv2.INTER_CUBIC)
|
||
|
result = cv2.subtract(x, y_dst)
|
||
|
cv2.imwrite("saved Img/Subtract.bmp", result)
|
||
|
|
||
|
def alMulty(self):
|
||
|
x = cv2.imread(self.path1, 1).astype(np.float64)/255
|
||
|
y = cv2.imread(self.path2, 1).astype(np.float64)/255
|
||
|
rows, cols = x.shape[:2]
|
||
|
y_dst = cv2.resize(y, (cols, rows), interpolation=cv2.INTER_CUBIC)
|
||
|
result = cv2.multiply(x, y_dst) * 255
|
||
|
cv2.imwrite("saved Img/Multiply.bmp", result)
|
||
|
|
||
|
def alDivide(self):
|
||
|
x = cv2.imread(self.path1, 1).astype(np.float64)/255
|
||
|
y = cv2.imread(self.path2, 1).astype(np.float64)/255
|
||
|
rows, cols = x.shape[:2]
|
||
|
y_dst = cv2.resize(y, (cols, rows), interpolation=cv2.INTER_CUBIC)
|
||
|
result = cv2.divide(x, y_dst) * 255
|
||
|
cv2.imwrite("saved Img/Divide.bmp", result)
|