310 likes | 448 Vues
This lecture covers the fundamental concepts of computer vision, focusing on correlation, convolution, and spatial filtering methods. It explores histogram equalization techniques, illustrating how to construct probability density functions (PDFs) and cumulative distribution functions (CDFs) for image processing. Students will learn to equalize images using CDFs, perform operations with linear and nonlinear spatial filters, and implement filtering in MATLAB using the imfilter function. This comprehensive review includes practical examples and in-class exercises to reinforce understanding of key concepts.
E N D
Lecture 05 Roger S. Gaborski Introduction to Computer Vision Roger S. Gaborski
Quiz Review • In Class Exercise • Correlation – Convolution • Filtering Roger S. Gaborski
Example • Histogram PDF CDF Equalized Image • Filtering using Correlation continued
Histogram Equalization • Consider an image with the following gray level values: • Construct the pdf • Construct the cdf • Equalize the image using the cdf (not histeq)
Histogram Equalization • Consider an image with the following gray level values: • Construct the pdf 1/9 2/9 3/9 4/9 5/9 .1 .2 .3 .4 .5
pdf cdf 1/9 2/9 3/9 4/9 5/9 .1 .2 .3 .4 .5 Histogram Equalization Look Up Table 1/9 2/9 3/9 4/9 5/9 6/9 7/9 8/9 1 cdf probability .1 .2 .3 .4 .5 Gray level value Gray level value
Histogram Equalization • Consider an image with the following gray level values: • Construct the pdf • Construct the cdf • Equalize the image using the cdf (not histeq)
Spatial Filtering • Neighborhood processing • Define center point (x, y) • Perform operations involving only pixels in the neighborhood • Result of operation is response to process at that point • Moving the pixel results in a new neighborhood • Repeat process for every point in the image Roger S. Gaborski
Linear and Nonlinear Spatial Filtering • Linear operation • Multiply each pixel in the neighborhood by the corresponding coefficient and sum the results to get the response for each point (x, y) • If neighborhood is m x n , then mn coefficients are required • Coefficients are arranged in a matrix, called • filter / filter mask / kernel / template • Mask sizes are typically odd numbers (3x3, 5x5, etc.) Roger S. Gaborski
Image origin y Kernel coefficients mask x Image region under mask Roger S. Gaborski
Correlation and Convolution • Correlation • Place mask w on the image array f as previously described • Convolution • First rotate mask w by 180 degrees • Place rotated mask on image as described previously • Convolution = 180 degree rotation + correlation Roger S. Gaborski
Example: 1D Correlation • Assume w and f are one dimensional • Origin of f is its left most point • Place w so that its right most point coincides with the origin of f • Pad f with 0s so that there are corresponding f points for each w point (also pad end with 0s) • Multiply corresponding points and sum • In this case (example on next page) result is 0 • Move w to the right one value, repeat process • Continue process for whole length of f Roger S. Gaborski
Reminder • ‘full’ is the result we obtain from the operations on the previous slide. If instead of aligning the left most element of f with the right most element of w we aligned the center element of w with the left most value of f we would obtain the ‘same’ result, same indicating the result is the same length of the original w Roger S. Gaborski
Chapter 3 www.prenhall.com/gonzalezwoodseddins Roger S. Gaborski
‘Full’ correlation Roger S. Gaborski
‘Same’ correlation etc. Roger S. Gaborski
Example - Convolution • Convolution is the same procedure, but the filter is first rotated 180 degrees. • Convolution = 180 degree rotation + correlation • If the filter is symmetric, correlation and convolution results are the same Roger S. Gaborski
Chapter 3 www.prenhall.com/gonzalezwoodseddins This can be simply extend to images Roger S. Gaborski
Linear Filtering in MATLAB g = imfilter(f, w, filtering mode, boundary, size) • filters the imput image f with the filter mask w. • f is input image. It can be of any class (logical/numeric) and dimension. • g is output image • filter mode: - 'corr' : correlation, and default mode - 'conv' : convolution Roger S. Gaborski
Parameters • g = imfilter(f, w, filtering mode, boundary, size) Boundary options - X pad boundary with value X. Default X = 0. - 'symmetric' symmetric padding - 'replicate' replicate padding - 'circular' circular padding Size options - 'same' g is the same size of f (default mode) - 'full' g is full filtered by w, so size of g is increased Roger S. Gaborski
MATLAB function for filtering: imfilter • g = imfilter(f, w, ‘replicate’) • Correlation is the default filtering mode. • If filters are pre-rotated 180 degrees, can simply use default(corr) for convolution • If filter is symmetric, doesn’t matter Roger S. Gaborski
Chapter 3 www.prenhall.com/gonzalezwoodseddins Roger S. Gaborski
Example:Smoothing • w = ones(31); (31x31 filter) • % Normally the coefficients (w) are scaled to sum to one • % In this example only coefficients are not scaled by 312 • % Convolution should result in a blurred result • gd = imfilter(f, w); • % Default mode: correlation filtering • imshow(gd, [ ]); Roger S. Gaborski
Chapter 3 www.prenhall.com/gonzalezwoodseddins Input Default padding ‘replicate’ ‘symmetric’ ‘circular’ ‘replicate’, uint8 Roger S. Gaborski