Last Time Dithering Threshold Brightness preserving threshold Random
Last Time • Dithering – – – Threshold Brightness preserving threshold Random modulation Ordered dithering – clustered, dispersed Pattern dithering Floyd-Steinberg • Introduction to signal processing – – 9/23/04 Fourier transform Some important transforms High-Frequency Sharp Edges Low Frequency Smooth variation © University of Wisconsin, CS 559 Spring 2004
Today • Filtering • Resampling 9/23/04 © University of Wisconsin, CS 559 Spring 2004
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 9/23/04 © University of Wisconsin, CS 559 Spring 2004
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 9/23/04 © University of Wisconsin, CS 559 Spring 2004
Qualitative Filters F 9/23/04 G H = Low-pass = High-pass = Band-pass © University of Wisconsin, CS 559 Spring 2004
Low-Pass Filtered Image 9/23/04 © University of Wisconsin, CS 559 Spring 2004
High-Pass Filtered Image 9/23/04 © University of Wisconsin, CS 559 Spring 2004
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 9/23/04 © University of Wisconsin, CS 559 Spring 2004
Convolution Example Result Filter 9/23/04 Function © University of Wisconsin, CS 559 Spring 2004
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=F G Take the inverse Fourier transform of H, to get h Then h=f g • Multiplication in the spatial domain is the same as convolution in the frequency domain 9/23/04 © University of Wisconsin, CS 559 Spring 2004
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 3 x 3 box filter – Effect is averaging 9/23/04 © University of Wisconsin, CS 559 Spring 2004
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 9/23/04 Frequency: sinc © University of Wisconsin, CS 559 Spring 2004
Box Filter 9/23/04 © University of Wisconsin, CS 559 Spring 2004
Handling Boundaries • At (0, 0) for instance, you might need pixel data for (-1, -1), which doesn’t exist • Option 1: Make the output image smaller – don’t evaluate pixels you don’t have all the input for • Option 2: Replicate the edge pixels – Equivalent to: posn = x + i; if ( posn < 0 ) posn = 0; and so on for other indices • Option 3: Reflect image about edge – Equivalent to: posn = x + i; if ( posn < 0 ) posn = -posn; and similar for others 9/23/04 © University of Wisconsin, CS 559 Spring 2004
Bartlett Filter • Triangle shaped filter in spatial domain • In frequency domain, product of two box filters, so attenuates high frequencies more than a box Spatial: Triangle (Box Box) 9/23/04 Frequency: sinc 2 © University of Wisconsin, CS 559 Spring 2004
Constructing Masks: 1 D • Sample the filter function at matrix “pixels”, then normalize • eg 2 D Bartlett 1 5 0 1 1 3 1 2 • Can go to edge of pixel or middle of next: results are slightly different 0 9/23/04 1 2 1 4 © University of Wisconsin, CS 559 Spring 2004 1 2 1
Constructing Masks: 2 D • Multiply 2 1 D masks together using outer product 0. 2 0. 6 0. 2 • M is 2 D mask, m is 1 D mask 0. 2 0. 04 0. 12 0. 04 0. 6 0. 12 0. 36 0. 12 0. 04 9/23/04 © University of Wisconsin, CS 559 Spring 2004
Bartlett Filter 9/23/04 © University of Wisconsin, CS 559 Spring 2004
Gaussian Filter • Attenuates high frequencies even further • In 2 d, rotationally symmetric, so fewer artifacts 9/23/04 © University of Wisconsin, CS 559 Spring 2004
Gaussian Filter 9/23/04 © University of Wisconsin, CS 559 Spring 2004
Constructing Gaussian Mask • Use the binomial coefficients – Central Limit Theorem (probability) says that with more samples, binomial converges to Gaussian 1 64 9/23/04 1 1 16 1 4 6 4 1 1 6 15 20 15 6 2 1 1 3 3 1 1 4 6 4 1 1 © University of Wisconsin, CS 559 Spring 2004
High-Pass Filters • A high-pass filter can be obtained from a low-pass filter – If we subtract the smoothed image from the original, we must be subtracting out the low frequencies – What remains must contain only the high frequencies • High-pass masks come from matrix subtraction: • eg: 3 x 3 Bartlett 9/23/04 © University of Wisconsin, CS 559 Spring 2004
High-Pass Filter 9/23/04 © University of Wisconsin, CS 559 Spring 2004
Edge Enhancement • High-pass filters give high values at edges, low values in constant regions • Adding high frequencies back into the image enhances edges • One approach: – Image = Image + [Image – smooth(Image)] Low-pass High-pass 9/23/04 © University of Wisconsin, CS 559 Spring 2004
Edge-Enhance Filter 9/23/04 © University of Wisconsin, CS 559 Spring 2004
Edge Enhancement 9/23/04 © University of Wisconsin, CS 559 Spring 2004
Fixing Negative Values • The negative values in high-pass filters can lead to negative image values – Most image formats don’t support this • Solutions: – Truncate: Chop off values below min or above max – Offset: Add a constant to move the min value to 0 – Re-scale: Rescale the image values to fill the range (0, max) 9/23/04 © University of Wisconsin, CS 559 Spring 2004
Filtering and Color • To filter a color image, simply filter each of R, G and B separately • Re-scaling and truncating are more difficult to implement: – Adjusting each channel separately may change color significantly – Adjusting intensity while keeping hue and saturation may be best, although some loss of saturation is probably OK 9/23/04 © University of Wisconsin, CS 559 Spring 2004
Resampling • Making an image larger is like sampling the original function at higher density – You need more pixels to represent the same thing, so a higher pixel density Original More samples Original spacing = bigger • Reducing an image in size is like sampling at lower density • Generating new samples of the “same” function is called resampling – In theory, 2 steps: Reconstruction and sampling – but not in practice • Many other image manipulation tasks require resampling 9/23/04 © University of Wisconsin, CS 559 Spring 2004
General Scenario • You are trying to create a new image of some form, and you need data from a particular place in the existing image – Always: Figure out where the new sample comes from in the original image Original 9/23/04 © University of Wisconsin, CS 559 Spring 2004 New
Resampling at a Point • We want to reconstruct the original “function” at the required point • We will use information from around the point to do this • We do it using a filter – We will justify this shortly • Which filter? ? – We’ll look at Bartlett (triangular) – Other filters also work • You might view this as interpolation, but to understand what’s happening, we’ll view it as filtering Use these to reconstruct 9/23/04 © University of Wisconsin, CS 559 Spring 2004
Resampling at a Point • Place a Bartlett filter at the required point • Multiply the value of the neighbor by the filter at that point, and add them – Convolution with discrete samples • The filter size is a parameter • Say the filter is size 3, and you need the value at x=5. 75 – You need the image samples, I(x), from x=5, x=6 and x=7 – You need the filter value, H(s), at s=-0. 75, s=0. 25 and s=1. 25 – Compute: I(5)*H(-0. 75)+I(6)*H(0. 25)+I(7)*H(1. 25) 9/23/04 © University of Wisconsin, CS 559 Spring 2004
Project 1 • Due Oct 18 • Implement a basic image editing program – Photoshop lite – The web site is long and detailed – Look for hints and notes on implementation on the web site • Start early: you have enough information to implement several operations already • Keep an eye out for hints and clarifications on the class mailing list 9/23/04 © University of Wisconsin, CS 559 Spring 2004
Project 1 Grading • Read very carefully the requirements for grading – We will compile and run your program automatically – We will look at the output individually – We will not tolerate programs that don’t compile or run • The aim is to implement 100 points worth of options – Different options have different point values – Some options are harder than others – The value of some options depends on whether you do other, similar options • You may work in pairs, in which case the aim is 200 points – Both people must independently email cs 559 -1 9/23/04 © University of Wisconsin, CS 559 Spring 2004
- Slides: 34