Skip to content

Commit 054048e

Browse files
committed
Modified Bitwise Code
Signed-off-by: Mukesh Sai Madepalli <[email protected]>
1 parent 60de909 commit 054048e

File tree

1 file changed

+41
-24
lines changed

1 file changed

+41
-24
lines changed
Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,43 @@
11
import cv2
2+
import argparse
23

3-
# getting the path for first image
4-
src1 = input("Enter the path of the image 1\n")
5-
src1 = cv2.imread(src1)
6-
# src1 = cv2.resize(src1,(540,540)) #resizing the image
7-
# getting the path for second image
8-
src2 = input("Enter the path of the image 2\n")
9-
src2 = cv2.imread(src2)
10-
11-
# Resizing the image so that both images have same dimensions
12-
src2 = cv2.resize(src2, src1.shape[1::-1])
13-
# Applying Bitwise AND operation
14-
andop = cv2.bitwise_and(src1, src2, mask=None)
15-
andop = cv2.resize(andop, (640, 640))
16-
cv2.imshow('Bitwise AND', andop)
17-
18-
orop = cv2.bitwise_or(src1, src2, mask=None) # Applying Bitwise OR operation
19-
orop = cv2.resize(orop, (640, 640))
20-
cv2.imshow('Bitwise OR', orop)
21-
22-
xorop = cv2.bitwise_xor(src1, src2, mask=None) # Applying Bitwise OR operation
23-
xorop = cv2.resize(xorop, (640, 640))
24-
cv2.imshow('Bitwise XOR', xorop)
25-
cv2.waitKey(0)
26-
cv2.destroyAllWindows()
4+
def perform_bitwise_operations(image1_path, image2_path):
5+
src1 = cv2.imread(image1_path)
6+
src2 = cv2.imread(image2_path)
7+
8+
# Resizing the images to have the same dimensions
9+
src2 = cv2.resize(src2, src1.shape[1::-1])
10+
11+
# Performing bitwise AND operation
12+
and_op = cv2.bitwise_and(src1, src2, mask=None)
13+
14+
# Performing bitwise OR operation
15+
or_op = cv2.bitwise_or(src1, src2, mask=None)
16+
17+
# Performing bitwise XOR operation
18+
xor_op = cv2.bitwise_xor(src1, src2, mask=None)
19+
20+
return and_op, or_op, xor_op
21+
22+
def save_images(image1, image2, image3):
23+
cv2.imshow('Bitwise AND', image1)
24+
cv2.imshow('Bitwise OR', image2)
25+
cv2.imshow('Bitwise XOR', image3)
26+
cv2.waitKey(0)
27+
cv2.destroyAllWindows()
28+
29+
if __name__ == '__main__':
30+
# Creating command-line arguments parser
31+
parser = argparse.ArgumentParser(description='Perform bitwise operations on two images.')
32+
parser.add_argument('image1', type=str, help='Path to the first image file.')
33+
parser.add_argument('image2', type=str, help='Path to the second image file.')
34+
args = parser.parse_args()
35+
36+
image1_path = args.image1
37+
image2_path = args.image2
38+
39+
# Performing bitwise operations
40+
result1, result2, result3 = perform_bitwise_operations(image1_path, image2_path)
41+
42+
# Displaying and saving the resulting images
43+
save_images(result1, result2, result3)

0 commit comments

Comments
 (0)