Fourier analysis of images

Similar documents
Thinking in Frequency

Motion illusion, rotating snakes

Next Classes. Spatial frequency Fourier transform and frequency domain. Reminder: Textbook. Frequency view of filtering Hybrid images Sampling

02/02/10. Image Filtering. Computer Vision CS 543 / ECE 549 University of Illinois. Derek Hoiem

06: Thinking in Frequencies. CS 5840: Computer Vision Instructor: Jonathan Ventura

Thinking in Frequency

CSCI 1290: Comp Photo

Motivation: Image denoising. How can we reduce noise in a photograph?

Motivation: Image denoising. How can we reduce noise in a photograph?

CEE598 - Visual Sensing for Civil Infrastructure Eng. & Mgmt.

Sampling and Reconstruction

Image Filtering in Spatial domain. Computer Vision Jia-Bin Huang, Virginia Tech

Prof. Feng Liu. Winter /10/2019

Templates and Image Pyramids

>>> from numpy import random as r >>> I = r.rand(256,256);

Image Filtering and Gaussian Pyramids

>>> from numpy import random as r >>> I = r.rand(256,256);

Templates and Image Pyramids

CS 4501: Introduction to Computer Vision. Filtering and Edge Detection

Image filtering, image operations. Jana Kosecka

Images and Filters. EE/CSE 576 Linda Shapiro

Matlab (see Homework 1: Intro to Matlab) Linear Filters (Reading: 7.1, ) Correlation. Convolution. Linear Filtering (warm-up slide) R ij

Sampling and Reconstruction

Midterm is on Thursday!

CS6670: Computer Vision Noah Snavely. Administrivia. Administrivia. Reading. Last time: Convolution. Last time: Cross correlation 9/8/2009

Last Lecture. photomatix.com

Last Lecture. photomatix.com

Linear Filters Tues Sept 1 Kristen Grauman UT Austin. Announcements. Plan for today 8/31/2015. Image noise Linear filters. Convolution / correlation

Vision Review: Image Processing. Course web page:

Computer Vision Lecture 3

Image Enhancement II: Neighborhood Operations

Frequencies and Color

Sampling and reconstruction

Sampling and Pyramids

Sampling and reconstruction

Announcements. Image Processing. What s an image? Images as functions. Image processing. What s a digital image?

Digital Image Processing

Practical Image and Video Processing Using MATLAB

CS4495/6495 Introduction to Computer Vision. 2C-L3 Aliasing

Image features: Histograms, Aliasing, Filters, Orientation and HOG. D.A. Forsyth

Digital Image Processing

Digital Image Processing

Digital Image Processing. Filtering in the Frequency Domain (Application)

Frequency Domain Enhancement

Achim J. Lilienthal Mobile Robotics and Olfaction Lab, AASS, Örebro University

Midterm Review. Image Processing CSE 166 Lecture 10

LAB MANUAL SUBJECT: IMAGE PROCESSING BE (COMPUTER) SEM VII

Sampling and Reconstruction

Image acquisition. Midterm Review. Digitization, line of image. Digitization, whole image. Geometric transformations. Interpolation 10/26/2016

Image Filtering. Median Filtering

Lec 05 - Linear Filtering & Edge Detection

Image Sampling. Moire patterns. - Source: F. Durand

Sampling and reconstruction. CS 4620 Lecture 13

EE482: Digital Signal Processing Applications

Image Pyramids. Sanja Fidler CSC420: Intro to Image Understanding 1 / 35

Computer Graphics (Fall 2011) Outline. CS 184 Guest Lecture: Sampling and Reconstruction Ravi Ramamoorthi

CS534 Introduction to Computer Vision. Linear Filters. Ahmed Elgammal Dept. of Computer Science Rutgers University

Overview. Neighborhood Filters. Dithering

Image Processing for feature extraction

Computer Vision, Lecture 3

More image filtering , , Computational Photography Fall 2017, Lecture 4

