Lecture 4 Linear Filters and Convolution

Slides:



Advertisements
Similar presentations
Linear Filtering – Part I Selim Aksoy Department of Computer Engineering Bilkent University
Advertisements

Spatial Filtering (Chapter 3)
CS 4487/9587 Algorithms for Image Analysis
E.G.M. PetrakisFiltering1 Linear Systems Many image processing (filtering) operations are modeled as a linear system Linear System δ(x,y) h(x,y)
Digital Image Processing In The Name Of God Digital Image Processing Lecture3: Image enhancement M. Ghelich Oghli By: M. Ghelich Oghli
Edge detection Goal: Identify sudden changes (discontinuities) in an image Intuitively, most semantic and shape information from the image can be encoded.
Lecture 4 Edge Detection
Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007
Computer Vision - A Modern Approach Set: Linear Filters Slides by D.A. Forsyth Differentiation and convolution Recall Now this is linear and shift invariant,
Edge detection. Edge Detection in Images Finding the contour of objects in a scene.
Image processing. Image operations Operations on an image –Linear filtering –Non-linear filtering –Transformations –Noise removal –Segmentation.
Computer Vision - A Modern Approach
CS 376b Introduction to Computer Vision 02 / 27 / 2008 Instructor: Michael Eckmann.
1 Image Filtering Readings: Ch 5: 5.4, 5.5, 5.6,5.7.3, 5.8 (This lecture does not follow the book.) Images by Pawan SinhaPawan Sinha formal terminology.
Linear filtering. Overview: Linear filtering Linear filters Definition and properties Examples Gaussian smoothing Separability Applications Denoising.
Linear filters and edges. Linear Filters General process: Form new image whose pixels are a weighted sum of original pixel values, using the same set.
CS443: Digital Imaging and Multimedia Filters Spring 2008 Ahmed Elgammal Dept. of Computer Science Rutgers University Spring 2008 Ahmed Elgammal Dept.
1 Image filtering Images by Pawan SinhaPawan Sinha.
1 Image filtering
Lecture 2: Image filtering
1 Images and Transformations Images by Pawan SinhaPawan Sinha.
Linear filtering.
1 Image filtering Hybrid Images, Oliva et al.,
Linear Filtering About modifying pixels based on neighborhood. Local methods simplest. Linear means linear combination of neighbors. Linear methods simplest.
Basic Image Processing January 26, 30 and February 1.
Most slides from Steve Seitz
Filtering Course web page: vision.cis.udel.edu/cv March 5, 2003  Lecture 9.
CS 376b Introduction to Computer Vision 02 / 26 / 2008 Instructor: Michael Eckmann.
Linear Filters and Edges
Machine Vision ENT 273 Image Filters Hema C.R. Lecture 5.
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell Image processing.
Linear Filtering – Part I Selim Aksoy Department of Computer Engineering Bilkent University
Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T Computer Vision Tahun: 2010.
EECS 274 Computer Vision Linear Filters and Edges.
CS 556 – Computer Vision Image Basics & Review. What is an Image? Image: a representation, resemblance, or likeness An image is a signal: a function carrying.
Linear filtering. Motivation: Noise reduction Given a camera and a still scene, how can you reduce noise? Take lots of images and average them! What’s.
Machine Vision ENT 273 Image Filters Hema C.R. Lecture 5.
CSC508 Convolution Operators. CSC508 Convolution Arguably the most fundamental operation of computer vision It’s a neighborhood operator –Similar to the.
Digital Image Processing Lecture 16: Segmentation: Detection of Discontinuities Prof. Charlene Tsai.
Intelligent Vision Systems ENT 496 Image Filtering and Enhancement Hema C.R. Lecture 4.
CSE 6367 Computer Vision Image Operations and Filtering “You cannot teach a man anything, you can only help him find it within himself.” ― Galileo GalileiGalileo.
Digital Image Processing Lecture 16: Segmentation: Detection of Discontinuities May 2, 2005 Prof. Charlene Tsai.
Reconnaissance d’objets et vision artificielle
Linear filtering. Motivation: Image denoising How can we reduce noise in a photograph?
Instructor: Mircea Nicolescu Lecture 5 CS 485 / 685 Computer Vision.
Grauman Today: Image Filters Smooth/Sharpen Images... Find edges... Find waldo…
Lecture 1: Images and image filtering CS4670/5670: Intro to Computer Vision Noah Snavely Hybrid Images, Oliva et al.,
Filters– Chapter 6. Filter Difference between a Filter and a Point Operation is that a Filter utilizes a neighborhood of pixels from the input image to.
Edges Edges = jumps in brightness/color Brightness jumps marked in white.
Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis.
Correlation and Convolution They replace the value of an image pixel with a combination of its neighbors Basic operations in images Shift Invariant Linear.
Digital Image Processing Lecture 16: Segmentation: Detection of Discontinuities Prof. Charlene Tsai.
Digital Image Processing Lecture 10: Image Restoration
Linear Filters and Edges Chapters 7 and 8
Linear Filters T-11 Computer Vision University of Houston
Filtering – Part I Gokberk Cinbis Department of Computer Engineering
Image filtering Hybrid Images, Oliva et al.,
Image filtering Images by Pawan Sinha.
Image filtering Images by Pawan Sinha.
Image filtering Images by Pawan Sinha.
Basic Image Processing
Digital Image Processing Week IV
Most slides from Steve Seitz
Image filtering Images by Pawan Sinha.
Image filtering
Image filtering
Department of Computer Engineering
Image Filtering Readings: Ch 5: 5. 4, 5. 5, 5. 6, , 5
Most slides from Steve Seitz
Lecture 7 Spatial filtering.
Presentation transcript:

