Introduction to Computer Vision Introduction Zhigang Zhu, City College of New York CSc I6716 Spring 2012 Image Enhancement Part I Feature Extraction (1)
Introduction to Computer Vision What are Image Features? n Local, meaningful, detectable parts of the image.
Introduction to Computer Vision More Color Woes Squares with dots in them are the same color
Introduction to Computer Vision Topics n Image Enhancement l Brightness mapping l Contrast stretching/enhancement l Histogram modification l Noise Reduction l ……... n Mathematical Techniques l Convolution l Gaussian Filtering n Edge and Line Detection and Extraction n Region Segmentation n Contour Extraction n Corner Detection
Introduction to Computer Vision Image Enhancement n Goal: improve the ‘visual quality’ of the image l for human viewing l for subsequent processing n Two typical methods l spatial domain techniques.... u operate directly on image pixels l frequency domain techniques.... u operate on the Fourier transform of the image n No general theory of ‘visual quality’ l General assumption: if it looks better, it is better l Often not a good assumption
Introduction to Computer Vision Spatial Domain Methods n Transformation T l point - pixel to pixel l area - local area to pixel l global - entire image to pixel n Neighborhoods l typically rectangular l typically an odd size: 3x3, 5x5, etc l centered on pixel I(x,y) n Many IP algorithms rely on this basic notion T(I(x,y)) I(x,y)I’(x,y)neighborhood N I’(x,y) = T(I(x,y)) O=T(I)
Introduction to Computer Vision Point Transforms: General Idea O = T(I) Input pixel value, I, mapped to output pixel value, O, via transfer function T INPUT OUTPUT Transfer Function T
Introduction to Computer Vision Grayscale Transforms n Photoshop ‘adjust curve’ command Input gray value I(x,y) Output gray value I’(x,y)
Introduction to Computer Vision Point Transforms: Brightness
Introduction to Computer Vision Point Transforms:Thresholding n T is a point-to-point transformation l only information at I(x,y) used to generate I’(x,y) n Thresholding I max if I(x,y) > t I min if I(x,y) ≤ t I’(x,y) = t=89 t2550 0
Introduction to Computer Vision Point Transforms: Linear Stretch INPUT OUTPUT
Introduction to Computer Vision Linear Scaling n Consider the case where the original image only utilizes a small subset of the full range of gray values: n New image uses full range of gray values. n What's F? {just the equation of the straight line}
Introduction to Computer Vision Linear Scaling n F is the equation of the straight line going through the point (I min, 0) and (I max, K) n useful when the image gray values do not fill the available range. n Implement via lookup tables
Introduction to Computer Vision Scaling Discrete Images n Have assumed a continuous grayscale. n What happens in the case of a discrete grayscale with K levels?
Introduction to Computer Vision Non-Linear Scaling: Power Law n < 1 to enhance contrast in dark regions n > 1 to enhance contrast in bright regions. O = I
Introduction to Computer Vision Square Root Transfer: =.5
Introduction to Computer Vision =3.0
Introduction to Computer Vision Examples n Technique can be applied to color images l same curve to all color bands l different curves to separate color bands:
Introduction to Computer Vision Point Transforms:Thresholding n T is a point-to-point transformation l only information at I(x,y) used to generate I’(x,y) n Thresholding I max if I(x,y) > t I min if I(x,y) ≤ t I’(x,y) = t=89 t2550 0
Introduction to Computer Vision Threshold Selection n Arbitrary selection l select visually n Use image histogram Threshold
Introduction to Computer Vision Histograms n The image shows the spatial distribution of gray values. n The image histogram discards the spatial information and shows the relative frequency of occurrence of the gray values.
Introduction to Computer Vision Image Histogram n The histogram typically plots the absolute pixel count as a function of gray value: For an image with dimensions M by N
Introduction to Computer Vision Probability Interpretation n The graph of relative frequency of occurrence as a function of gray value is also called a histogram: n Interpreting the relative frequency histogram as a probability distribution, then: P(I(x,y) = i) = H(i)/(MxN)
Introduction to Computer Vision Cumulative Density Function n Interpreting the relative frequency histogram as a probability distribution, then: n Curve is called the cumulative distribution function Gray Value P(I(x,y) = i) = H(i)/(MxN)
Introduction to Computer Vision Examples
Introduction to Computer Vision Color Histograms
Introduction to Computer Vision Histogram Equalization n Image histograms consist of peaks, valleys, and low plains n Peaks = many pixels concentrated in a few grey levels n Plains = small number of pixels distributed over a wider range of grey levels
Introduction to Computer Vision Histogram Equalization n The goal is to modify the gray levels of an image so that the histogram of the modified image is flat. l Expand pixels in peaks over a wider range of gray-levels. l “Squeeze” low plains pixels into a narrower range of gray levels. n Utilizes all gray values equally n Example Histogram: l Note low utilization of small gray values
Introduction to Computer Vision Desired Histogram n All gray levels are used equally. n Has a tendency to enhance contrast.
Introduction to Computer Vision Brute Force How are the gray levels in the original image changed to produce the enhanced image? Method 1. Choose points randomly. Method 2. Choice depends on the gray levels of their neighboring points. Computationally expensive. Approximations.
Introduction to Computer Vision Histogram Equalization Mapping from one set of grey-levels, , to a new set, . n Ideally, the number of pixels, N p, occupying each grey level should be: n To approximate this, apply the transform l Where CH is the cumulative histogram (see next slide) l j is the gray value in the source image l i is the gray value in the equalized image N p = M*N G i = MAX 0, round CH(j) NpNp
Introduction to Computer Vision Example ideal G=8 MxN=2400 N p =300 jH(j)CH(j)i CH(j) = H(i) i=0 j
Introduction to Computer Vision Example
Introduction to Computer Vision Comparison Original >1 Histogram equalization
Introduction to Computer Vision Why? n Given MxN input image I with gray scale p 0 ….p k and histogram H(p). n Desire output image O with gray scale q 0 ….q k and uniform histogram G(q) n Treat the histograms as a discrete probability density function. Then monotonic transfer function m = T(n) implies: n The sums can be interpreted as discrete distribution functions. From Image Processing, Analysis, and Machine Vision, Sonka et al. G(q i ) = H(p j ) i=0 j=0 m n
Introduction to Computer Vision Why? continued n The histogram entries in G must be: (because G is uniform) n Plug this into previous equation to get: n Now translate into continuous domain (can’t really get uniform distributions in the discrete domain) MxN q k - q 0 G(i) = = H(p i ) i=0 m n MxN q k - q 0 MxN q k - q 0 = H(s)ds p0p0 pnpn q0q0 qmqm ds MN(q m -q 0 ) q k - q 0
Introduction to Computer Vision Why? continued n Solve last equation for q to get: n Map back into discrete domain to get: n Leads to an algorithm….. MN q k - q 0 H(s)ds + q 0 p0p0 pnpn q m = T(p) = MN q k - q 0 H(i) + q 0 q m = T(p) = i=p 0 pnpn
Introduction to Computer Vision Histogram Equalization Algorithm n For an NxM image of G gray levels, say l Create image histogram l For cumulative image histogram H c n Set n Rescan input image and write new output image by setting T(p) = round ( H c (p)) G-1 NM g q = T(g p )
Introduction to Computer Vision Observations n Acquisition process degrades image n Brightness and contrast enhancement implemented by pixel operations n No one algorithm universally useful n > 1 enhances contrast in bright images n < 1 enhances contrast in dark images n Transfer function for histogram equalisation proportional to cumulative histogram
Introduction to Computer Vision Noise Reduction n What is noise? n How is noise reduction performed? l Noise reduction from first principles l Neighbourhood operators u linear filters (low pass, high pass) u non-linear filters (median) image + noise = ‘grainy’ image
Introduction to Computer Vision Noise n Plot of image brightness. n Noise is additive. n Noise fluctuations are rapid l high frequency. Image Noise Image + Noise
Introduction to Computer Vision Sources of Noise n Sources of noise = CCD chip. n Electronic signal fluctuations in detector. n Caused by thermal energy. n Worse for infra-red sensors. n Electronics n Transmission Radiation from the long wavelength IR band is used in most infrared imaging applications
Introduction to Computer Vision Noise Model 22 n Plot noise histogram n Typical noise distribution is normal or Gaussian n Mean(noise) = 0 n Standard deviation (x) = exp 1 2 (x- 2
Introduction to Computer Vision Effect of n Integral under curve is 1 =10 =20 =30
Introduction to Computer Vision Two Dimensional Gaussian
Introduction to Computer Vision Noise n Noise varies above and below uncorrupted image. Image + Noise
Introduction to Computer Vision Noise Reduction - 1 n How do we reduce noise? n Consider a uniform 1-d image and add noise. n Focus on a pixel neighbourhood. n Averaging the three values should result in a value closer to original uncorrupted data n Especially if gaussian mean is zero A i-1 A i A i+1 Ci Ci
Introduction to Computer Vision Noise Reduction - 1 n Averaging ‘smoothes’ the noise fluctuations. n Consider the next pixel A i+1 n Repeat for remainder of pixels. A i-1 A i A i+1 A i+2 C i+1
Introduction to Computer Vision Neighborhood Operations n All pixels can be averaged by convolving 1-d image A with mask B to give enhanced image C. n Weights of B must equal one when added together. l Why? C = A * B B = [ B1 B2 B3 ] C i = A i-1 B 1 + A i B 2 + A i+1 B 3 B = [1 1 1] C i = 1 3 A i-1 + A i + A i+1 3
Introduction to Computer Vision 2D Analog of 1D Convolution n Consider the problem of blurring a 2D image n Here’s the image and a blurred version: n How would we do this? l What’s the 2D analog of 1D convolution?
Introduction to Computer Vision 2D Blurring Kernel n C = A * B n B becomes B = 1 9
Introduction to Computer Vision Convolution n Extremely important concept in computer vision, image processing, signal processing, etc. n Lots of related mathematics (we won’t do) n General idea: reduce a filtering operation to the repeated application of a mask (or filter kernel) to the image l Kernel can be thought of as an NxN image l N is usually odd so kernel has a central pixel n In practice l (flip kernel) l Align kernel center pixel with an image pixel l Pointwise multiply each kernel pixel value with corresponding image pixel value and add results l Resulting sum is normalized by kernel weight l Result is the value of the pixel centered on the kernel
Introduction to Computer Vision Image Kernel Result Image Example Kernel is aligned with pixel in image, multiplicative sum is computed, normalized, and stored in result image. n Process is repeated across image. What happens when kernel is near edge of input image?
Introduction to Computer Vision Border Problem n missing samples are zero n missing samples are gray n copying last lines n reflected indexing (mirror) n circular indexing (periodic) n truncation of the result
Introduction to Computer Vision Image size = M 1 N 1 Mask size = M 2 N 2 Convolution size = M 1 - M 2 +1 N 1 -N 2 +1 N1N1 N2N2 N 1 -N 2 +1 Typical Mask sizes = 3 3, 5 5, 7 7, 9 9, 11 11 What is the convolved image size for a 128 128 image and 7 7 mask? Convolution Size
Introduction to Computer Vision Convolution = I M *
Introduction to Computer Vision Properties of Convolution n Commutative: f 1 (t) * f 2 (t) = f 2 (t) * f 1 (t) n Distributive: f 1 (t) * [f 2 (t) + f 3 (t)] = f 1 (t) * f 2 (t) + f 1 (t) * f 3 (t) n Associative: f 1 (t) * [f 2 (t) * f 3 (t)] = [f 1 (t) * f 2 (t)] * f 3 (t) n Shift: if f 1 (t) * f 2 (t) = c(t), then l f 1 (t) * f 2 (t-T) = f 1 (t-T) * f 2 (t) = c(t-T) Convolution with impulse: f(t) * (t) = f(t) Convolution with shifted impulse: f(t) * (t-T) = f(t-T)
Introduction to Computer Vision Noise Reduction - 1 Uncorrupted Image Image + Noise Image + Noise - Blurred
Introduction to Computer Vision Noise Reduction - 1 n Technique relies on high frequency noise fluctuations being ‘blocked’ by filter. Hence, low-pass filter. n Fine detail in image may also be smoothed. n Balance between keeping image fine detail and reducing noise.
Introduction to Computer Vision Noise Reduction - 1 n Saturn image coarse detail n Boat image contains fine detail n Noise reduced but fine detail also smoothed
Introduction to Computer Vision hmmmmm….. ImageBlurred Image -=
Introduction to Computer Vision Noise Reduction - 2: Median Filter n Nonlinear Filter n Compute median of points in neighborhood n Has a tendency to blur detail less than averaging n Works very well for ‘shot’ or ‘salt and pepper’ noise OriginalLow-passMedian
Introduction to Computer Vision Noise Reduction - 2 Low-passMedian Low-pass: fine detail smoothed by averaging Median: fine detail passed by filter
Introduction to Computer Vision Edge Preserving Smoothing n Smooth (average, blur) an image without disturbing l Sharpness or l position Of the edges n Nagoa-Maysuyama Filter n Kuwahara Filter n Anisotropic Diffusion Filtering (Perona & Malik,.....) n Spatially variant smoothing
Introduction to Computer Vision Nagao-Matsuyama Filter n Calculate the variance within nine subwindows of a 5x5 moving window n Output value is the mean of the subwindow with the lowest variance n Nine subwindows used:
Introduction to Computer Vision Kuwahara Filter n Principle: l divide filter mask into four regions (a, b, c, d). l In each compute the mean brightness and the variance l The output value of the center pixel (abcd) in the window is the mean value of that region that has the smallest variance.
Introduction to Computer Vision Kuwahara Filter Example Original Median (1 iteration) Median (10 iterations) Kuwahara
Introduction to Computer Vision Anisotropic Diffusion Filtering Note: Original Perona-Malik diffusion process is NOT anisotropic, although they erroneously said it was.
Introduction to Computer Vision Example: Perona-Malik n In general: l Anisotropic diffusion estimates an image from a noisy image l Useful for restoration, etc. l Only shown smoothing examples l Read the literature
Introduction to Computer Vision Observations on Enhancement n Set of general techniques n Varied goals: l enhance perceptual aspects of an image for human observation l preprocessing to aid a vision system achieve its goal n Techniques tend to be simple, ad-hoc, and qualitative n Not universally applicable l results depend on image characteristics l determined by interactive experimentation n Can be embedded in larger vision system l selection must be done carefully l some techniques introduce artifacts into the image data n Developing specialized techniques for specific applications can be tedious and frustrating.
Introduction to Computer Vision Summary n What is noise? l Gaussian distribution n Noise reduction l first principles n Neighbourhood l low-pass l median n Averaging pixels corrupted by noise cancels out the noise. n Low-pass can blur image. n Median may retain fine image detail that may be smoothed by averaging. Conclusion