300 likes | 395 Views
Last Time. Color Quantization Dithering. Today. Signal processing for graphics Homework 2 is available Project 2 is almost available. Enlarging an Image. To enlarge an image, you have to add pixels between the old pixels What values do you choose for those pixels?.
E N D
Last Time • Color Quantization • Dithering (C) University of Wisconsin 2002, CS 559
Today • Signal processing for graphics • Homework 2 is available • Project 2 is almost available (C) University of Wisconsin 2002, CS 559
Enlarging an Image • To enlarge an image, you have to add pixels between the old pixels • What values do you choose for those pixels? (C) University of Wisconsin 2002, CS 559
Images as Samples of Functions • We can view an image as a set of samples from an ideal function • This is particularly true if we are plotting a function, but it is also the case that a digital photograph is a sample of some function • If we knew what the function was, we could enlarge the image by resampling the function • Failing that, we can reconstruct the function and then resample it (C) University of Wisconsin 2002, CS 559
Why Signal Processing? • Signal processing provides the tools for understanding sampling and reconstruction • Sampling: • How do we know how many pixels are required, and where to place them? • Reconstruction: • What happens when a monitor converts a set of points into a continuous picture? • How do we enlarge, reduce, rotate, smooth or enhance images? • Jaggies, Aliasing • How do we avoid jagged, pixelated lines (C) University of Wisconsin 2002, CS 559
A Striking Example (C) University of Wisconsin 2002, CS 559
Periodic Functions • Fact: Any periodic signal can be represented as a sum of sine and cosine waves with harmonic frequencies • If one function has frequency f, then its harmonics are function with frequency nf for integer n • Sequence of boxes is: (C) University of Wisconsin 2002, CS 559
Boxes as Sum of Cosines (C) University of Wisconsin 2002, CS 559
General Functions • A non-periodic function can be represented as a sum of sin’s and cos’s of (possibly) all frequencies: • F() is the spectrum of the function f(x) • The spectrum is how much of each frequency is present in the function • We’re talking about functions, not colors, but the idea is the same (C) University of Wisconsin 2002, CS 559
Fourier Transform • F() is computed from f(x) by the Fourier Transform: (C) University of Wisconsin 2002, CS 559
Example: Box Function (C) University of Wisconsin 2002, CS 559
Box Function and Its Transform (C) University of Wisconsin 2002, CS 559
Cosine and Its Transform -1 1 If f(x) is even, so is F() (C) University of Wisconsin 2002, CS 559
Sine and Its Transform -1 1 - If f(x) is odd, so is F() (C) University of Wisconsin 2002, CS 559
Constant Function and Its Transform The constant function only contains the 0th frequency – it has no wiggles (C) University of Wisconsin 2002, CS 559
Delta Function and Its Transform Fourier transform and inverse Fourier transform are qualitatively the same, so knowing one direction gives you the other (C) University of Wisconsin 2002, CS 559
Shah (Spikes) and Its Transform (C) University of Wisconsin 2002, CS 559
Gaussian and Its Transform (the same) (C) University of Wisconsin 2002, CS 559
Qualitative Properties • The spectrum of a functions tells us the relative amounts of high and low frequencies • Sharp edges give high frequencies • Smooth variations give low frequencies • A function is bandlimited if its spectrum has no frequencies above a maximum limit • sin, cos are band limited • Box, Gaussian, etc are not (C) University of Wisconsin 2002, CS 559
Functions to Images • Images are 2D, discrete functions • 2D Fourier transform uses product of sin’s and cos’s (things carry over naturally) • Fourier transform of a discrete, quantized function will only contain discrete frequencies in quantized amounts • In particular, we can store the Fourier transform of a discrete image in the same amount of space as we can store the image • Numerical algorithm: Fast Fourier Transform (FFT) computes discrete Fourier transforms (C) University of Wisconsin 2002, CS 559
Filters • A filter is something that attenuates or enhances particular frequencies • Easiest to visualize in the frequency domain, where filtering is defined as multiplication: • Here, F is the spectrum of the function, G is the spectrum of the filter, and H is the filtered function. Multiplication is point-wise (C) University of Wisconsin 2002, CS 559
Qualitative Filters F G H Low-pass = High-pass = Band-pass = (C) University of Wisconsin 2002, CS 559
Low-Pass Filtered Image (C) University of Wisconsin 2002, CS 559
High-Pass Filtered Image (C) University of Wisconsin 2002, CS 559
Filtering in the Spatial Domain • Filtering the spatial domain is achieved by convolution • Qualitatively: Slide the filter to each position, x, then sum up the function multiplied by the filter at that position (C) University of Wisconsin 2002, CS 559
Convolution Example (C) University of Wisconsin 2002, CS 559
Convolution Theorem • Convolution in the spatial domain is the same as multiplication in the frequency domain • Take a function, f, and compute its Fourier transform, F • Take a filter, g, and compute its Fourier transform, G • Compute H=FG • Take the inverse Fourier transform of H, to get h • Then h=fg • Multiplication in the spatial domain is the same as convolution in the frequency domain (C) University of Wisconsin 2002, CS 559
Filtering Images • Work in the discrete spatial domain • Convert the filter into a matrix, the filter mask • Move the matrix over each point in the image, multiply the entries by the pixels below, then sum • eg 3x3 box filter • averages (C) University of Wisconsin 2002, CS 559
Box Filter • Box filters smooth by averaging neighbors • In frequency domain, keeps low frequencies and attenuates (reduces) high frequencies, so clearly a low-pass filter Spatial: Box Frequency: sinc (C) University of Wisconsin 2002, CS 559
Filtering Algorithm • If Iinput is the input image, and Ioutput is the output image, M is the filter mask and k is the mask size: • Care must taken at the boundary • Make the output image smaller • Extend the input image in some way (C) University of Wisconsin 2002, CS 559