Skip to content

Commit 5bb2787

Browse files
committed
Bitwise Operations
1 parent 5ce3fbc commit 5bb2787

File tree

3 files changed

+173
-1
lines changed

3 files changed

+173
-1
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Bitwise Operations"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": 4,
13+
"metadata": {},
14+
"outputs": [],
15+
"source": [
16+
"import numpy as np\n",
17+
"import cv2"
18+
]
19+
},
20+
{
21+
"cell_type": "code",
22+
"execution_count": 9,
23+
"metadata": {},
24+
"outputs": [],
25+
"source": [
26+
"rectangle = np.zeros((300, 300), dtype=\"uint8\")\n",
27+
"cv2.rectangle(rectangle, (25, 25), (275, 275), (255, 255, 255), -1)\n",
28+
"cv2.imshow(\"Original Rectangle\", rectangle)\n",
29+
"\n",
30+
"circle = np.zeros((300, 300), dtype=\"uint8\")\n",
31+
"cv2.circle(circle, (150, 150), 150, (255, 255, 255), -1)\n",
32+
"cv2.imshow(\"Original Circle\", circle)\n",
33+
"\n",
34+
"cv2.waitKey(0)\n",
35+
"cv2.destroyAllWindows()"
36+
]
37+
},
38+
{
39+
"cell_type": "code",
40+
"execution_count": 12,
41+
"metadata": {},
42+
"outputs": [],
43+
"source": [
44+
"bitwiseAnd = cv2.bitwise_and(rectangle, circle)\n",
45+
"cv2.imshow(\"AND\", bitwiseAnd)\n",
46+
"\n",
47+
"bitwiseOr = cv2.bitwise_or(rectangle, circle)\n",
48+
"cv2.imshow(\"OR\", bitwiseOr)\n",
49+
"\n",
50+
"bitwiseXor = cv2.bitwise_xor(rectangle, circle)\n",
51+
"cv2.imshow(\"XOR\", bitwiseXor)\n",
52+
"\n",
53+
"bitwiseNot1 = cv2.bitwise_not(rectangle)\n",
54+
"bitwiseNot2 = cv2.bitwise_not(circle)\n",
55+
"cv2.imshow(\"NOT-Rectangle\", bitwiseNot1)\n",
56+
"cv2.imshow(\"NOT-Circle\", bitwiseNot2)\n",
57+
"\n",
58+
"cv2.waitKey(0)\n",
59+
"cv2.destroyAllWindows()"
60+
]
61+
}
62+
],
63+
"metadata": {
64+
"kernelspec": {
65+
"display_name": "Python 3",
66+
"language": "python",
67+
"name": "python3"
68+
},
69+
"language_info": {
70+
"codemirror_mode": {
71+
"name": "ipython",
72+
"version": 3
73+
},
74+
"file_extension": ".py",
75+
"mimetype": "text/x-python",
76+
"name": "python",
77+
"nbconvert_exporter": "python",
78+
"pygments_lexer": "ipython3",
79+
"version": "3.5.2"
80+
}
81+
},
82+
"nbformat": 4,
83+
"nbformat_minor": 2
84+
}

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ This is a repository of code files which can be used to perform some basic tasks
1616

1717
* [Geometric Transformations on Images](https://github.com/altruistcoder/Open-CV-Implementations/blob/master/geometric_transformations.ipynb):
1818

19-
Python Code to perform Geometric Transformations like Image Translation, Rotation, Resizing, Flipping and Cropping of an image using OpenCV.
19+
Python Code to perform Geometric Transformations like Image Translation, Rotation, Resizing, Flipping and Cropping of an image using OpenCV.
20+
21+
* [Bitwise Operations on Images](https://github.com/altruistcoder/Open-CV-Implementations/blob/master/bitwise_operations.ipynb):
22+
23+
Python Code to perform Bitwise operations like AND, OR, XOR and Not operations on an image using OpenCV.

bitwise_operations.ipynb

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Bitwise Operations"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": 4,
13+
"metadata": {},
14+
"outputs": [],
15+
"source": [
16+
"import numpy as np\n",
17+
"import cv2"
18+
]
19+
},
20+
{
21+
"cell_type": "code",
22+
"execution_count": 9,
23+
"metadata": {},
24+
"outputs": [],
25+
"source": [
26+
"rectangle = np.zeros((300, 300), dtype=\"uint8\")\n",
27+
"cv2.rectangle(rectangle, (25, 25), (275, 275), (255, 255, 255), -1)\n",
28+
"cv2.imshow(\"Original Rectangle\", rectangle)\n",
29+
"\n",
30+
"circle = np.zeros((300, 300), dtype=\"uint8\")\n",
31+
"cv2.circle(circle, (150, 150), 150, (255, 255, 255), -1)\n",
32+
"cv2.imshow(\"Original Circle\", circle)\n",
33+
"\n",
34+
"cv2.waitKey(0)\n",
35+
"cv2.destroyAllWindows()"
36+
]
37+
},
38+
{
39+
"cell_type": "code",
40+
"execution_count": 12,
41+
"metadata": {},
42+
"outputs": [],
43+
"source": [
44+
"bitwiseAnd = cv2.bitwise_and(rectangle, circle)\n",
45+
"cv2.imshow(\"AND\", bitwiseAnd)\n",
46+
"\n",
47+
"bitwiseOr = cv2.bitwise_or(rectangle, circle)\n",
48+
"cv2.imshow(\"OR\", bitwiseOr)\n",
49+
"\n",
50+
"bitwiseXor = cv2.bitwise_xor(rectangle, circle)\n",
51+
"cv2.imshow(\"XOR\", bitwiseXor)\n",
52+
"\n",
53+
"bitwiseNot1 = cv2.bitwise_not(rectangle)\n",
54+
"bitwiseNot2 = cv2.bitwise_not(circle)\n",
55+
"cv2.imshow(\"NOT-Rectangle\", bitwiseNot1)\n",
56+
"cv2.imshow(\"NOT-Circle\", bitwiseNot2)\n",
57+
"\n",
58+
"cv2.waitKey(0)\n",
59+
"cv2.destroyAllWindows()"
60+
]
61+
}
62+
],
63+
"metadata": {
64+
"kernelspec": {
65+
"display_name": "Python 3",
66+
"language": "python",
67+
"name": "python3"
68+
},
69+
"language_info": {
70+
"codemirror_mode": {
71+
"name": "ipython",
72+
"version": 3
73+
},
74+
"file_extension": ".py",
75+
"mimetype": "text/x-python",
76+
"name": "python",
77+
"nbconvert_exporter": "python",
78+
"pygments_lexer": "ipython3",
79+
"version": "3.5.2"
80+
}
81+
},
82+
"nbformat": 4,
83+
"nbformat_minor": 2
84+
}

0 commit comments

Comments
 (0)