1.Discuss the frequency domain techniques of image enhancement in detail.

Image preprocessing in spatial domain

Lecture #10. EECS490: Digital Image Processing

Lec 04: Image Filtering and Edge Features

Filters. Materials from Prof. Klaus Mueller

Transforms and Frequency Filtering

Digital Image Processing. Image Enhancement: Filtering in the Frequency Domain

ECE 484 Digital Image Processing Lec 09 - Image Resampling

Image Enhancement in spatial domain. Digital Image Processing GW Chapter 3 from Section (pag 110) Part 2: Filtering in spatial domain

IMAGE ENHANCEMENT IN SPATIAL DOMAIN

2D Discrete Fourier Transform

Robert Collins CSE486, Penn State. Lecture 3: Linear Operators

IMAGE PROCESSING: AREA OPERATIONS (FILTERING)

Understanding Digital Signal Processing

Lecture 3: Linear Filters

Digital Image Processing. Digital Image Fundamentals II 12 th June, 2017

Tonemapping and bilateral filtering

Aliasing and Antialiasing. What is Aliasing? What is Aliasing? What is Aliasing?

CoE4TN4 Image Processing. Chapter 3: Intensity Transformation and Spatial Filtering

Fourier Transform. Any signal can be expressed as a linear combination of a bunch of sine gratings of different frequency Amplitude Phase

CoE4TN4 Image Processing. Chapter 4 Filtering in the Frequency Domain

Midterm Examination CS 534: Computational Photography

Chapter 3 Image Enhancement in the Spatial Domain. Chapter 3 Image Enhancement in the Spatial Domain

Image Enhancement in the Spatial Domain Low and High Pass Filtering

Table of contents. Vision industrielle 2002/2003. Local and semi-local smoothing. Linear noise filtering: example. Convolution: introduction

Prof. Vidya Manian Dept. of Electrical and Comptuer Engineering

8.2 IMAGE PROCESSING VERSUS IMAGE ANALYSIS Image processing: The collection of routines and

The Fourier Transform

Image Enhancement. DD2423 Image Analysis and Computer Vision. Computational Vision and Active Perception School of Computer Science and Communication

Image Processing Computer Graphics I Lecture 20. Display Color Models Filters Dithering Image Compression

Computing for Engineers in Python

Image Scaling. This image is too big to fit on the screen. How can we reduce it? How to generate a halfsized

CS 111: Programing Assignment 2

CAP 5415 Computer Vision. Marshall Tappen Fall Lecture 1

Image Interpolation. Image Processing

Color Space 1: RGB Color Space. Color Space 2: HSV. RGB Cube Easy for devices But not perceptual Where do the grays live? Where is hue and saturation?

TDI2131 Digital Image Processing

Filip Malmberg 1TD396 fall 2018 Today s lecture

CSC 320 H1S CSC320 Exam Study Guide (Last updated: April 2, 2015) Winter 2015

Transcription:

Fourier analysis of images Intensity Image Fourier Image Slides: James Hays, Hoiem, Efros, and others http://sharp.bu.edu/~slehar/fourier/fourier.html#filtering

Signals can be composed + = http://sharp.bu.edu/~slehar/fourier/fourier.html#filtering More: http://www.cs.unm.edu/~brayer/vision/fourier.html

Fourier Transform Fourier transform stores the magnitude and phase at each frequency Magnitude encodes how much signal there is at a particular frequency Phase encodes spatial information (indirectly) For mathematical convenience, this is often notated in terms of real and complex numbers Amplitude: A = ± R ω + I 2 2 ( ) ( ω) Phase: φ = tan I( ω) R( ω)

Filtering in the Frequency Domain Ideal LPF: D(u,v) is the distance from point (u,v) to the center of the filter. D is the cutoff frequency. Gaussian LPF:. g(x).8.6.4.2. σ -6-4 -2 2 4 x 2 2 ( x + y ) g( x, y ) = exp( 2 ) 2σ = g( x ) g( y ) 2 x g( x ) = exp( 2 ) 2σ G(u,v) = H(u,v) F(u,v) element-wise multiplication in frequency domain, then perform inverse DFT on G(u,v)...

