Developing Image Processing and Computer Vision Applications Dr. Usman Ghani
Developing Image Processing and Computer Vision Applications Dr. Usman Ghani
Vision applications
Artificial Intelligence
▰ Introduction to OpenCV
▰ Image Basics in OpenCV
▰ Basic functions of OpenCV
▰ Constructing Basic Shapes in OpenCV
▰ Image filtering
▰ Morphological transformations
▰ Processing Images with OpenCV
▰ Working with videos
2
Introduction to
OpenCV
3
How does computer vision works?
4
Applications of OpenCV
Manufacturing Production
Autonomous vehicles Line
• e.g. Self Driving Cars • Labeling and tracing products
5
Computer Vision Toolkits
Endrov
VTK VXL
PIL BootCV
Computer
PCL Vision VLFeat
toolkits
6
Introduction to the OpenCV library
7
Installing OpenCV, Python, and other packages
8
Image Basics in
OpenCV
9
Concepts of pixels, colors, channels, images,
and color spaces
10
Accessing and manipulating pixels in OpenCV
11
Get image shape
12
Basic functions of
OpenCV
13
Read an Image
14
https://miro.medium.com/max/1400/1*IHHLvhkhx2xHloOb3-wXwA.jpeg
Display an image
Output
15
Save image to disk
16
Access Image properties
Syntax:
• img.shape
• img.dtype
• img.size
17
Change Color Spaces
RGB → Gray
cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
18
Resize image
19
Constructing Basic
Shapes in OpenCV
20
Draw a rectangle on image
Output
21
Draw a circle on image
Syntax: cv2.circle(image,
center_coordinates, radius, color,
thickness)
Output
22
Draw a line on image
Output
23
Draw an ellipse on image
Output
24
Put text on image
Output
25
Image filtering
26
Sharpen the image
Output
27
Blur an image
Output
28
Apply Gaussian Filter on an image
Output
29
Apply Median Filter on an image
Output
30
Apply an identity Filter on an image
Output
31
Processing Image
Operations with OpenCV
32
Perform Thresholding on an image
Output
33
Detect Edges of objects in an image
Output
34
Detect Contours in an image
#find Contours
cv2.FindContours(image,mode=
CV_RETR_LIST,method=CV_CHAIN_APPROX_
SIMPLE)
#draw contours
cv2.DrawContours(img, contours,
contourIdx, colour, thickness)
Output
35
Setting Region of Image
Output
36
Blending Images
Blend Pictures
Syntax: cv2.addWeighted(img1, alpha, img2, beta, gamma)
Pic 1 Pic 2
37
Crop an image
38
Splitting and merging images
Split an image
39
Draw Histogram of an image
40
Apply Log Transformation on an image
# Apply log transform.
c = 255/(np.log(1 + np.max(img)))
log_transformed = c * np.log(1 + img)
abc= np.array(log_transformed, dtype = np.uint8)
41
Apply Power Law Transformation on an image
43
Dilation Operation
44
Erosion Operation
45
Opening Operation
Syntax: cv2.morphologyEx(img,
cv2.MORPH_OPEN, kernel)
46
Closing Operation
Syntax: cv2.morphologyEx(img,
cv2.MORPH_CLOSE, kernel)
47
Top Hat Operation
Syntax: cv2.morphologyEx(img,
cv2.MORPH_TOPHAT, kernel)
48
Black Hat Operation
Syntax: cv2.morphologyEx(img,
cv2.MORPH_BLACKHAT, kernel)
49
Morphological gradient operation
Syntax: cv2.morphologyEx(img,
cv2.MORPH_GRADIENT, kernel))
50
Perform Negative of an Image
# Subtract the img from max value
(calculated from dtype)
img_neg = 255 - img
51
THANKS!
Prof Dr. Muhammad Usman Ghani Khan
Director
NCAI UET Lahore
[email protected]
52