Lecture 4 Linear Filters and Convolution Slides by: David A. Forsyth Clark F. Olson Steven M. Seitz Linda G. Shapiro

Image noise In finding the interesting features (such as edges) in an image, the biggest problem is noise. Noise is: Sensor error in acquiring the image Anything other than what you are looking for Noise is often caused by underexposure (low light, high film speed) Noisy image from Wikipedia page on image noise

Noise Common types of noise: Salt and pepper noise - contains random occurrences of black and white pixels Impulse noise - contains random occurrences of white pixels Gaussian noise - variations in intensity drawn from a Gaussian (normal) distribution

Image noise “Simple” noise model: Independent stationary additive Gaussian noise The noise value at each pixel is given by an independent draw from the same normal (i.e., Gaussian) probability distribution The scale (σ) determines how large the effect of the noise is. Result image “Perfect” image additive noise where z is a random number between 0 and 1.

Image noise Issues: Advantages: This model allows noise values that could be greater than maximum camera output or less than zero. For small standard deviations, this isn’t too much of a problem - it’s a fairly good model. Independence may not be justified (e.g., damage to lens). Noise may not be stationary (e.g., thermal gradients in the ccd). Advantages: Fairly accurate Relatively easy to determine response of filters to such noise

Linear filters We use linear filtering to reduce the effect of noise (among other things). General process: Form new image, where pixels are a weighted sum of nearby pixel values in original image, using the same set of weights at each point Properties: Output is a linear function of the input Output is a shift-invariant function of the input (i.e. shift the input image two pixels to the left, the output is shifted two pixels to the left)

Linear filtering Filtering operations use a “kernel” or “mask” composed of weights to determine how to compute the weighted average in a neighborhood. Usually, the mask is centered on the pixel and the weights are applied by multiplying by the corresponding pixel in the image and summing. 36 36 36 36 36 36 36 45 45 45 36 45 45 45 54 36 45 54 54 54 45 45 54 54 54 ** ** ** ** ** ** 39 ** ** ** 1/9 1/9 1/9 3x3 Mask Input Image Output Image

Mean filtering A mean filter (as on the previous slide) averages the pixels in some neighborhood (such as the 3x3 box surrounding the pixel). For this neighborhood, every pixel in the output (except for the borders) is defined as:

Kernel The kernel is a 2D array or matrix or image. The kernel has an origin that represents the location that is multiplied by the pixel at the location of the output pixel. Usually at the center of the kernel, but not necessarily Kernel for mean filtering in a 3x3 neighborhood (center is bold): For smoothing or averaging, the kernel coefficients always add up to one. Larger (sometimes much larger) kernels are common. 1/9 1/9 1/9

Image boundaries At the image boundary, we can’t use the same process, since part of the kernel will be outside of the input image. Some methods for handling the boundary: Shrink the output image (ignore the boundaries) Consider every pixel outside of the input to be: Black (zero) The same as the nearest pixel inside the image Extends the borders infinitely A mirror image of the pixels inside the image Less likely to appear as edge at boundary, but second order effects occur (second derivative may appear large)

Mean filtering 90 10 20 30 40 60 90 50 80

Mean filtering As the size of the kernel is increased, the noise is more smoothed, but so is the rest of the image.

Linear filtering Some examples of linear filtering Smoothing by averaging (mean filtering) Form the average of pixels in a neighborhood Smoothing with a Gaussian Form a weighted average of pixels in a neighborhood Finding a derivative (approximation)

Convolution Linear filtering can be performed using a process called discrete convolution. Represent the pixel weights as an image, K K is usually called the kernel in convolution Operation is associative (if defined correctly) Continuous convolution is common in signal processing (and other fields), but, since images are not continuous, we will use only discrete convolution

Convolution Algorithmically, convolution corresponds to four nested loops (two over the image, two over the kernel). For each image row in output image: For each image column in output image: Set running total to zero. For each kernel row: For each kernel column: Multiply kernel value by appropriate image value Add result to running total Set output image pixel to value of running total

Convolution Mathematically: Odd definition preserves associativity and commutativity. Subtracting u and v from the image indices implies that the kernel is flipped before applying it to the image. All linear operations can be written as a convolution with some kernel. Variables u and v range over the size of the kernel. Note that the kernel origin (0,0) is usually at the center of the kernel (but does not need to be).

Convolution The “center” of the kernel is at the origin. For our “mean filter” kernel, we have: -1 ≤ u ≤ 1 -1 ≤ v ≤ 1 Again, note the change in the sign of u and v – this is flipping the image (or, equivalently, the kernel). K(0, 0) K(-1, -1) Kernel K 1/9 1/9 1/9 v K(1, 0) u