Ideal LPF: Gaussian LPF:

High-pass Filters in the Frequency Domain Ideal HPF: Gaussian HPF: G(u,v) = H(u,v) F(u,v) element-wise multiplication in frequency domain, then perform inverse DFT on G(u,v)...

Ideal HPF: Gaussian HPF:

Filtering with the FFT in Matlab im = double(imread('baboon.bmp'))/255; im = rgb2gray(im); % im should be a gray-scale floating point image figure; imshow(im); [imh, imw] = size(im); hs = 5; % filter half-size fil = fspecial('gaussian', hs*2+, ); figure; bar3(fil); fftsize = 24; % should be order of 2 (for speed) and include padding im_fft = fft2(im, fftsize, fftsize); % ) fft im with padding figure(); imagesc(log(abs(fftshift(im_fft)))), axis image, colormap jet fil_fft = fft2(fil, fftsize, fftsize); image % 2) fft fil, pad to same size as figure(); imagesc(log(abs(fftshift(fil_fft)))), axis image, colormap jet im_fil_fft = im_fft.* fil_fft; % 3) multiply fft images im_fil = ifft2(im_fil_fft); % 4) inverse fft2 im_fil = im_fil(+hs:size(im,)+hs, +hs:size(im, 2)+hs); % 5) remove padding figure; imshow(im_fil);

Filtering Why does the Gaussian give a nice smooth image, but the square filter give edgy artifacts? Gaussian Box filter

Gaussian

Box Filter

Sampling Why does a lower resolution image still make sense to us? What do we lose? Image: http://www.flickr.com/photos/igorms/3696757/

Subsampling by a factor of 2 Throw away every other row and column to create a /2 size image

Aliasing problem D example (sinewave): Source: S. Marschner

Aliasing problem D example (sinewave): Source: S. Marschner

Aliasing problem Sub-sampling may be dangerous. Characteristic errors may appear: Wagon wheels rolling the wrong way in movies Checkerboards disintegrate in ray tracing Striped shirts look funny on color television Source: D. Forsyth

Aliasing in video Slide by Steve Seitz

Aliasing in graphics Source: A. Efros

Sampling and aliasing

Nyquist-Shannon Sampling Theorem When sampling a signal at discrete intervals, the sampling frequency must be 2 f max f max = max frequency of the input signal This allows us to reconstruct the original perfectly from the sampled version v v v good bad

Anti-aliasing Solutions: Sample more often Get rid of all frequencies that are greater than half the new sampling frequency Will lose information But it s better than aliasing Apply a smoothing filter

Algorithm for downsampling by factor of 2. Start with image(h, w) 2. Apply low-pass filter im_blur = imfilter(image, fspecial( gaussian, 7, )) 3. Sample every other pixel im_small = im_blur(:2:end, :2:end);

Anti-aliasing Forsyth and Ponce 22

Subsampling without pre-filtering /2 /4 (2x zoom) /8 (4x zoom) Slide by Steve Seitz

Subsampling with Gaussian pre-filtering Gaussian /2 G /4 G /8 Slide by Steve Seitz

Why do we get different, distance-dependent interpretations of hybrid images??

Salvador Dali invented Hybrid Images? Salvador Dali Gala Contemplating the Mediterranean Sea, which at 3 meters becomes the portrait of Abraham Lincoln, 976

Clues from Human Perception Early processing in humans filters for various orientations and scales of frequency Perceptual cues in the mid-high frequencies dominate perception When we see an image from far away, we are effectively subsampling it Early Visual Processing: Multi-scale edge and blob filters

Campbell-Robson contrast sensitivity curve

Hybrid Image in FFT Hybrid Image Low-passed Image High-passed Image

Perception Why do we get different, distance-dependent interpretations of hybrid images??

