Introduction to Data Science: (Khoa học dữ liệu)
Introduction to Data Science: (Khoa học dữ liệu)
2
Plan
• Introduction
• Digital images and basic operations
‒ histogram, brightness, contrast, color, texture, …
3
Computer Vision ?
• Image Processing
‒ Work with image as a matrix
‒ Input: image ➔ output: image
‒ Help human to examine / modify images
• Computer Vision
‒ Make computers understand images and video
‒ Images and video are a source of information on the
reality
What kind of scene?
Where are the cars?
How far is the building?
…
4
Computer Vision and Applications
5
How vision is used now
Source: Derek Hoiem, Computer vision, CS 543 / ECE 549, University of Illinois
6
How vision is used now
Source: Derek Hoiem, Computer vision, CS 543 / ECE 549, University of Illinois
7
How vision is used now
Source: Derek Hoiem, Computer vision, CS 543 / ECE 549, University of Illinois
8
How vision is used now
• Content-based image retrieval
9
How vision is used now
• Panorama stitching:
Source:http://miseaupoint.org/blog/en/wp-content/uploads/2014/01/photo_stitching.jpg
11
How vision is used now
12
How vision is used now
http://www.robocup.org/
Where is it?
Text in the picture,
How to represent what does it mean?
the image content ? Are there any person
in the picture?
17
Digital images ?
18
Digital images ?
• For an image I x
19
Digital images ?
20
Color image in RGB space
21
Image histogram
22
Image histogram
Histogram
Should be normalized by dividing all elements to total number
of pixels in the image
p 𝑖 𝜖 [0,1]
255
𝑝 𝑖 = 1
𝑖=0
23
Image histogram
• Histogram
‒ Only statistic information
‒ No indication about the location of pixel (no spatial
information) ➔ Different images can have the same
histogram
24
Image Brightness
• Brightness of a grayscale image is the average intensity
of all pixels in an image
‒ refers to the overall lightness or darkness of the image
25
Contrast
• The contrast of a grayscale image indicate how easily
object in the image can be distinguished
• Many different equations for contrast exist
‒ Standard deviation of intensity values of pixels in the
image
26
Brightness/Contrast vs histogram
Narrow histogram
Broad histogram
27
Contrast Enhancement
• Modify pixel intensities to obtain higher contrast
• There are several methods:
‒ Linear stretching of intensity range:
• Linear transform
• Linear transform with saturation
• Piecewise linear transform
28
Linear stretching 𝑠 = 𝑠𝑚𝑖𝑛 + 𝑟 − 𝑟𝑚𝑖𝑛
𝑠𝑚𝑎𝑥 − 𝑠𝑚𝑖𝑛
𝑟𝑚𝑎𝑥 − 𝑟𝑚𝑖𝑛
𝑠 = 𝑎. 𝑟 + 𝑠𝑚𝑖𝑛 − 𝑎. 𝑟𝑚𝑖𝑛 ,
𝑠 −𝑠
where a = 𝑟𝑚𝑎𝑥− 𝑟𝑚𝑖𝑛
𝑚𝑎𝑥 𝑚𝑖𝑛
29
Linear stretching
30
Histogram equalization
• Change histogram of modified image into uniform
distribution
• No parameters. OpenCV:cv2.equalizeHist(img)
31
Histogram equalization
32
Gama correction
Non linear transformation
• The general form of power-law transformation is:
𝑠 = 𝑐. 𝑟
‒ > 1: compress values in dark area, while expanding values in light
area
‒ < 1 : expand values in dark area, while compressing values in light
area
s : new value
r : normalized old values
to [0, 1]
(r = old intensity/(L-1))
c : scaling constant
corresponding to the bit size
used
(c = L-1 = 255)
33
Gama correction
𝑟 𝛾
𝑠 = 255.
255
34
Color Image histogram
• Intensity histogram:
‒ Convert color image to
grayscale
=> Compute histogram of gray
scale image
• Individual Color Channel
Histograms:
3 histograms for (R,G,B)
• 3D histogram:
a color identified by 3 values. Not
usually because of big elements
Source: https://web.cs.wpi.edu/~emmanuel
35
RGB (Red – Green - Blue)
36
Human Vision
37
Human Vision ➔ Camera
• Three kinds of cones
- each cone is able to detect a range of colors
- labeled by the color at which they are most sensitive
.
100
S M L
50
WAVELENGTH (nm.)
38
HSV (Hue – Saturation- Value)
39
HSV (Hue – Saturation- Value)
40
HSV (Hue – Saturation- Value)
41
Lab color space
42
Lab color space
43
Color conversions
• OpenCV:
‒ https://docs.opencv.org/4.0.0/de/d25/imgproc_color_conversions
.html
‒ Function: cv::cvtColor (InputArray src, OutputArray dst, int
code, int dstCn=0)
• converts an image from one color space to another
• code: conversion code (COLOR_RGB2HSV,
COLOR_RGB2HSV, COLOR_BGR2Lab, …)
44
Color space vs. illumination conditions
Fig.: Density Plot showing the variation of values in color channels for
2 similar bright images of yellow color
Source: Vikas Gupta, Learn OpenCV
47
Different illumination
• Different illumination:
• Different illumination:
‒ RGB space: the variation in the value of channels is very
hight
‒ HSV: compact in H. Only H contains information about the
absolute color ➔ a choix
‒ YCrCb, LAB: compact in CrCb and in AB
• Higher level of compactness is in LAB
‒ Convert to other color spaces (OpenCV):
• cvtColor(bgr, ycb, COLOR_BGR2YCrCb);
• cvtColor(bgr, hsv, COLOR_BGR2HSV);
• cvtColor(bgr, lab, COLOR_BGR2Lab);
50
Spatial convolution
51
Spatial convolution
Mask (kernel)
Original image Filtered image
52
Spatial convolution
53
Spatial convolution
Source: http://machinelearninguru.com
54
Spatial convolution
I' = I * K
55
Spatial convolution
I' = I * K
56
Spatial convolution
I' = I * K
57
Spatial convolution
• Border problem?
‒ Zero padding in the input matrix
‒ reflect across border:
• f(-x,y) = f(x,y)
• f(-x,-y) = f(x,y)
‒…
58
Some kernels
• 2D spatial convolution
‒ is mostly used in image processing for feature extraction
‒ And is also the core block of Convolutional Neural Networks
(CNNs)
• Each kernel has its own effect and is useful for a specific
task such as
‒ blurring (noise removing): mean filter, gaussian filter, …
‒ Sharpening,
‒ edge detection: sobel, prewitt, laplace
‒ …..
60
Some kernels
0 0 0
* 0 1 0
0 0 0
0 0 0
* 1 0 0
0 0 0
Filtered image
Original image
(shifted left by 1 pixel)
Source: David Lowe
61
Some kernels
62
Some kernels
• Gaussian filter
65
Some kernels
• Sobel
Vertical Edge
(absolute value)
66
Some kernels
• Sobel
Horizontal Edge
(absolute value)
67
Edge detection
68
Edge detection with first derivatives
69
Edge detection with first derivatives
‒ Prewitt
• less sensitive to noise
• Smoothing with mean filter,
then compute1st derivative
‒ Sobel:
• less sensitive to noise
• Smoothing with gaussian,
then computing1st derivative
y x
70
Edge detection with first derivatives
71
Image derivatives
• 1st derivatives :
First derivative of
I* Ix image with
respect to x
First derivative of
I* Iy image with
respect to y
Image gradient
72
Image gradient
73
Edge detection with second derivatives
[ 0 1 0
1 −4 1
0 1 0 ] Or
[ 1 1 1
1 −8 1
1 1 1 ]
• Find zero-crossing
74
Laplacian filter - Second derivative
75
OpenCV
76
Image representation
77
Feature extraction
• Global features
79
Feature extraction
Dividing into
patches with Keypoint detection
regular grid
Image segmentation
81
Feature extraction
• Image segmentation
‒ Thresholding
‒ Split and merge
‒ Region growing
‒ Watershed
‒…
82
Feature extraction
• Keypoint detectors:
‒ DoG /SIFT detector
‒ Harris corner detector
‒ Moravec
‒ …
• Local features: computed in
local regions associated to each
keypoints:
- SIFT,
- SURF(Speeded Up Robust
Features),
- PCA-SIFT
- LBP, BRISK, MSER and
FREAK, …
83
Keypoint detector
84
Keypoint detector: DoG/SIFT detector
85
Feature extraction : Good feature?
• Compact
• Invariant to
‒ geometric transformation
‒ Camera viewpoint
‒ Lighting condition
86
Feature extraction : SIFT feature
87
Other detectors and descriptors
88
Feature extraction : OpenCV
89
Feature extraction : OpenCV
• SIFT
sift = cv.xfeatures2d.SIFT_create() // for version before v 4.4.
sift = cv. SIFT_create() // for version from v 4.4.
‒ sift.detect() function finds the keypoint in the images
‒ sift.compute() which computes the descriptors from the keypoints
kp = sift.detect(gray,None)
kp,des = sift.compute(gray,kp)
‒ Find keypoints and descriptors in a single step
sift.detectAndCompute()
kp, des = sift.detectAndCompute(gray,None)
‒ https://docs.opencv.org/3.4/da/df5/tutorial_py_sift_intro.html
• SURF: similar
90
Feature extraction : OpenCV
• SURF: similar
>>> img = cv.imread('fly.png',0)
# Create SURF object. You can specify params here or later.
# Here I set Hessian Threshold to 400
>>> surf = cv.xfeatures2d.SURF_create(400)
# Find keypoints and descriptors directly
>>> kp, des = surf.detectAndCompute(img,None)
>>> len(kp)
699
‒ https://docs.opencv.org/3.4/df/dd2/tutorial_py_surf_intro.html
91
Origine: Bag-of-words models
• Orderless document representation: frequencies of
words from a dictionary Salton & McGill (1983)
Csurka et al. (2004), Willamowski et al. (2005), Grauman & Darrell (2005), Sivic et al. (2003, 2005) 93
Bag of features: outline
1. Extract features OpenCV:
BOWImgDescriptorExtractor Class
2. Learn “visual vocabulary”
3. Quantize features using visual vocabulary
4. Represent images by frequencies of
“visual words”
94
Higher semantic vision problem
1. Image representation
- Pixel level
- Region level
- Image level
2. Classification: ML techniques
- Pixel level ➔ segmentation
- Region level ➔ detection
- Image level ➔ classification/recognition
95
References
• CVIP tool to explore the power of computer processing of digital images: Many methods in image
processing and computer vision have been implemented
‒ https://cviptools.ece.siue.edu/
• Library: OpenCV, with C/C++, Python and Java interfaces. OpenCV was designed for computational
efficiency and with a strong focus on real-time application: https://opencv.org/
• Books:
‒ Rafael C. Gonzalez, Richard Eugene Woods, Digital Image Processing, 2nd edition, Prentice -Hall,
2002: Chap 3 (spatial operators), 6 (Color spaces)
‒ Richard Szeliski, Computer Vision: Algorithms and Applications, Springer, 2010.
http://szeliski.org/Book/
• Articles:
‒ SIFT (DoG detector and SIFT descriptor): https://www.cs.ubc.ca/~lowe/keypoints/
‒ SURF: Herbert Bay, Andreas Ess, Tinne Tuytelaars, and Luc Van Gool, "Speeded Up Robust
Features", ETH Zurich, Katholieke Universiteit Leuven
‒ GLOH: Krystian Mikolajczyk and Cordelia Schmid "A performance evaluation of local descriptors",
IEEE Transactions on Pattern Analysis and Machine Intelligence, 10, 27, pp 1615--1630, 2005.
‒ PHOG: http://www.robots.ox.ac.uk/~vgg/research/caltech/phog.html
• https://www.learnopencv.com/ : many examples with code in C++/ Python and clear explanation
96
Thank you for
your attention!
98