Convolution Convolution is written in shorthand as O = K * I. The “flipping” preserves commutativity: K * I = I * K and associativity: J * (K * I) = (J * K) * I, but only if the borders are handled correctly. Must expand the output, treating values outside the input image as zero.

Cross-correlation Cross-correlation is the same as convolution, except that you don’t flip the kernel. How does this differ from convolution for: Mean filtering? Gaussian filtering?

Example: smoothing by averaging Kernel Input Output Here is the point to introduce some visual “notation”. I’ve given the kernel as an image on the top. Usually, these images are white for the largest value, and black for the smallest (which is zero in this case). The point of this pair of images is that if you convolve the one on the left with the kernel shown above you get the one on the right, which is nothing like a smoothed version of the one on the left (there’s some fairly aggressive ringing). Explain the ringing qualitatively in terms of the boundaries of the kernel, and point out that the effect would disappear if there weren’t sharp edges in the kernel. 20

Smoothing with a Gaussian Smoothing with an average actually doesn’t compare at all well with a defocused lens (e.g., in an eye). A defocused lens smoothes an image symmetrically, which is what we want. Most obvious difference is that a single point of light viewed in a defocused lens looks like a fuzzy blob, but the averaging process would give a little square. We want smoothing to be the same in all directions. I always walk through the argument on the left rather carefully; it gives some insight into the significance of impulse responses or point spread functions. A Gaussian gives a good model of a fuzzy blob

An isotropic Gaussian Plot of: The constant is necessary so that the function integrates to 1. Plot of: The image shows a smoothing kernel proportional to a Gaussian (a circularly symmetric fuzzy blob) Sigma (σ) is often referred to as the scale of the Gaussian

Gaussian smoothing In practice, we must discretize the (continuous) Gaussian function: We could generate the following 3x3 kernel with σ=1: (Normally, we would use a larger kernel.) h(-1, -1) h(-1, 0) h(-1, 1) h(0, -1) h(0, 0) h(0, 1) h(1, -1) h(1, 0) h(1, 1) 0.059 0.097 0.059 0.097 0.159 0.097 =

Gaussian smoothing Unfortunately, the sum of the values for the kernel on the previous slide is only 0.779. We need to normalize the kernel by dividing each value by 0.779. The sum is now 1. 0.059 0.097 0.059 0.097 0.159 0.097 0.075 0.124 0.075 0.124 0.204 0.124

Smoothing with a Gaussian You want to point out the absence of ringing effects here. 25

Averaging vs. Gaussian smoothing 26

Differentiation Recall that: This is linear and shift invariant, so it must be the result of a convolution.

Differentiation and convolution We can approximate this as: This is called a “finite difference.” It is definitely a convolution – what is the kernel? Often called the gradient when applied to an image. This finite difference (gradient) measures horizontal change. By itself, it’s not a very good way to do things, since it is very sensitive to noise. I tend not to prove “Now this is linear and shift invariant, so must be the result of a convolution” but leave it for people to look up in the chapter.

Gradient kernels To determine the horizontal image gradient, we could use one of the following kernels: The first has better “localization,” but shifts the image by half of a pixel. For vertical image gradients, we use one of: -1 1 -1 0 1 -1 1 -1 1

Finite differences (horizontal) Large (bright) values for light/dark transitions Kernel: 1 -1 Negative (dark) values for dark/light transitions Detects only horizontal changes. Small (grey) values for non-transitions Now the figure on the right is signed; darker is negative, lighter is positive, and mid grey is zero. I always ask 1) which derivative (y or x) is this? 2) Have I got the sign of the kernel right? (i.e. is it d/dx or -d/dx).

Finite differences Finite difference filters respond strongly to noise. Image noise results in pixels that look very different from their neighbors Generally, the larger the noise, the stronger the response.

Finite differences responding to noise Low noise Medium noise High noise

Finite differences and noise What is to be done? Intuitively, most pixels in images look quite a lot like their neighbors. This is somewhat true even at an edge; along the edge they’re similar, across the edge they’re not. This suggests that smoothing the image should help, by forcing pixels different to their neighbors (noise pixels?) to look more like neighbors.

Filter responses are correlated The filter responses are correlated over scales similar to the scale of the filter. Filtered noise is sometimes useful. It looks like some natural textures, can be used to simulate fire, etc.

Filtered noise Independent stationary Gaussian noise convolved with a Gaussian kernel. The scores are correlated over the same scale as the kernel.

Filtered noise Independent stationary Gaussian noise convolved with a Gaussian kernel. The scores are correlated over the same scale as the kernel.

Filtered noise Independent stationary Gaussian noise convolved with a Gaussian kernel. The scores are correlated over the same scale as the kernel.

Median filtering A median filter takes the median value in the neighborhood of a pixel, rather than a weighted average. Is this a convolution? Advantage: It doesn’t smooth over region boundaries. Noise added to the images is Gaussian.

Median filtering Median filtering works best with salt and pepper noise.