Things to Remember Sometimes it makes sense to think of images and filtering in the frequency domain Fourier analysis Can be faster to filter using FFT for large images (N logn vs. N 2 for autocorrelation) Images are mostly smooth Basis for compression Remember to low-pass before sampling

Practice question. Match the spatial domain image to the Fourier magnitude image 2 3 4 5 B A C D E

Slide credit Fei Fei Li

three views of filtering Image filtered in spatial domain Filter is a mathematical operation of a grid of numbers Smoothing, sharpening, measuring texture Image filtered in the frequency domain Filtering is a way to modify the frequencies of images Denoising, sampling, image compression Templates and Image Pyramids Filtering is a way to match a template to the image Detection, coarse-to-fine registration

Image filtering Image filtering: compute function of local neighborhood at each position Really important! Enhance images Denoise, resize, increase contrast, etc. Extract information from images Texture, edges, distinctive points, etc. Detect patterns Template matching

Example: box filter g[, ] Slide credit: David Lowe (UBC)

Image filtering g[, ] f [.,.] h[.,.] 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 h[ m, n] = k, l g[ k, l] f [ m + k, n + l] Credit: S. Seitz

Image filtering g[, ] f [.,.] h[.,.] 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 h[ m, n] = g[ k, l] k, l f [ m + k, n + l] Credit: S. Seitz

Image filtering g[, ] f [.,.] h[.,.] 2 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 h[ m, n] = g[ k, l] k, l f [ m + k, n + l] Credit: S. Seitz

Image filtering g[, ] f [.,.] h[.,.] 2 3 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 h[ m, n] = g[ k, l] k, l f [ m + k, n + l] Credit: S. Seitz

Image filtering g[, ] f [.,.] h[.,.] 2 3 3 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 h[ m, n] = g[ k, l] k, l f [ m + k, n + l] Credit: S. Seitz

Image filtering g[, ] f [.,.] h[.,.] 2 3 3 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9? 9 h[ m, n] = g[ k, l] k, l f [ m + k, n + l] Credit: S. Seitz

Image filtering g[, ] f [.,.] h[.,.] 2 3 3 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9? 9 9 9 9 9 5 9 h[ m, n] = g[ k, l] k, l f [ m + k, n + l] Credit: S. Seitz

Image filtering g[, ] f [.,.] h[.,.] 2 3 3 3 2 9 9 9 9 9 2 4 6 6 6 4 2 9 9 9 9 9 3 6 9 9 9 6 3 9 9 9 9 9 3 5 8 8 9 6 3 9 9 9 9 3 5 8 8 9 6 3 9 9 9 9 9 2 3 5 5 6 4 2 2 3 3 3 3 2 9 h[ m, n] = g[ k, l] k, l f [ m + k, n + l] Credit: S. Seitz

Box Filter What does it do? g[, ] Replaces each pixel with an average of its neighborhood Achieve smoothing effect (remove sharp features) Slide credit: David Lowe (UBC)

Smoothing with box filter

Practice with linear filters? Original Source: D. Lowe

Practice with linear filters Original Filtered (no change) Source: D. Lowe

Practice with linear filters? Original Source: D. Lowe

Practice with linear filters Original Shifted left By pixel Source: D. Lowe

Practice with linear filters 2 -? Original (Note that filter sums to ) Source: D. Lowe

Practice with linear filters 2 - Original Sharpening filter - Accentuates differences with local average Source: D. Lowe

Sharpening Source: D. Lowe

Other filters 2 Sobel - -2 - Vertical Edge (absolute value)

Other filters - 2-2 Sobel - Horizontal Edge (absolute value)

The Convolution Theorem The Fourier transform of the convolution of two functions is the product of their Fourier transforms F[ g h] = F[ g]f[ h] Convolution in spatial domain is equivalent to multiplication in frequency domain! g * h = F [F[ g]f[ h]]

