Digital Image Processing COSC 638/4393 Lecture 9 Sept 26 th, 217 Pranav Mantini Slides from Dr. Shishir K Shah and Frank (Qingzhong) Liu, S. Narasimhan
HISTOGRAM SHAPING We now describe methods for histogram shaping. Accomplished by point operations: object shape and location are unchanged. 2
EXAMPLE Given a 4 x 4 image I with gray-level range {,..., 15} (K-1 = 15): It's histogram is 3
EXAMPLE The normalized histogram is k 1 2 3 4 5 6 7 8 9 1 11 12 13 14 15 3 16 3 16 3 16 2 16 2 16 p(k) From which we can compute the intermediate image J1 and finally the "flattened" image J: 2 16 1 16 4
EXAMPLE The new, flattened histogram looks like this: The heights H(k) cannot be reduced, just moved - or stacked, so: Digital histogram flattening doesn't really "flatten" the histogram - it just makes it "flatter" by spreading out the histogram. The spaces that appear are highly characteristic of a "flattened" histogram - especially when the original histogram is highly compressed. 5
Histogram Shaping Consider the same image as in the last example. We had Fit this to the following (triangular) histogram: 6
EXAMPLE Here's the cumulative (summed) probabilities associated with it: n 1 2 3 4 5 6 7 8 9 1 11 12 13 14 15 P (n) J 1 16 1 16 3 16 3 16 6 16 6 16 1 16 1 16 13 16 13 16 15 16 15 16 16 16 16 16 Careful visual inspection of J 1 let's us form the new image: 7
EXAMPLE Here's the new histogram: 8
BASIC ALGEBRAIC IMAGE OPERATIONS Algebraic image operations (between images) are quite simple Suppose we have two N x N images I 1 and I 2. The four basic algebraic operations (like the ones on your calculator) are: Pointwise Matrix Addition J = I 1 + I 2 if J(i, j) = I 1 (i, j) + I 2 (i, j) for <= i, j <= N-1 Pointwise Matrix Subtraction J = I 1 - I 2 if J(i, j) = I 1 (i, j) - I 2 (i, j) for <= i, j <= N-1 Pointwise Matrix Multiplication J = I 1.* I 2 if J(i, j) = I 1 (i, j) x I 2 (i, j) for <= i, j <= N-1 Pointwise Matrix Division J = I 1./ I 2 if J(i, j) = I 1 (i, j) / I 2 (i, j) for <= i, j <= N-1 9
Frame Averaging However, since I 1 = I 2 = = I M = I, then and from before Hence we can expect that J ~= I + ~= I if enough frames (M) are averaged together 1
Motion Detection Often it is of interest to detect object motion between frames Applications: video compression, target recognition and tracking, security cameras, surveillance, automated inspection, etc. Here is a simple approach: Let I 1, I 2 be consecutive frames taken in close time proximity, e.g., from a video camera Form the absolute difference image J = I 1 - I 2 Applying a full-scale contrast stretch to J will give a more visually dramatic result 11
The Basic Geometric Transformations The most basic geometric transformations are - Translation - Rotation - Zooming Translation Translation is the simplest geometric operation and requires no interpolation Let a(i, j) = i - i, b(i, j) = j - j where (i, j ) are constants In this case J(i, j) = I(i - i, j - j ); a shift or translation of the image by an amount i in the vertical (row) direction and an amount j in the horizontal direction 12
Frequency domain analysis and Periodic Function Fourier Transform What are the frequencies in the function? Is a certain frequency more common or dominant than other????
Jean Baptiste Joseph Fourier (1768-183) Had crazy idea (187): Any periodic function can be rewritten as a weighted sum of Sines and Cosines of different frequencies. Don t believe it? Neither did Lagrange, Laplace, Poisson and other big wigs Not translated into English until 1878! But it s true! called Fourier Series Possibly the greatest tool used in Engineering
Time and Frequency example : g(t) = sin( f t) + (1/3)sin( (3f) t)
Time and Frequency example : g(t) = sin(2pi f t) + (1/3)sin(2pi (3f) t) = +
Frequency Spectra example : g(t) = sin(2pi f t) + (1/3)sin(2pi (3f) t) = +
Periodic Function 4π 6π Sum of sine and cosine waves:
Periodic Function 4π 6π Sum of sine and cosine waves: f t = a + a 1 cos t + a 2 cos 2t + b 1 sin t + b 2 sin 2t +
Recap න sin mt dt=? cos mt dt=? sin mt cos nt dt =? sin mt sin nt dt =? ( m! = n) sin mt sin nt dt =? (m = n) cos mt cos nt dt =? ( m! = n) cos mt cos nt dt =? (m = n)
Recap sin mt dt= cos mt dt= න sin mt cos nt dt = sin mt sin nt dt =? ( m! = n) sin mt sin nt dt =? (m = n) cos mt cos nt dt =? ( m! = n) cos mt cos nt dt =? (m = n)
Recap sin mt dt= cos mt dt= න sin mt cos nt dt = න sin mt sin nt dt = m! = n න sin mt sin nt dt = π (m = n) න cos mt cos nt dt = ( m! = n) න cos mt cos nt dt = π(m = n)
Periodic Function 4π 6π Sum of sine and cosine waves: f t = a + a 1 cos t + a 2 cos 2t + b 1 sin t + b 2 sin 2t +
Periodic Function Sum of sine and cosine waves: න f(t)dt = න න a dt 4π 6π + න b 1 sin(t)dt a 1 cos t dt + න + න b 2 sin(2t)dt a 2 cos 2t dt + +
Periodic Function Sum of sine and cosine waves: න 4π 6π f(t)dt = න a dt = a a = 1 f(t)dt
Periodic Function 4π 6π Sum of sine and cosine waves: f t cos(nt) = a cos(nt) + a 1 cos t cos(nt) + a 2 cos 2t cos(nt) + b 1 sin t cos(nt) + b 2 sin 2t cos(nt) +
Periodic Function Sum of sine and cosine waves: න = න f t cos nt dt a cos nt dt + න න 4π 6π a 1 cos t cos nt dt + න b 1 sin t cos nt dt + න a 2 cos 2t cos nt dt + b 2 sin 2t cos nt dt +
Periodic Function Sum of sine and cosine waves: න = න + න න f t cos nt dt a cos nt dt + න 4π 6π a 2 cos 2t cos nt dt + න b 1 sin t cos nt dt + න a 1 cos t cos nt dt a n cos nt cos nt dt + b 2 sin 2t cos nt dt +
Periodic Function 4π 6π Sum of sine and cosine waves: න f t cos nt dt = a n = 1 π න න a n cos nt cos nt dt f t cos nt dt Similarly, b n = 1 π න f t sin nt dt
Periodic Function 4π 6π Sum of sine and cosine waves: a = 1 න a n = 1 π න f(t)dt f t cos nt dt b n = 1 π න f t sin nt dt
Periodic Function Sum of sine and cosine waves: b n = 1 π a = 1 a n = 1 π 4π 6π f(t)dt = 1/2 f t cos nt dt = if n is even f t sin nt dt = 2 if n is odd nπ
Frequency Spectra
Frequency Spectra = + =
Frequency Spectra = + =
Frequency Spectra = + =
Frequency Spectra = + =
Frequency Spectra = + =
Frequency Spectra = A k 1 1 sin(2 kt ) k
Complex number trick For every frequency n, there are two components a n andb n (cos component and sine component) Represented using complex numbers. A F( ) R( ) ii ( ) R I 2 2 ( ) ( ) tan 1 I( ) R( )
Fourier Transform We want to understand the frequency u of our signal. So, let s reparametrize the signal by n instead of x: f(x) Fourier Transform F(u) Represent the signal as an infinite weighted sum of an infinite number of sinusoids F u = න e ik f x = න cos k cos ux dx j න f x isin k Spatial Domain (x) f x cos ux j sin ux dx i 1 sin ux dx Note: F u f x iux dx Frequency Domain (u) (Frequency Spectrum F(u)) e
Inverse Fourier Transform (IFT) Frequency Domain (u) Spatial Domain (x) f x 1 2 F u e iux dx
Sinusoidal Images We shall make frequent discussion in this module of the frequency content of an image. First consider images having the simplest frequency content. A digital sine image I is an image having elements and a digital cosine image has elements where u and v are integer frequencies in the i- and j- directions (measured in cycles/image; notice division by N). 43
Sinusoidal Images sin(i + j) sin(i +.5j) sin(.5i +.5j) Waveform Contour plots From Wolframalpha
Sinusoidal Images sin(i + j) sin(i +.5j) sin(.5i +.5j) Waveform Contour plots From Wolframalpha
Sinusoidal Images sin(i + j) sin(i +.5j) sin(.5i +.5j) Waveform Contour plots From Wolframalpha
Sinusoidal Images sin(i + j) sin(i +.5j) sin(.5i +.5j) Waveform Contour plots From Wolframalpha
Sinusoidal Images The radial frequency (how fast the image oscillates in its direction of propagation) is The angle of the wave (relative to the i-axis) is 48
Complex Exponential Images We will need to use complex exponential functions to later define the Fourier Transform of a digital image. We define the 2-D complex exponential function to be The complex exponential allows convenient representation and manipulation of frequencies, as we will see. 49
Complex Numbers Review of Notation A number of the form X = A + B is a complex number. Complex numbers have a magnitude and a phase -1 Complex numbers conveniently represent magnitude and phase: The complex conjugate of X is: X* = A - -1 B Observe that 5
Properties of Complex Exponential We will use the abbreviation for the complex exponential image, where N = size of the image. Hence the complex exponential From Euler's identity: 51
Properties of Complex Exponential Indexing the powers of the component sinusoids. (ui vj) W + N indexes the frequencies of 52
Magnitude and Phase of Complex Exponential The magnitude and phase of (ui vj) W + N Comments It is possible to develop Fourier transform (frequency domain) concepts without complex numbers - but the mathematics becomes much lengthier. (ui vj) Using W + N to represent a frequency component oscillating at u (cy/im) and v (cy/im) in the i- and j-directions simplifies things considerably. (ui vj) Thus, it is useful to think of W + N in that way: a representation of a direction and frequency of oscillation. 53
Values of Complex Exponential The complex exponential is a representation of frequency indexed by exponent ui. The minimum physical frequency periodically occurs at index u = kn (including u = ): The maximum physical frequency periodically occurs at index u = kn + N/2 (N is even): This will be important when we consider the meaning of the Fourier Transform. 54
Discrete Fourier Transform Abbreviated as DFT. Discrete Fourier Expansion of an Image Any N x N image I can be expressed as the weighted sum of a finite number of complex exponential images: A unique representation of an image as a finite weighted sum of complex exponentials of different frequencies. The weights are unique. Given only the elements (the DFT coefficients) one can compute I(i, j) from them. Remember that (i, j) are space coordinates while (u, v) are frequency coordinates. We can obtain the DFT coefficients from I: 55