Computer Vision I -
Algorithms and Applications:
Basics of Image Processing
Carsten Rother
28/10/2013
Link to lectures
β’ Slides of Lectures and Exercises will be online:
http://www.inf.tu-Dresden/index.php?node_id=2091&ln=en (on our webpage > teaching > Computer Vision)
28/10/2013
Computer Vision I: Basics of Image Processing 2
Roadmap: Basics Digital Image Processing
β’ Images
β’ Point operators (ch. 3.1)
β’ Filtering: (ch. 3.2, ch 3.3, ch. 3.4) β main focus
β’ Linear filtering
β’ Non-linear filtering
β’ Fourier Transformation (ch. 3.4)
β’ Multi-scale image representation (ch. 3.5)
β’ Edges (ch. 4.2)
β’ Edge detection and linking
β’ Lines (ch. 4.3)
β’ Line detection and vanishing point detection
Roadmap: Basics Digital Image Processing
β’ Images
β’ Point operators (ch. 3.1)
β’ Filtering: (ch. 3.2, ch 3.3, ch. 3.4) β main focus
β’ Linear filtering
β’ Non-linear filtering
β’ Fourier Transformation (ch. 3.4)
β’ Multi-scale image representation (ch. 3.5)
β’ Edges (ch. 4.2)
β’ Edge detection and linking
β’ Lines (ch. 4.3)
β’ Line detection and vanishing point detection
28/10/2013
Computer Vision I: Basics of Image Processing 4
What is an Image
β’ We can think of the image as a function:
πΌ π₯, π¦ , πΌ: β Γ β ββ
β’ For every 2D point (pixel) it tells us the amount of light it receives
β’ The size and range of the sensor is limited:
πΌ π₯, π¦ , πΌ: π, π Γ π, π β [0, π]
β’ Colour image is then a vector-valued function:
πΌ π₯, π¦ =
πΌπ π₯, π¦ πΌπΊ π₯, π¦ πΌπ΅ π₯, π¦
, πΌ: π, π Γ π, π β 0, π 3
β’ Comment, in most lectures we deal with grey-valued images and extension to colour is βobviousβ
Images as functions
28/10/2013
Computer Vision I: Basics of Image Processing 6
[from Steve Seitz]
Digital Images
β’ We usually do not work with spatially continuous functions, since our cameras do not sense in this way.
β’ Instead we use (spatially) discrete images
β’ Sample the 2D domain on a regular grid (1D version)
β’ Intensity/color values usually also discrete.
Quantize the values per channel (e.g. 8 bit per channel)
Comment on Continuous Domain / Range
28/10/2013
Computer Vision I: Basics of Image Processing 8
β’ There is a branch of computer vision research (βvariational methodsβ), which operates on continuous domain for input images and output results
β’ Continuous domain methods are typically used for physics-based vision: segmentation, optical flow, etc. (we may consider this
briefly in later lectures)
β’ Continues domain methods then use different optimization techniques, but still discretize in the end.
β’ In this lecture and other lectures we mainly operate in discrete domain and discrete or continuous range for output results
Roadmap: Basics Digital Image Processing
β’ Images
β’ Point operators (ch. 3.1)
β’ Filtering: (ch. 3.2, ch 3.3, ch. 3.4) β main focus
β’ Linear filtering
β’ Non-linear filtering
β’ Fourier Transformation (ch. 3.4)
β’ Multi-scale image representation (ch. 3.5)
β’ Edges (ch. 4.2)
β’ Edge detection and linking
β’ Lines (ch. 4.3)
β’ Line detection and vanishing point detection
Point operators
β’ Point operators work on every pixel independently:
π½ π₯, π¦ = β πΌ π₯, π¦
β’ Examples for h:
β’ Control contrast and brightness; β(π§) = ππ§ + π
28/10/2013
Computer Vision I: Basics of Image Processing 10
Contrast enhanced original
Example for Point operators: Gamma correction
Intensity range: [0,1]
In (old) CRT monitors
An intensity π§ was perceived as:
β π§ = π§πΎ (πΎ = 2.2 typically) Inside cameras:
β π§ = π§1/πΎ where
often πΎ = 2.2 (called gamma correction)
Important: for many tasks in vision, e.g. estimation of a normal, it is good to run β π§ = π§πΎ to get to a linear function
Today: even with βlinear mappingβ monitors, it is good to keep the gamma corrected image. Since human vision is more sensitive in dark areas.
Example for Point Operators: Alpha Matting
28/10/2013
Computer Vision I: Basics of Image Processing 12
πΆ π₯, π¦ = πΌ π₯, π¦ πΉ π₯, π¦ + 1 β πΌ π₯, π¦ π΅(π₯, π¦)
Background π΅
Composite πΆ Matte πΌ
(amount of transparency) Foreground πΉ
Roadmap: Basics Digital Image Processing
β’ Images
β’ Point operators (ch. 3.1)
β’ Filtering: (ch. 3.2, ch 3.3, ch. 3.4) β main focus
β’ Linear filtering
β’ Non-linear filtering
β’ Fourier Transformation (ch. 3.4)
β’ Multi-scale image representation (ch. 3.5)
β’ Edges (ch. 4.2)
β’ Edge detection and linking
β’ Lines (ch 4.3)
β’ Line detection and vanishing point detection
Linear Filters / Operators
β’ Properties:
β’ Homogeneity: π[ππ] = ππ[π]
β’ Additivity: π[π + π] = π[π] + π[π]
β’ Superposition: π[ππ + ππ] = ππ[π] + ππ[π]
β’ Example:
β’ Convolution
β’ Matrix-Vector operations
28/10/2013
Computer Vision I: Basics of Image Processing 14
Convolution
β’ Replace each pixel by a linear combination of its neighbours and itself.
β’ 2D convolution (discrete) π = π β β
π π₯, π¦ = π,π π π₯ β π, π¦ β π β π, π = π,π π π, π β π₯ β π, π¦ β π
π π₯, π¦ β π₯, π¦ g π₯, π¦
Centred at 0,0
Convolution
28/10/2013
Computer Vision I: Basics of Image Processing 16
β’ Linear β β π0 + π1 = β β π0 + β β π1
β’ Associative π β π β β = π β π β β
β’ Commutative π β β = β β π
β’ Shift-Invariant π π₯, π¦ = π π₯ + π, π¦ + π β β β π π₯, π¦ = (β β π)(π₯ + π, π¦ + π)
(behaves everywhere the same)
β’ Can be written in Matrix form: g = H f
β’ Correlation (not mirrored filter):
π π₯, π¦ =
π,π
π π₯ + π, π¦ + π β π, π
Examples
β’ Impulse function: π = π β πΏ
β’ Box Filter:
x
πΏ
yApplication: Noise removal
β’ Noise is what we are not interested in:
sensor noise (Gaussian, shot noise), quantisation artefacts, light fluctuation, etc.
β’ Typical assumption is that the noise is not correlated between pixels
β’ Basic Idea:
neighbouring pixel contain information about intensity
28/10/2013 Computer Vision: Algorithms and Applications --
- Carsten Rother 18
Noise removal
The box filter does noise removal
β’ Box filter takes the mean in a neighbourhood
28/10/2013
Computer Vision I: Basics of Image Processing 20
Filtered Image
Image Pixel-independent
Gaussian noise added Noise
Derivation of the Box Filter
β’ π¦π is true gray value (color)
β’ π₯π observed gray value (color)
β’ Noise model: Gaussian noise:
π π₯π π¦π) = π π₯π; π¦π, π ~ exp[β π₯πβπ¦π
2
2π2 ]
π¦π π₯π
Derivation of Box Filter
28/10/2013
Computer Vision I: Basics of Image Processing 22
Further assumption: independent noise
Find the most likely solution the true signal π¦
Maximum-Likelihood principle (probability maximization):
π(π₯) is a constant (drop it out), assume (for now) uniform prior π(π¦).
So we get:
π π₯ π¦) ~ exp[β π₯πβπ¦π
2
2π2 ]
π
π¦β = ππππππ₯π¦ π π¦ π₯) = ππππππ₯π¦ π π¦ π π₯ π¦ π(π₯)
the solution is trivial: π¦π = π₯π for all π ο
additional assumptions about the signal π are necessary !!!
π π¦ π₯) = π π₯ π¦ βΌ exp[β π₯π β π¦π 2 2π2 ] π
posterior
likelihood prior
Derivation of Box Filter
Assumption: not uniform prior π π¦ but β¦
in a small vicinity the βtrueβ signal is nearly constant Maximum-a-posteriori:
π π¦ π₯) βΌ exp[β π₯πβ² β π¦πβ² 2 2π2 ]
π¦πβ = ππππππ₯π¦π exp[β π₯πβ² β π¦π 2 2π2 ]
π¦πβ = πππππππ¦π π₯πβ² β π¦π 2
Only one π¦π in a window π(π)
For one pixel π : π
take neg. logarithm:
Derivation of Box Filter
28/10/2013
Computer Vision I: Basics of Image Processing 24
π¦πβ = πππππππ¦π π₯πβ² β π¦π 2
How to do the minimization:
Take derivative and set to 0:
(the average)
π¦πβ
Box filter optimal under pixel-independent Gaussian Noise and constant signal in window
πΉ π¦π = π₯πβ² β π¦π 2
Gaussian (Smoothing) Filters
β’ Nearby pixels are weighted more than distant pixels
β’ Isotropic Gaussian (rotational symmetric)
Gaussian Filter
28/10/2013
Computer Vision I: Basics of Image Processing 26
Input: constant grey-value image
More noise needs larger sigma
Handling the Boundary (Padding)
Gaussian for Sharpening
28/10/2013
Computer Vision I: Basics of Image Processing 28
Sharpen an image by amplifying what is smoothing removes:
π = π + πΎ (π β βπππ’π β π)
How to compute convolution efficiently?
β’ Separable filters (next)
β’ Fourier transformation (see later)
β’ Integral Image trick (see exercise)
Important for later (integral Image trick):
The Box filter (mean filter) can be computed in π(π).
Naive implemettaioin would be π(ππ€)
where π€ is the number of elements in box filter
Separable filters
28/10/2013
Computer Vision I: Basics of Image Processing 30
For some filters we have: π β β = π β (βπ₯ β βπ¦) Where βπ₯, βπ¦ are 1D filters.
Example Box filter:
Now we can do two 1D convolutions:
π β β = π β βπ₯ β βπ¦ = (π β βπ₯) β βπ¦
NaΓ―ve implementation for 3x3 filter: 9N operations versus 3N+3N operations
βπ₯ β βπ¦
βπ₯
βπ¦
Can any filter be made separable?
Apply SVD to the kernel matrix:
If all ππ are 0 (apart from π0) then it is separable.
Note:
βπ₯ β βπ¦
βπ₯
βπ₯ βπ¦
βπ¦
Example of separable filters
28/10/2013
Computer Vision I: Basics of Image Processing 32
Roadmap: Basics Digital Image Processing
β’ Images
β’ Point operators (ch. 3.1)
β’ Filtering: (ch. 3.2, ch 3.3, ch. 3.4) β main focus
β’ Linear filtering
β’ Non-linear filtering
β’ Fourier Transformation (ch, 3.4)
β’ Multi-scale image representation (ch. 3.5)
β’ Edges (ch. 4.2)
β’ Edge detection and linking
β’ Lines (ch. 4.3)
β’ Line detection and vanishing point detection
Non-linear filters
β’ There are many different non-linear filters.
We look at a selection:
β’ Median filter
β’ Bilateral filter (Guided Filter)
β’ Morphological operations
28/10/2013
Computer Vision I: Basics of Image Processing 34
Shot noise (Salt and Pepper Noise) - motivation
Original + shot noise
Gaussian filtered
Median filtered
Another example
28/10/2013
Computer Vision I: Basics of Image Processing 36
Original
Mean Median
Noised
Median Filter
Replace each pixel with the median in a neighbourhood:
Used a lot for post processing of outputs (e.g. optical flow)
5 6 5
4 20 5
4 6 5
5 6 5
4 5 5
4 6 5
β’ No strong smoothing effect since values are not averaged
β’ Very good to remove outliers (shot noise)
median
Median filter: order the values and take the middle one
Median Filter: Derivation
Reminder: for Gaussian noise we did solve the following ML problem
28/10/2013
Computer Vision I: Basics of Image Processing 38
π¦πβ = ππππππ₯π¦π exp[β π₯πβ² β π¦π 2
2π2 ] = πππππππ¦π π₯πβ² β π¦π = 1/ π π₯π
Does not look like a Gaussian distribution median mean
π¦πβ = ππππππ₯π¦π exp[β π₯πβ² β π¦π
2π2 ] = πππππππ¦π |π₯πβ² β π¦π| = ππππππ (π π )
2
For Median we solve the following problem:
Due to absolute norm it is more robust π π¦ π₯)
Median Filter Derivation
minimize the following:
function:
Problem: not differentiable ο, good news: it is convex ο
πΉ π¦π = |π₯πβ² β π¦π|
Optimal solution is the mean of all values
Motivation β Bilateral Filter
28/10/2013
Computer Vision I: Basics of Image Processing 40
Original + Gaussian noise Gaussian filtered Bilateral filtered
Bilateral Filter β in pictures
Bilateral Filter weights Output
Centre pixel
Gaussian Filter weights
Noisy input
Output (sketched)
Bilateral Filter β in equations
28/10/2013
Computer Vision I: Basics of Image Processing 42
Filters looks at: a) distance of surrounding pixels (as Gaussian) b) Intensity of surrounding pixels
Problem: computation is slow π ππ€ ; approximations can be done in π(π)
Comment: Guided filter (see later) is similar and can be computed exactly in π(π) See a tutorial on: http://people.csail.mit.edu/sparis/bf_course/
Similar to Gaussian filter Consider intensity Linear combination
Application: Bilteral Filter
Cartoonization
HDR compression (Tone mapping)
Joint Bilteral Filter
28/10/2013
Computer Vision I: Basics of Image Processing 44
Similar to Gaussian Consider intensity
f is the input image β which is processed
f is a guidance image β where we look for pixel similarity
~ ~
~
Application: combine Flash and No-Flash
[Petschnigg et al. Siggraph β04]
input image π guidance image π
We donβt care about absolute colors
~ Joint Bilateral Filter
~ ~
Application: Cost Volume Filtering
28/10/2013
Computer Vision I: Basics of Image Processing 46
Goal
Given z; derive binary x:
Algorithm to minimization: πβ = πππππππ₯ πΈ(π)
π = π , πΊ, π΅ π x = 0,1 π
Reminder from first Lecture: Interactive Segmentation
Model: Energy function π¬ π = πππ π₯π + π,π πππ(π₯π, π₯π)
Unary terms Pairwise terms
Reminder: Unary term
Optimum with unary terms only
Dark means likely background
Dark means likely foreground
ππ(π₯π = 0) ππ(π₯π = 1)
New query image π§π
Cost Volumne for Binary Segmenation
28/10/2013
Computer Vision I: Basics of Image Processing 48
ππ(π₯π = 0) ππ(π₯π = 1)
Image (x,y)
Label Space (here 2)
For 2 Labels, we can also look at the ratio Image:
πΌπ = ππ(π₯π = 1) / ππ(π₯π = 0)
Application: Cost Volumne Filtering
An alternative to energy minimization
Filtered cost volume
Energy minimization Guidance Input Image π
(user brush strokes)
Winner takes all Result
Ratio Cost-volume is the Input Image π
~
[C. Rhemann, A. Hosni, M. Bleyer, C. Rother, and M. Gelautz, Fast Cost- Volume Filtering for Visual Correspondence and Beyond, CVPR 11]
Application: Cost volume filtering for dense Stereo
28/10/2013
Computer Vision I: Basics of Image Processing 50
Stereo result (winner takes all) 20-label cost
volume π Box filter
True solution Bilateral filter Guided filter Guidance Image π
[C. Rhemann, A. Hosni, M. Bleyer, C. Rother, and M. Gelautz, Fast Cost- Volume Filtering for Visual Correspondence and Beyond, CVPR 11]
Stereo Image pair
~
Application: Cost volume filtering for dense Stereo
Very competative in terms of results for a fast methods (Middleburry Ranking)
[C. Rhemann, A. Hosni, M. Bleyer, C. Rother, and M. Gelautz, Fast Cost- Volume Filtering for Visual Correspondence and Beyond, CVPR 11]
Recent Trend: Guided Filter
28/10/2013
Computer Vision I: Basics of Image Processing 52
Diferent pixel coordinates π, π linear combination of image π
Size of window ππ is fixed, e.g. 7x7.
Sum over all windows ππwhich contain pixels: π and π
βDifferent to biltarel filter since a sum over small windowsβ
ππ 7x7 pixels
π
[He, Sun ECCV β10]
Recent Trend: Guided Filter
Diferent pixel cooridinates π, π linear combination of image π
A window ππwhich is centred exactly on the edge Size of window ππ is fixed, e.g. 7x7.
Sum over all windows ππwhich contain pixels: π and π
βDifferent to biltarel filter since a sum over small windowsβ
Case 1: πΌπ , πΌπ on the same side: ππ β ππ (ππ β ππ) have the same sign. Then πππ large Case 2: πΌπ , πΌπ on the same side: ππ β ππ (ππ β ππ) have different sign. Then πππ small
variance in window ππ mean in window ππ
π~π
π~π π~π
~ ~
~ ~
Bilteral Filter and Guided Filter behave very similiarly
28/10/2013
Computer Vision I: Basics of Image Processing 54
Bilteral Filter and Guided Filter behave very similiarly
Guided Filter Bilteral Filter
Guided Filter: Can be computed in O(N)
28/10/2013
Computer Vision I: Basics of Image Processing 56
Can also be written as: (see paper for detail)
[He, Sun ECCV β10]
Integral Image trick
Applications: Matting
Guideanace Image π~ Input Image π Output Image π
[He, Sun ECCV β10]
Morphological operations
28/10/2013
Computer Vision I: Basics of Image Processing 58
β’ Perform convolution with a βstructural elementβ:
binary mask (e.g. circle or square)
β’ Then perform thresholding to recover a binary image
black is 1 white is 1
Opening and Closing Operations
β’ Opening operation: πππππ‘π πππππ π, π , π
β’ Closing opertiaon: πππππ πππππ‘π π, π , π
closing opening
Input image
erode and dilate are not commutative
Application: Denoise Binary Segmentation
28/10/2013
Computer Vision I: Basics of Image Processing 60
Note: nothing is commutative
Closing β than opening Opening β than closing
Input
Segmentation
Application: Binary Segmentation
[Criminisi, Sharp, Blake, GeoS: Geodesic Image Segmentation, ECCV 08]
Result: Edge preserving Opening and closing
Extend morphological operations to deal with cost volume and make it edge preserving (same idea as in joint bilateral filter)
Again: An alternative to energy minization
Ratio Cost-volume is the Input Image π
Energy minimization
Energy
minimization
ours
Related nonlinear operations on binary images
28/10/2013
Computer Vision I: Basics of Image Processing 62
Distance transform Binary
Image
Skeleton
Binary Input Image Connected components
Roadmap: Basics Digital Image Processing
β’ Images
β’ Point operators (Ch. 3.1)
β’ Filtering: (ch. 3.2, ch 3.3, ch. 3.4) β main focus
β’ Linear filtering
β’ Non-linear filtering
β’ Fourier Transformation (ch. 3.4)
β’ Multi-scale image representation (ch. 3.5)
β’ Edges (Ch. 4.2)
β’ Edge detection and linking
β’ Lines (Ch 4.3)
β’ Line detection and vanishing point detection
Fourier Transformation β¦ to analyse Filters
28/10/2013
Computer Vision I: Basics of Image Processing 64
Complex valued, continuous
sinusoid for different frequency π
π π₯ = β π₯ β π π₯ = π΄ ππ(π€π₯+π) = π΄ [ cos(π π₯ + π) + π π ππ(π π₯ + π) ] Amplitude phase
Simply try all possible π and record π΄, π . The Fourier transformation of β(π₯) is then:
π» π = β π₯ = π΄ πππ = π΄ (cos π + π sin π )
Filter/Image
How does a sinusoid influences a given filter/Image β(π₯) ?
Output signal
The output is also a sinusoid
Fourier Transform
Low-pass filter:
Band-pass filter:
Fourier Pair: Computation
28/10/2013
Computer Vision I: Basics of Image Processing 66
β π₯ β π»(π) π» π =
ββ
β
β π₯ πβπππ₯ ππ₯ β π₯ =
ββ
β
π» π ππππ₯ πΟ
π» π = 1
π π₯=0 πβ1
β π₯ πβπ2πππ₯π
Discrete Fourier transformation N is the range of signal (image region)
β(π₯) = 1
π π=0 πβ1
π» π ππ2πππ₯π
continuousdiscrete
Inverse Discrete Fourier transformation
Discrete Inverse Fourier Transform: Visualization
h(x) = 1
π π=0 πβ1
π» π ππ2πππ₯π
For this signal a reconstruction with sinus function only is sufficient
Discrete Inverse Fourier Transform: Visualization
28/10/2013
Computer Vision I: Basics of Image Processing 68
h(x) = 1
π π=0 πβ1
π» π ππ2πππ₯π
[from wikipedia]
Example: Discrete 2D
Original Amplitude Phase
Example: Discrete 2D
28/10/2013
Computer Vision I: Basics of Image Processing 70
Original Amplitude Phase
Example: Discrete 2D
Fast Fourier Transformation
28/10/2013
Computer Vision I: Basics of Image Processing 72
β’ Important property: (π π₯ β β π₯ ) = πΊ(π) π»(π)
β’ Fast computation:
π π₯ , β(π₯) O(Nw)
convolution π π₯ β β(π₯)
πΉ π , π»(π)
O(N logN)
fourier transform
O(N) multiplication
O(N logN)
inverse fourier transform
πΉ π π»(π)
O(N log N)
Roadmap: Basics Digital Image Processing
β’ Images
β’ Point operators (Ch. 3.1)
β’ Filtering: (ch. 3.2, ch 3.3, ch. 3.4) β main focus
β’ Linear filtering
β’ Non-linear filtering
β’ Fourier Transformation (ch. 3.4)
β’ Multi-scale image representation (ch. 3.5)
β’ Edges (Ch. 4.2)
β’ Edge detection and linking
β’ Lines (Ch 4.3)
β’ Line detection and vanishing point detection
Reading for next class
This lecture:
β’ Chapter 3 (in particular: 3.2, 3.3) - Basics of Digital Image Processing
Next lecture:
β’ Chapter 3.5: multi-scale representation
β’ Chapter 4.2 and 4.3 - Edge and Line detection
β’ Chapter 2 (in particular: 2.1, 2.2) β Image formation process
β’ And a bit of Hartley and Zisserman β chapter 2
28/10/2013
Computer Vision I: Introduction 74