Title: Image Transforms
1Image Transforms
2Content
- Overview
- Convolution
- Edge Detection
- Gradients
- Sobel operator
- Canny edge detector
- Laplacian
- Hough Transforms
- Geometric Transforms
- Affine Transform
- Perspective Transform
- Histogram Equalization
3Image Transforms
4Image Transform Concept
T
5Image Transform Concept
T
6Image Transforms
7Image Convolution
g(x,y) is known as convolution kernel.
8Image Convolution
g(x,y) is known as convolution kernel.
height 2h 1 width 2w 1
9Image Convolution
g(x,y) is known as convolution kernel.
height 2h 1 width 2w 1
10Some Convolution Kernels
11OpenCV Implementation ? Image Filter
void cvFilter2D( const CvArr src, CvArr
dst, const CvMat kernel, CvPoint
anchorcvPoint(-1, -1) )
12Deal with Convolution Boundaries
void cvCopyMakeBorder( const CvArr src,
CvArr dst, CvPoint offset, int bordertype,
CvScalar valuecvScalarAll(0) )
13Image Transforms
14Edge Detection
- Convert a 2D image into a set of curves
- Extracts salient features of the scene
- More compact than pixels
15Origin of Edges
surface normal discontinuity
depth discontinuity
surface color discontinuity
illumination discontinuity
Edges are caused by a variety of factors
16Edge Detection
How can you tell that a pixel is on an edge?
17Edge Types
18Real Edges
Noisy and Discrete!
- We want an Edge Operator that produces
- Edge Magnitude
- Edge Orientation
- High Detection Rate and Good Localization
19Derivatives of Image in 1D
? 1D image
? gradient
? Laplacian
- Edges can be characterized as either
- local extrema of ?I(x)
- zero-crossings of ?2I(x)
202D-Image Gradient
212D-Image Gradient
- Gives the direction of most rapid change in
intensity - Gradient direction
- Edge strength
22Classification of Points
- To precisely locate the edge, we need to thin.
- Ideally, edges should be only one point thick.
23The Sobel Operators
-1 0 1
-2 0 2
-1 0 1
1 2 1
0 0 0
-1 -2 -1
Good Localization Noise Sensitive Poor Detection
Sobel (3 x 3)
-1 -2 0 2 1
-2 -3 0 3 2
-3 -5 0 5 3
-2 -3 0 3 2
-1 -2 0 2 1
1 2 3 2 1
2 3 5 3 2
0 0 0 0 0
-2 -3 -5 -3 -2
-1 -2 -3 -2 -1
Sobel (5 x 5)
Poor Localization Less Noise Sensitive Good
Detection
24OpenCV Implementation ? The Sobel Operators
void cvSobel( const CvArr src, CvArr dst,
int xorder, int yorder, int aperture_size
3 )
25OpenCV Implementation ? The Scnarr Operator
void cvSobel( const CvArr src, CvArr dst,
int xorder, int yorder, int aperture_size
3 )
aperture_size
CV_SCHARR
26Demonstration
27Exercise
Download Test Program
28Effects of Noise
Consider a single row or column of the image
Where is the edge?
29Solution Smooth First
30Solution Smooth First
Where is the edge?
31Derivative Theorem of Convolution
Gaussian
32Derivative Theorem of Convolution
33Optimal Edge Detection Canny
- Assume
- Linear filtering
- Additive iid Gaussian noise
- An "optimal" edge detector should have
- Good Detection
- Filter responds to edge, not noise.
- Good Localization
- detected edge near true edge.
- Single Response
- one per edge.
34Optimal Edge Detection Canny
- Based on the first derivative of a Gaussian
- Detection/Localization trade-off
- More smoothing improves detection
- And hurts localization.
35Stages of the Canny algorithm
- Noise reduction
- Size of Gaussian filter
- Finding the intensity gradient of the image
- Non-maximum suppression
- Tracing edges through the image and hysteresis
thresholding - High threshold
- Low threshold
36Parameters of Canny algorithm
- Noise reduction
- Size of Gaussian filter
- Finding the intensity gradient of the image
- Non-maximum suppression
- Tracing edges through the image and hysteresis
thresholding - High threshold
- Low threshold
37OpenCV Implementation ? The Canny Operator
void cvCanny( const CvArr img, CvArr
edges, double lowThresh, double highThresh,
int apertureSize 3 )
38Example Canny Edge Detector
Download Test Program
39ReviewDerivatives of Image in 1D
? 1D image
? gradient
? Laplacian
- Edges can be characterized as either
- local extrema of ?I(x)
- zero-crossings of ?2I(x)
40Laplacian
- A scalar ? isotropic.
- Edge detection Find all points for which
- ?2I(x, y) 0
- No thinning is necessary.
- Tends to produce closed edge contours.
41Laplacian
42Discrete Laplacian Operators
43OpenCV Implementation ?The Discrete Laplacian
Operators
void cvLaplace( const CvArr src, CvArr
dst, int apertureSize 3 )
44Example
45Laplician for Edge Detection
Find zero-crossing on the Laplacian image.
46Zero Crossing Detection
There is a little bug in the above algorithm.
Try to design your own zero-crossing detection
algorithm.
47ExampleLaplician for Edge Detection
Download Test Program
48Laplacian for Image Sharpening
49ExampleLaplacian for Image Sharpening
Sharpened Image
50Laplacian of Gaussian (LoG)
Gaussian
51Some LoG Convolution Kernels
52ExampleLoG for Edge Detection
by Laplacian
by LoG
53Image Transforms
54Goal of Hough Transforms
- A technique to isolate the curves of a given
shape / shapes in a given image - Classical Hough Transform
- can locate regular curves like straight lines,
circles, parabolas, ellipses, etc. - Generalized Hough Transform
- can be used where a simple analytic description
of feature is not possible
55HT for Line Detection
A line in xy-plane is a point in mb-plane.
(m, b)
56HT for Line Detection
A line in xy-plane is a point in mb-plane.
All lines passing through a point in xy-plane is
a line in mb-plane.
(m2, b2)
(m1, b1)
(m3, b3)
57HT for Line Detection
A line in xy-plane is a point in mb-plane.
All lines passing through a point in xy-plane is
a line in mb-plane.
Given a point in xy-plane, we draw a line in
mb-plane.
(m2, b2)
(m1, b1)
(m3, b3)
58HT for Line Detection
A line in xy-plane is a point in mb-plane.
Given a point in xy-plane, we draw a line in
mb-plane.
A line in xy-plane is then transformed in to a
set of lines in mb-plane, which intersect at a
common point.
(m, b)
59HT for Line Detection
A line in xy-plane is a point in mb-plane.
Given a point in xy-plane, we draw a line in
mb-plane.
How to implement?
Is mb representation suitable?
A line in xy-plane is then transformed in to a
set of lines in mb-plane, which intersect at a
common point.
(m, b)
60HT Line Detection by ??-representation
A line in xy-plane is a point in ??-plane.
(?, ?)
61HT Line Detection by ??-representation
A line in xy-plane is a point in ??-plane.
All lines passing through a point in xy-plane is
a curve in ?? -plane.
62HT Line Detection by ??-representation
A line in xy-plane is a point in ??-plane.
All lines passing through a point in xy-plane is
a curve in ?? -plane.
Given a point in xy-plane, we draw a curve in ??
-plane.
63HT Line Detection by ??-representation
A line in xy-plane is a point in ??-plane.
Given a point in xy-plane, we draw a curve in ??
-plane.
A line in xy-plane is then transformed in to a
set of curves in ?? -plane, which intersect at a
common point.
(?, ?)
64HT Line Detection by ??-representation
A line in xy-plane is a point in ??-plane.
Given a point in xy-plane, we draw a curve in ??
-plane.
A line in xy-plane is then transformed in to a
set of curves in ?? -plane, which intersect at a
common point.
65OpenCV Implementation ? Hough Line Transform
CvSeq cvHoughLines2( CvArr image, void
line_storage, int method, double rho,
double theta, int threshold, double param1
0, double param2 0 )
66ExampleHough Line Transform
Download Test Program
67Hough Circle Transform
Circle equation
image space
parameter space
68Hough Circle Transform
Cost ineffective time consuming
Circle equation
image space
parameter space
69Hough Gradient Method
Circle equation
Parametric form
image space
70Hough Gradient Method
The value of can be obtained from the edge
detection process.
Circle equation
Parametric form
image space
71Hough Gradient Method
Circle equation
- Quantize the parameter space for the parameters a
and b. - Zero the accumulator array M(a, b).
- Compute the gradient magnitude G(x, y) and angle
?(x, y). - For each edge (x0, y0) point in G(x, y),
increment all points in the accumulator array
M(a, b) along the line - Local maxima in the accumulator array correspond
to centers of circles in the image.
image space
72OpenCV Implementation ? Hough Circle Transform
CvSeq cvHoughCircles( CvArr image, void
circle_storage, int method, double dp,
double min_dist, double param1100, double
param2100 int min_radius0, int
max_radius0 )
73ExampleHough Circle Transform
Download Test Program
74Image Transforms
75Geometric Transforms ?Stretch, Shrink, Warp, and
Rotate
76Scaling , Rotation, Translation
Scaling
Rotation
Translation
77Scaling , Rotation Translation
Scaling
Translation
Rotation
Translation
Translation
78Homogeneous Coordinate
79Scaling , Rotation Translation
Scaling
2?3 matrix
Translation
Rotation
Translation
2?3 matrix
80Affine Transformation
- An affine transformation is any transformation
that can be expressed in the form of a matrix
multiplication followed by a vector addition. - In OpenCV the standard style of representing such
a transformation is as a 2-by-3 matrix.
2?3 matrix
81Affine Transformation
82GetAffineTransform
83Get Affine Transform
84Get 2D Rotation Matrix
85WarpAffine
86GetQuadrangleSubPix
87Example Affine Transform
Download Test Program
88GetQuadrangleSubPix
89Sparse Affine Transformation
90Perspective Transform
91Perspective Transform
92Perspective Transform
93Affine Transform vs. Perspective Transform
Affine Transform
Perspective Transform
94Get Perspective Transform
95WarpPerspective
96Sparse Perspective Transformation
97Image Transforms
98Graylevel Histogram of Image
99Goal of Histogram Equalization
100Goal of Histogram Equalization
Image Enhancement
101Method ? Graylevel Remapping
102Probability Theory
pdf
cdf
103Example Gaussian
104Example Gaussian
105Demonstration
106OpenCV Implementation
107Example
Download Test Program