Uploaded by Muhammad Shahan Abbas

02 Sampling Quantization Interpolation

advertisement
National University of Sciences and
Technology (NUST)
School of Electrical Engineering and Computer Science
(SEECS)
Digital Image Processing
1
Khawar Khurshid
Sampling
Quantization
Interpolation
2
Khawar Khurshid
Sampling and Quantization
Sampling:
Digitization of the spatial coordinates (x,y)
Quantization:
Digitization in amplitude (also known as gray
level quantization)
• 8 bit quantization: 28 =256 gray levels
(0: black, 255: white)
• 1 bit quantization: 21 = 2 gray levels
(0: black, 1: white)
3
Khawar Khurshid
Sampling
4
Khawar Khurshid
Sampling
5
Khawar Khurshid
Quantization – (Example)
Return change using only
these notes
6
Khawar Khurshid
Quantization – (Example)
Return 5
For Rs. 7
Return 5
For Rs. 9
Return 10
For Rs. 12
Return 10
For Rs. 23 Return 25
…
…
45
Change you return
For Rs. 3
50
40
35
30
25
20
15
10
5
0
0
5
10
15
20
25
30
35
40
45
50
Actual change
7
Khawar Khurshid
Discrete color output
Quantization – (Example)
Continuous colors mapped to a
finite, discrete set of colors.
Continuous color input
8
Khawar Khurshid
16 colors
16 million colors
Quantization – (Example)
9
Khawar Khurshid
Sampling and Quantization
Pixel Grid
Real Image
10
Sampled
Quantized
Sampled &
Quantized
Khawar Khurshid
Sampling and Quantization
11
Khawar Khurshid
Sampling and Quantization
12
Khawar Khurshid
Sampling and Quantization
256x256
256 gray levels
128x128
64x64
16 gray levels
8 gray levels
4 gray levels
13
32x32
Binary Image
Khawar Khurshid
Interpolation
14
Khawar Khurshid
Interpolation
Why?
•
•
•
•
15
Changing Perspective
Rotation
Resizing
Warping
Khawar Khurshid
Nearest Neighbor Replacement
Simply Replicate the value from neighboring
pixels.
1
1
1
16
0
1
0
1
0
1
1
0
1
1
1
0
1
0
1
Khawar Khurshid
Nearest Neighbor Replacement
Adds blocky effect.
1
1
1
17
0
1
0
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
1
1
1
0
0
0
0
1
1
1
0
0
0
0
1
1
1
0
0
1
1
0
0
0
1
1
1
1
0
0
0
1
1
Khawar Khurshid
1-D Interpolation
Interpolation works by using known data to
estimate values at unknown points.
18
Khawar Khurshid
1-D Interpolation
Linear Interpolation: Fit a linear function piecewise
between the points.
19
Khawar Khurshid
1-D Interpolation
Quadratic: Fit a Quadratic Polynomial between the three
points.
20
Khawar Khurshid
1-D Interpolation
Fitting Polynomial to data points.
21
Khawar Khurshid
1-D Interpolation
Degree
Polynomial
Zero
Polynomial
f(x) = 0
22
Req. Pts.
None
f(x) = a0
horizontal line
with y-intercept
a0
1
1 (Linear)
f(x) = a0 + a1x
an oblique line
with y-intercept
a0 and slope a1
2
2
(Quadratic)
f(x) = a0 + a1x + a2x2
3 (Cubic)
f(x) = a0 + a1x + a2x2+
a3x3
0
•
•
•
•
How it looks
Parabola
3
4
Spline
No. of unknowns in a polynomial of degree n-1 = n
Select n nearest known neighbours to generate n equations
Solve the linear system of equations to estimate the constants
Simply put the unknown x value and interpolate the y value
Khawar Khurshid
Linear Interpolation
• Equation of a line
y1 − y0
(x − x0 ) + y0
y=
x1 − x0
• Interpolation using Linear Polynomial
–
–
23
y = a0 + a1x
Requires two unknowns
Khawar Khurshid
Bi-linear Interpolation
• Key Points:
– Q11 = (x1, y1), Q12 = (x1, y2),
– Q21 = (x2, y1), Q22 = (x2, y2).
• Linear interpolation in the xdirection followed by linear
interpolation in y-direction
24
Khawar Khurshid
Interpolation
Nearest Neighbor
Bi-Linear
25
Khawar Khurshid
Interpolation
215
128
26
Khawar Khurshid
Interpolation
27
Khawar Khurshid
Interpolation – (Comparison)
We’ll enlarge this image
by a factor of 4 …
… via bilinear interpolation
and compare it to a nearest
neighbor enlargement.
28
Khawar Khurshid
Interpolation – (Comparison)
Original
Image
To better see what happens, we’ll look at the parrot’s eye.
29
Khawar Khurshid
Interpolation – (Comparison)
Pixel replication
30
Bilinear interpolation
Khawar Khurshid
Interpolation – (Comparison)
Pixel replication
31
Bilinear interpolation
Khawar Khurshid
Interpolation – (Non Integer)
Zoom in on a
section for a
closer look at
the process
Example:
resize to 3/7
of the original
32
Khawar Khurshid
Interpolation – (Non Integer)
3/7 resize
Zoom in for a
better look
33
Khawar Khurshid
Interpolation – (Non Integer)
3/7 resize
Outlined in
blue: 7x7
pixel squares
34
Khawar Khurshid
Interpolation – (Non Integer)
3/7 resize
In yellow: 3 pixels
for every 7 rows,
3 pixels for every
7 cols.
35
Khawar Khurshid
Interpolation – (Non Integer)
3/7 resize
Keep the
highlighted
pixels…
36
Khawar Khurshid
Interpolation – (Non Integer)
3/7 resize
… don’t keep
the others.
37
Khawar Khurshid
Interpolation – (Non Integer)
3/7 resize
Copy them into
a new image.
38
Khawar Khurshid
Interpolation – (Non Integer)
3/7 resize
Copy them into
a new image.
39
Khawar Khurshid
Interpolation – (Non Integer)
3/7 times the
linear dimensions
of the original
40
Khawar Khurshid
Interpolation – (Non Integer)
Original
image
Detail of
resized image
Resize to 3/7 of
the original dims.
41
Khawar Khurshid
Interpolation – (Non Integer)
7/3 resize
Original
image
42
Pixels spread out
for a 7/3 resize …
… then filled in.
Khawar Khurshid
Interpolation – (Non Integer)
7/3 resize
Each 3x3 block
of pixels from
here …
Original
image
43
… is spread out over
a 7x7 block here
Detail
Khawar Khurshid
Interpolation – (Non Integer)
7/3 resize
3x3 blocks
distributed over
7x7 blocks
44
Khawar Khurshid
Interpolation – (Non Integer)
7/3 resize
Empty pixels filled
with color from nonempty pixel
45
Khawar Khurshid
Interpolation – (Non Integer)
7/3 resize
Empty pixels filled
with color from nonempty pixel
46
Khawar Khurshid
Interpolation – (Non Integer)
Original
image
47
7/3 resized
Khawar Khurshid
Interpolation
•
Non-adaptive algorithms
– Examples
• nearest neighbour, bilinear, bicubic, spline etc.
– Depending on their complexity, these use anywhere from 0 to 256 (or more)
adjacent pixels when interpolating.
– The more adjacent pixels they include, the more accurate they can become,
but this comes at the expense of much longer processing time.
– These algorithms can be used to both distort and resize a photo
•
Adaptive algorithms
– Many of these apply a different version of their algorithm (on a pixel-bypixel basis) when they detect the presence of an edge-- aiming to minimize
unsightly interpolation artifacts in regions where they are most apparent.
– These algorithms are primarily designed to maximize artifact-free detail in
enlarged photos, so some cannot be used to distort or rotate an image.
48
Khawar Khurshid
End
Sampling, Quantization,
Interpolation
49
Khawar Khurshid
Download