Upload
others
View
1
Download
0
Embed Size (px)
Citation preview
Intro. Image Proc. & Python © S. Tanimoto Sampling
Introduction to Image Processing and Python--Image Representation: Sampling
Sampling
Steven L. Tanimoto
1
1Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
Key Issues in Image
• Image capture• Image representation• Image transformation• Image analysis• Image synthesis• Image data management
2
2Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
Key Issues in Image
• Image capture• Image representation• Image transformation• Image analysis• Image synthesis• Image data management
3
3Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
Digital Image Representation
When we want to capture a visual scene in a digital image, we face two fundamental questions:
1. How densely should our sample points be arranged? ("sampling")
2. How should each sample (e.g., color) be represented with number(s)? ("quantization")
4
4Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
Sampling
Density of samples (sampling rate or "frequency")Placement of samples (grid systems and alignment
or "phase")
Samples could represent very small regions or larger areas. This is an issue that the designers of digital cameras must consider.
We'll focus mainly on the concept of sampling rate.
5
5Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
Representing a Continuous Image
• Let’s call our original image or view to be represented our “picture.”
• The picture may be formed with a lens focusing light from a scene onto a surface.
• The picture might be a work of art created with watercolors on white artist’s paper.
• The picture is “continuous” in the sense that it has a color defined at every (infinitessimal) point within its boundaries.
6
6Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
Sampling
• Sampling means making a selection of points (samples) to represent the picture.
• Usually, the samples are organized with a grid.
7
7Saturday, August 24, 13
Pixels, Numbers, and Programs; © S. Tanimoto --
Sampling
Example
Photo of Lincoln Sample points Digitized
8
Steven Tanimoto 4/3/08if ((x+10) mod 20)+((y+10) mod 20) = 0 then 255 else s1(x,y)/2Is the formula used to produce the dots on the darkened version of the original.
8Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto 9
9Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
Sampling Rate
• How many samples per unit (distance or area for pictures, time for sound)
• For pictures, we will typically use distance, but the units might vary.
• Direct units: inches, centimeters• Indirect units: “width of the picture”• (If we are re-sampling a digital image) “old
pixel widths”.
10
10Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
How Many Samples is Enough?
• An important question because it relates to:• Perceived Image quality• Faithfulness in representing details• Cost of various kinds: • amount of memory required• time to download images from camera or
web.• time to process the image.
11
11Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
Oscillating Patterns
12
English Camp on San Juan Island, near Roche Harbor, WA.
S. Tanimoto
12Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
Oscillating Patterns
13
• We use a picket fence as an example of an oscillating pattern because it’s a clear case for teaching and learning – almost a caricature.
• In reality, there may be high-frequency oscillating patterns subtly embedded in the image.
• For example, any sharp edge in a scene contains high-frequency wavy patterns, but they may be invisible except at the edge due to interference elsewhere.
13Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
Consider the Picket Fence
To represent this "oscillation", a series of samples from left to right will need a sample on each picket and in each space between pickets.
14
14Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
Consider the Picket Fence
To represent this "oscillation", a series of samples from left to right will need a sample on each picket and in each space between pickets.
15
15Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
Nyquist Criterion
• Suppose that the most rapidly changing pattern changes at a rate of k cycles per unit distance.
• The Nyquist criterion says that we’ll need at least 2k samples per unit distance to represent this pattern.
• That’s a minimum of 2 samples per cycle.• (Also known as Shannon sampling or
Nyquist-Shannon sampling)
16
16Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
Aliasing
If the sampling rate is lower than the Nyquist rate, we won't have the true number of pickets showing. The oscillating pattern will seem to have a different (lower) frequency than the correct frequency. This is known as aliasing.
In graphics, the blocky character of diagonal or curved lines is also called aliasing.
Both forms of aliasing are due to insufficient resolution (i.e., sampling at too low a rate).
17
17Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
Aliased Pickets
original high-res image downsampled using 1 to 10 in each direction (horizontally and vertically)
s1(10*floor(x/10), 10*floor(y/10))
18
18Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
PixelMath example of aliasing:Moire effect with an artificial image
• Start with sin(x) --not visible in PixelMath• 128 * (1 + sin(x)) --visible but boring• Multiply x by 0.5 to widen the stripes (actually
waves)• Add a small component that is a nonlinear
function of y to get some curvature. y2 / 1000.• Final PixelMath formula to synthesize a pattern of
curved stripes: 128 * (1+ sin(x*0.5+y*y/1000))
19
19Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
source pattern of stripes
20
20Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
PixelMath example
Resample at every other pixel. Transformation formula: Source1(x*2, y*2) Aliasing is not a problem at this rate.
21
21Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
S1(x*2, y*2)
22
22Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
PixelMath example
• Resample with a rate that is too low to capture the highest frequency oscillation.
• Take every 10th pixel in each direction• Transformation formula: Source1(x*10, y*10)
23
23Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
destination (shrunk)
24
24Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
destination (blowup)
The aliasing here is so bad that some of the curves bend in a completely different direction.
25
25Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
One Dimensional Case
Square wave and sine wave. Shown are 4 cycles of each. Here y is a function of x.
26
26Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
1D Case (cont.)
27
27Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
Sums of Sinusoids
• An arbitrary function y = f(x) can be expressed as a sum of sinusoids.∗
• * The functions must be “smooth” and bounded.
28
28Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
Adding Sinusoids
http://www.udel.edu/idsardi/sinewave/sinewave.html
29
magenta = red + blue
29Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
The “Nyquist Rate”
• Let g(x) be a signal to be sampled.• Let fh be the highest frequency component
in g(x)• The Nyquist rate fr = 2 fh is a lower bound
on the sampling frequency needed to accurately represent g(x).
• We actually must sample at a frequency higher (at least slightly higher) than fr to capture g(x)
30
30Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
The “Nyquist Frequency”
• Let fs be a chosen sampling frequency.• The frequency fN = fs / 2 is the Nyquist
frequency.• The Nyquist frequency is an upper bound on
the frequency of any oscillation in g(x) that is to be accurately represented in the sampling result.
• Note that fr < 2 fN
• Thus, fr / 2 < fN
31
31Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
The Shannon-Nyquist Theorem
• Let g(x) be a continuously varying function whose highest frequency component, at fB satisfies 2 fB < fs, the chosen sampling frequency.
• Then the samples obtained by sampling g(x) using sampling frequency fs uniquely determine g(x).
• That is, it’s theoretically possible to exactly reconstruct g(x) from the samples.
32
32Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
Nyquist freq., rate, etc.
33
33Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
Assumptions
• g(x) truly is bandlimited to fB.• The samples are perfectly accurate.• The reconstruction is perfect.In practice, none of these is really true.However, the theorem does guide us to the
correct sampling rates for pretty darn accurate (though not perfect) representations.
34
34Saturday, August 24, 13
SamplingIntro. Image Proc. & Python © S. Tanimoto
Conclusion
To avoid aliasing, use a sampling rate that allows more than two samples (pixel) per cycle of the highest-frequency oscillation in the image.
Or, prior to sampling, remove (using filtering) components at frequencies more than half the sampling frequency.
35
35Saturday, August 24, 13