Skip to content

Commit 2ed9fda

Browse files
committed
new files
Image Processing tutorials added
1 parent 3c1aff9 commit 2ed9fda

26 files changed

+703
-28
lines changed

Diff for: 02.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"#Print Statement"
7+
"# Print Statement"
88
]
99
},
1010
{

Diff for: 03.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1550,7 +1550,7 @@
15501550
},
15511551
{
15521552
"cell_type": "code",
1553-
"execution_count": 65,
1553+
"execution_count": 1,
15541554
"metadata": {},
15551555
"outputs": [
15561556
{

Diff for: 05.ipynb

+17
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,23 @@
314314
"print('Bye')"
315315
]
316316
},
317+
{
318+
"cell_type": "code",
319+
"execution_count": 1,
320+
"metadata": {},
321+
"outputs": [
322+
{
323+
"name": "stdout",
324+
"output_type": "stream",
325+
"text": [
326+
"hellohello\n"
327+
]
328+
}
329+
],
330+
"source": [
331+
"print(2*'hello')"
332+
]
333+
},
317334
{
318335
"cell_type": "markdown",
319336
"metadata": {},

Diff for: README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Python 3 Tutorial Using Jupyter Notebook
22

3-
Originally written by rajathkmp: https://github.com/rajathkmp/Python-Lectures
3+
Image Processing tutorials are written by me.
4+
5+
Python tutorials are originally written by rajathkmp: https://github.com/rajathkmp/Python-Lectures
46

57
These tutorials are designed for Python 3 users. I will keep updating this repo for more tutorials on further topics in the future.

Diff for: data/boundary.png

518 KB
Loading

Diff for: data/boundary2.PNG

507 KB
Loading

Diff for: data/canny.PNG

603 KB
Loading

Diff for: data/chardata.jpg

139 KB
Loading

Diff for: data/done.gif

1.22 MB
Loading

Diff for: data/drawthis.png

4.76 KB
Loading

Diff for: data/firebase1.PNG

58.4 KB
Loading

Diff for: data/masking.PNG

551 KB
Loading

Diff for: data/resC.PNG

9.88 KB
Loading

Diff for: data/resCp.PNG

3.82 KB
Loading

Diff for: data/research.gif

54.7 KB
Loading

Diff for: data/theend.gif

723 KB
Loading

Diff for: data/wtf.gif

862 KB
Loading

Diff for: image_proc01.ipynb

+461-25
Large diffs are not rendered by default.

Diff for: image_proc02.ipynb

+214
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Image Processing\n",
8+
"This is a follow up and advancement of the first tutorial on image processing. \n",
9+
"\n",
10+
"#### Disclaimer:\n",
11+
"If by following this second tutorial you feel like:\n",
12+
"<img src=\"data/wtf.gif\" width=\"500\">\n",
13+
"Then go **read the first tutorial** again carefully.\n",
14+
"\n",
15+
"But if you have understood all that was described in the first, **congrats on your first research!**\n",
16+
"<img src=\"data/research.gif\" width=\"500\">"
17+
]
18+
},
19+
{
20+
"cell_type": "code",
21+
"execution_count": 3,
22+
"metadata": {},
23+
"outputs": [],
24+
"source": [
25+
"import cv2\n",
26+
"import numpy as np\n",
27+
"import matplotlib.pyplot as plt\n",
28+
"% matplotlib inline"
29+
]
30+
},
31+
{
32+
"cell_type": "markdown",
33+
"metadata": {},
34+
"source": [
35+
"### Edge Detection\n",
36+
"Boundaries of any object is called an edge. In image processing you can extract the edges of object by very ease. It is basically a high pass filter that completely removes anything that is not an edge. \n",
37+
"\n",
38+
"<img src=\"data/canny.png\" width=\"900\">"
39+
]
40+
},
41+
{
42+
"cell_type": "code",
43+
"execution_count": 31,
44+
"metadata": {},
45+
"outputs": [
46+
{
47+
"data": {
48+
"text/plain": [
49+
"-1"
50+
]
51+
},
52+
"execution_count": 31,
53+
"metadata": {},
54+
"output_type": "execute_result"
55+
}
56+
],
57+
"source": [
58+
"img = cv2.imread('samples/D (198).jpg')\n",
59+
"im = cv2.resize(img, (500,500))\n",
60+
"gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)\n",
61+
"\n",
62+
"edges = cv2.Canny(gray, 550, 150)\n",
63+
"\n",
64+
"cv2.imshow('im', im)\n",
65+
"cv2.imshow('gray', gray)\n",
66+
"cv2.imshow('edges', edges)\n",
67+
"\n",
68+
"cv2.waitKey(0)"
69+
]
70+
},
71+
{
72+
"cell_type": "markdown",
73+
"metadata": {},
74+
"source": [
75+
"### Try it out with a video"
76+
]
77+
},
78+
{
79+
"cell_type": "code",
80+
"execution_count": 13,
81+
"metadata": {},
82+
"outputs": [],
83+
"source": [
84+
"cap = cv2.VideoCapture(0)\n",
85+
"\n",
86+
"while(cap.isOpened()):\n",
87+
" _, frame = cap.read()\n",
88+
" gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)\n",
89+
" edges = cv2.Canny(gray, 50, 100)\n",
90+
" \n",
91+
" cv2.imshow('frame', frame)\n",
92+
" cv2.imshow('edges', edges)\n",
93+
" \n",
94+
" if cv2.waitKey(1) & 0xff == ord('q'):\n",
95+
" break\n",
96+
"\n",
97+
"cap.release()\n",
98+
"cv2.destroyAllWindows()"
99+
]
100+
},
101+
{
102+
"cell_type": "markdown",
103+
"metadata": {},
104+
"source": [
105+
"### Object Tracking\n",
106+
"As we have covered all the basics of image processing which includes masking, finding edges, knowing the shape of images and frames of video; we can now proceed towards **making an object tracker from scratch!**\n",
107+
"\n",
108+
"This will include the concept of:\n",
109+
"- threshold\n",
110+
"- contours \n",
111+
"- image moments \n",
112+
"- finding the area of images\n",
113+
"- finding the coordinates of contours\n",
114+
"- drawing the boundary around the object using those coordinates\n",
115+
"\n",
116+
"#### Contours:\n",
117+
"Any closed area is a contour. As seen from the edge detector concept, every closed area you see there is a contour.\n",
118+
"#### Image Moments:\n",
119+
"The weighted average of all the pixel intensities in a image is called moment. We can find out the center of the weighted average hence, can calculate the centroid of an image."
120+
]
121+
},
122+
{
123+
"cell_type": "code",
124+
"execution_count": 14,
125+
"metadata": {},
126+
"outputs": [],
127+
"source": [
128+
"cap = cv2.VideoCapture(0)\n",
129+
"min_area = 100*100\n",
130+
"\n",
131+
"while(cap.isOpened):\n",
132+
" _,frame = cap.read()\n",
133+
" hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)\n",
134+
" \n",
135+
" upper = np.array([54,134,93])\n",
136+
" lower = np.array([255,255,255])\n",
137+
" \n",
138+
" mask = cv2.inRange(hsv, upper, lower)\n",
139+
" res = cv2.bitwise_and(frame, frame, mask=mask)\n",
140+
" \n",
141+
" # detection of contours\n",
142+
" res_gray = cv2.cvtColor(res, cv2.COLOR_BGR2GRAY)\n",
143+
" _, threshold = cv2.threshold(res_gray, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)\n",
144+
" _, contours, _ = cv2.findContours(threshold, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)\n",
145+
" \n",
146+
" for contour in contours:\n",
147+
" area = cv2.contourArea(contour)\n",
148+
" if area>min_area:\n",
149+
" # calculating the centroid\n",
150+
" moment = cv2.moments(contour)\n",
151+
" cx = int(moment['m10']/moment['m00'])\n",
152+
" cy = int(moment['m01']/moment['m00'])\n",
153+
" \n",
154+
" # make a rectangle bounding the contour\n",
155+
" [x, y, w, h] = cv2.boundingRect(contour)\n",
156+
" \n",
157+
" # draw a rectangle surrounding the contour image\n",
158+
" cv2.rectangle(frame, (x, y), (w+x, h+y), (0,255,0), 2)\n",
159+
" \n",
160+
" # put the centroid text\n",
161+
" cv2.putText(frame, str(cx)+','+str(cy), (cx,cy), 2, 1, (255,0,0), 1, 0)\n",
162+
" #endif\n",
163+
" #endfor\n",
164+
" cv2.imshow('frame', frame)\n",
165+
" if cv2.waitKey(1) & 0xff == ord('q'):\n",
166+
" break\n",
167+
" #endif\n",
168+
"#endwhile\n",
169+
"\n",
170+
"cap.release()\n",
171+
"cv2.destroyAllWindows()"
172+
]
173+
},
174+
{
175+
"cell_type": "markdown",
176+
"metadata": {},
177+
"source": [
178+
"### Future Workshops\n",
179+
"We at ***NUST Air Works*** have a strong belief in sharing information and keep learning, adopting, and adapting to newer and advanced concepts. In the future we are working on a new project for you which is solely on further image processing and machine learning. We are glad that you attended this workshop and we hope that you have learnt something from our team.\n",
180+
"\n",
181+
"### The End\n",
182+
"<img src=\"data/theend.gif\" width=\"800\">"
183+
]
184+
},
185+
{
186+
"cell_type": "code",
187+
"execution_count": null,
188+
"metadata": {},
189+
"outputs": [],
190+
"source": []
191+
}
192+
],
193+
"metadata": {
194+
"kernelspec": {
195+
"display_name": "Python 3",
196+
"language": "python",
197+
"name": "python3"
198+
},
199+
"language_info": {
200+
"codemirror_mode": {
201+
"name": "ipython",
202+
"version": 3
203+
},
204+
"file_extension": ".py",
205+
"mimetype": "text/x-python",
206+
"name": "python",
207+
"nbconvert_exporter": "python",
208+
"pygments_lexer": "ipython3",
209+
"version": "3.6.2"
210+
}
211+
},
212+
"nbformat": 4,
213+
"nbformat_minor": 2
214+
}

Diff for: image_proc03.ipynb

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cells": [],
3+
"metadata": {},
4+
"nbformat": 4,
5+
"nbformat_minor": 2
6+
}

Diff for: samples/B (105).jpg

2.26 MB
Loading

Diff for: samples/C (60).jpg

2.97 MB
Loading

Diff for: samples/D (198).jpg

3.72 MB
Loading

Diff for: samples/bouncingBall.avi

30.8 MB
Binary file not shown.

Diff for: samples/samples.jpg

9.3 KB
Loading

Diff for: untitled.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)