330 likes | 343 Views
Last Time. Color Quantization Mach Banding Humans exaggerate sharp boundaries, but not fuzzy ones. Today. Homework 1 is due Box up front Dithering (Digital Halftoning). Dithering (Digital Halftoning). Mach bands can be removed by adding noise along the boundary lines
E N D
Last Time • Color Quantization • Mach Banding • Humans exaggerate sharp boundaries, but not fuzzy ones (C) University of Wisconsin 2002, CS 559
Today • Homework 1 is due • Box up front • Dithering (Digital Halftoning) (C) University of Wisconsin 2002, CS 559
Dithering (Digital Halftoning) • Mach bands can be removed by adding noise along the boundary lines • General perceptive principle: replaced structured errors with noisy ones and people complain less • Old industry dating to the late 1800’s • (Can’t say since the turn of the century!) • Methods for producing grayscale images in newspapers and books (C) University of Wisconsin 2002, CS 559
Dithering to Black-and-White • Black-and-white is still the preferred way of displaying images in many areas • Black ink is cheaper than color • Printing with black ink is simpler and hence cheaper • Paper for black inks is not special • To get color to black and white, first turn into grayscale: I=0.299R+0.587G+0.114B • This formula reflects the fact that green is more representative of perceived brightness than blue is (C) University of Wisconsin 2002, CS 559
Sample Images (C) University of Wisconsin 2002, CS 559
Threshold Dithering • For every pixel: If the intensity < 0.5, replace with black, else replace with white • 0.5 is the threshold • This is the naïve version of the algorithm • To keep the overall image brightness the same, you should: • Compute the average intensity over the image • Use a threshold that gives that average • For example, if the average intensity is 0.6, use a threshold that is higher than 40% of the pixels, and lower than the remaining 60% • For all dithering we will assume that the image is gray and that intensities are represented as 0-1.0 • If you have a 0-255 image, you can scale all the thresholds (multiply by 255) (C) University of Wisconsin 2002, CS 559
Naïve Threshold Algorithm (C) University of Wisconsin 2002, CS 559
Random Modulation • Add a random amount to each pixel before thresholding • Typically add uniformly random amount from [-a,a] • Pure addition of noise to the image • As stated above, we are adding uniformly random noise • For better results, add better quality noise • For instance, use Gaussian noise • Should use same procedure as before for choosing threshold • Not good for black and white, but OK for more colors • Add a small random color to each pixel before finding the closest color in the table (C) University of Wisconsin 2002, CS 559
Random Modulation (C) University of Wisconsin 2002, CS 559
Ordered Dithering • Break the image into small blocks • Define a threshold matrix • Use a different threshold for each pixel of the block • Compare each pixel to its own threshold • The thresholds can be clustered, which looks like newsprint • The thresholds can be “random” which looks better Threshold matrix (C) University of Wisconsin 2002, CS 559
Clustered Dithering 22 23 10 20 14 25 3 8 5 17 15 6 1 2 11 12 9 4 7 21 18 19 13 24 16 (C) University of Wisconsin 2002, CS 559
Dot Dispersion 2 16 3 13 10 6 11 7 4 14 1 15 12 8 9 5 (C) University of Wisconsin 2002, CS 559
Pattern Dithering • Compute the intensity of each sub-block and index a pattern • NOT the same as before • Here, each sub-block has one of a fixed number of patterns – pixel is determined only by average intensity of sub-block • In ordered dithering, each pixel is checked against the dithering matrix before being turned on (C) University of Wisconsin 2002, CS 559
Floyd-Steinberg Dithering • Start at one corner and work through image pixel by pixel • Usually scan top to bottom in a zig-zag • Threshold each pixel • Compute the error at that pixel: The difference between what should be there and what you did put there • Propagate error to neighbors by adding some proportion of the error to each unprocessed neighbor e 7/16 3/16 5/16 1/16 (C) University of Wisconsin 2002, CS 559
Floyd-Steinberg Dithering (C) University of Wisconsin 2002, CS 559
Color Dithering • All the same techniques can be applied, with some modification • Below is Floyd-Steinberg: Error is difference from nearest color in the color table, error propagation is the same (C) University of Wisconsin 2002, CS 559
Images as Signals • We can view images as a signal - a value that changes over space • Spatial domain: signal is given as values at points in space • Frequency Domain: signal is given as values of frequency components (C) University of Wisconsin 2002, CS 559
Why Signal Processing? • Reconstruction: • What happens when a monitor converts a set of points into a continuous picture? • How do we enlarge images? • Sampling: • How do we know how many pixels are required? • Jaggies, Aliasing • How do we avoid jagged, pixelated lines • Digital Signal Processing provides the tools (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 Function 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