Filtering vs. Convolution g=filter f=image 2d filtering h=filter2(g,f); or h=imfilter(f,g); h[ m, n] = g[ k, l] k, l f [ m + k, n + l] 2d convolution h=conv2(g,f); h[ m, n] = k, l g[ k, l] f [ m k, n l]

Key properties of linear filters Linearity: filter(f + f 2 ) = filter(f ) + filter(f 2 ) Shift invariance: same behavior regardless of pixel location filter(shift(f)) = shift(filter(f)) Any linear, shift-invariant operator can be represented as a convolution Source: S. Lazebnik

More properties Commutative: a * b = b * a Conceptually no difference between filter and signal But particular filtering implementations might break this equality Associative: a * (b * c) = (a * b) * c Often apply several filters one after another: (((a * b ) * b 2 ) * b 3 ) This is equivalent to applying one filter: a * (b * b 2 * b 3 ) Distributes over addition: a * (b + c) = (a * b) + (a * c) Scalars factor out: ka * b = a * kb = k (a * b) Identity: unit impulse e = [,,,, ], a * e = a Source: S. Lazebnik

Important filter: Gaussian Weight contributions of neighboring pixels by nearness.3.3.22.3.3.3.59.97.59.3.22.97.59.97.22.3.59.97.59.3.3.3.22.3.3 5 x 5, σ = Slide credit: Christopher Rasmussen

Smoothing with Gaussian filter

Smoothing with box filter

Gaussian filters Remove high-frequency components from the image (low-pass filter) Images become more smooth Convolution with self is another Gaussian So can smooth with small-width kernel, repeat, and get same result as larger-width kernel would have Convolving two times with Gaussian kernel of width σ is same as convolving once with kernel of width σ 2 Separable kernel Factors into product of two D Gaussians Source: K. Grauman

Separability of the Gaussian filter Source: D. Lowe

Separability example 2D convolution (center location only) The filter factors into a product of D filters: Perform convolution along rows: * = Followed by convolution along the remaining column: * = Source: K. Grauman

Separability Why is separability useful in practice?

Practical matters How big should the filter be? Values at edges should be near zero Rule of thumb for Gaussian: set filter half-width to about 3 σ

Practical matters What about near the edge? the filter window falls off the edge of the image need to extrapolate methods: clip filter (black) wrap around copy edge reflect across edge Source: S. Marschner

Practical matters Q? methods (MATLAB): clip filter (black): imfilter(f, g, ) wrap around: imfilter(f, g, circular ) copy edge: imfilter(f, g, replicate ) reflect across edge: imfilter(f, g, symmetric ) Source: S. Marschner

g Practical matters What is the size of the output? MATLAB: filter2(g, f, shape) shape = full : output size is sum of sizes of f and g shape = same : output size is same as f shape = valid : output size is difference of sizes of f and g full same valid g g g g g f f f g g g g g g Source: S. Lazebnik

Median filters A Median Filter operates over a window by selecting the median intensity in the window. What advantage does a median filter have over a mean filter? Is a median filter a kind of convolution? 26 Steve Marschner 78 Slide by Steve Seitz

Comparison: salt and pepper noise 26 Steve Marschner 79 Slide by Steve Seitz

Hybrid Images Gaussian Filter! A. Oliva, A. Torralba, P.G. Schyns, Hybrid Images, SIGGRAPH 26 Laplacian Filter! unit impulse Gaussian Laplacian of Gaussian

Remember Linear filtering is sum of products at each position Can smooth, sharpen, translate (among many other uses) Be aware of details for filter size, extrapolation, cropping

Review: questions. Write down a 3x3 filter that returns a positive value if the average value of the 4-adjacent neighbors is less than the center and a negative value otherwise 2. Write down a filter that will compute the gradient in the x-direction: gradx(y,x) = im(y,x+)-im(y,x) for each x, y Slide: Hoiem

Review: questions 3. Fill in the blanks: a) _ = D * B b) A = _ * _ c) F = D * _ d) _ = D * D Filtering Operator A E B F G C H I D Slide: Hoiem