Lecture: Pixels and Filters

Slides:



Advertisements
Similar presentations
CS Spring 2009 CS 414 – Multimedia Systems Design Lecture 4 – Digital Image Representation Klara Nahrstedt Spring 2009.
Advertisements

Spatial Filtering (Chapter 3)
Motion illusion, rotating snakes. Slide credit Fei Fei Li.
CS 4487/9587 Algorithms for Image Analysis
Lecture 4 Linear Filters and Convolution
Image Filtering CS485/685 Computer Vision Prof. George Bebis.
1 Image filtering Hybrid Images, Oliva et al.,
Lecture 1: Images and image filtering
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.
CS443: Digital Imaging and Multimedia Filters Spring 2008 Ahmed Elgammal Dept. of Computer Science Rutgers University Spring 2008 Ahmed Elgammal Dept.
Announcements Kevin Matzen office hours – Tuesday 4-5pm, Thursday 2-3pm, Upson 317 TA: Yin Lou Course lab: Upson 317 – Card access will be setup soon Course.
1 Image filtering Images by Pawan SinhaPawan Sinha.
1 Image filtering
Lecture 2: Image filtering
1 Images and Transformations Images by Pawan SinhaPawan Sinha.
1 Image filtering Hybrid Images, Oliva et al.,
Most slides from Steve Seitz
Lecture 1: Images and image filtering CS4670/5670: Intro to Computer Vision Kavita Bala Hybrid Images, Oliva et al.,
Digital Signals and Systems
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.
Machine Vision ENT 273 Image Filters Hema C.R. Lecture 5.
Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.
Image Filtering Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 02/02/10.
Why is computer vision difficult?
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.
Lecture 5 Mask/Filter Transformation 1.The concept of mask/filters 2.Mathematical model of filtering Correlation, convolution 3.Smoother filters 4.Filter.
Machine Vision ENT 273 Image Filters Hema C.R. Lecture 5.
CSE 473/573 Computer Vision and Image Processing (CVIP) Ifeoma Nwogu Lecture 7 – Linear Filters 1.
Intelligent Vision Systems ENT 496 Image Filtering and Enhancement Hema C.R. Lecture 4.
Visual Computing Computer Vision 2 INFO410 & INFO350 S2 2015
CS 691B Computational Photography
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.
Lecture 3: Filtering and Edge detection
CS Spring 2010 CS 414 – Multimedia Systems Design Lecture 4 – Audio and Digital Image Representation Klara Nahrstedt Spring 2010.
CSE 185 Introduction to Computer Vision Image Filtering: Spatial Domain.
Lecture 1: Images and image filtering CS4670/5670: Intro to Computer Vision Noah Snavely Hybrid Images, Oliva et al.,
- photometric aspects of image formation gray level images
CEN352 Dr. Nassim Ammour King Saud University
All about convolution.
Histogram Histogram is a graph that shows frequency of anything. Histograms usually have bars that represent frequency of occuring of data. Histogram has.
Lecture 1: Images and image filtering
Image filtering Hybrid Images, Oliva et al.,
Recap from Wednesday Spectra and Color Light capture in cameras and humans.
Image filtering Images by Pawan Sinha.
CSCE 643 Computer Vision: Thinking in Frequency
Image filtering Images by Pawan Sinha.
Image Processing Today’s readings For Monday
Image filtering Images by Pawan Sinha.
Motion illusion, rotating snakes
Spatial operations and transformations
Linear filtering.
Lecture 5: Resampling, Compositing, and Filtering Li Zhang Spring 2008
Lecture: Image manipulations (2) Filters and kernels
Digital Image Processing Week IV
Most slides from Steve Seitz
Image filtering Images by Pawan Sinha.
Image filtering
Image filtering
Lecture 2: Image filtering
Midterm Exam Closed book, notes, computer Similar to test 1 in format:
Lecture 1: Images and image filtering
Linear Systems Review Objective
Image Filtering Readings: Ch 5: 5. 4, 5. 5, 5. 6, , 5
Most slides from Steve Seitz
Lecture 7 Spatial filtering.
All about convolution.
Fundamentals of Spatial Filtering
Spatial operations and transformations
Lecture: Pixels and Filters
Presentation transcript:

Lecture: Pixels and Filters Juan Carlos Niebles and Ranjay Krishna Stanford Vision Lab

What we will learn today? Image sampling and quantization Image histograms Images as functions Linear systems (filters) Convolution and correlation Some background reading: Forsyth and Ponce, Computer Vision, Chapter 7

What we will learn today? Image sampling and quantization Image histograms Images as functions Linear systems (filters) Convolution and correlation Some background reading: Forsyth and Ponce, Computer Vision, Chapter 7

Types of Images

Binary image representation Slide credit: Ulas Bagci

Grayscale image representation Slide credit: Ulas Bagci

Color Image - one channel

Color image representation Slide credit: Ulas Bagci

Images are sampled What happens when we zoom into the images we capture?

Errors due Sampling Slide credit: Ulas Bagci

Resolution is a sampling parameter, defined in dots per inch (DPI) or equivalent measures of spatial pixel density, and its standard value for recent screen technologies is 72 dpi Slide credit: Ulas Bagci

Images are Sampled and Quantized An image contains discrete number of pixels A simple example Pixel value: “grayscale” (or “intensity”): [0,255] 75 231 Last time: Images as Matrices intensity temperature depth 148

Images are Sampled and Quantized An image contains discrete number of pixels A simple example Pixel value: “grayscale” (or “intensity”): [0,255] “color” RGB: [R, G, B] Lab: [L, a, b] HSV: [H, S, V] [90, 0, 53] [249, 215, 203] [213, 60, 67]

With this loss of information (from sampling and quantization), Can we still use images for useful tasks?

What we will learn today? Image sampling and quantization Image histograms Images as functions Linear systems (filters) Convolution and correlation Some background reading: Forsyth and Ponce, Computer Vision, Chapter 7

Histogram Histogram of an image provides the frequency of the brightness (intensity) value in the image. def histogram(im): h = np.zeros(255) for row in im.shape[0]: for col in im.shape[1]: val = im[row, col] h[val] += 1

Histogram Histogram captures the distribution of gray levels in the image. How frequently each gray level occurs in the image Q

Histogram Slide credit: Dr. Mubarak Shah

Histogram – use case Slide credit: Dr. Mubarak Shah

Histogram – another use case Slide credit: Dr. Mubarak Shah

What we will learn today? Image sampling and quantization Image histograms Images as functions Linear systems (filters) Convolution and correlation Some background reading: Forsyth and Ponce, Computer Vision, Chapter 7

Images as discrete functions Images are usually digital (discrete): Sample the 2D space on a regular grid Represented as a matrix of integer values pixel

Images as coordinates Cartesian coordinates Notation for discrete functions

Images as coordinates Cartesian coordinates Notation for discrete functions

Images as functions An Image as a function f from R2 to RM: f( x, y ) gives the intensity at position ( x, y ) Defined over a rectangle, with a finite range: f: [a,b] x [c,d ]  [0,255] Domain support range

Images as functions An Image as a function f from R2 to RM: f( x, y ) gives the intensity at position ( x, y ) Defined over a rectangle, with a finite range: f: [a,b] x [c,d ]  [0,255] Domain support range Each r, g, b are functions that like the one above A color image:

Histograms are a type of image function

What we will learn today? Image sampling and quantization Image histograms Images as functions Linear systems (filters) Convolution and correlation Some background reading: Forsyth and Ponce, Computer Vision, Chapter 7

Systems and Filters Filtering: Goals: Forming a new image whose pixel values are transformed from original pixel values Goals: Goal is to extract useful information from images, or transform images into another domain where we can modify/enhance image properties Features (edges, corners, blobs…) super-resolution; in-painting; de-noising

Super-resolution De-noising In-painting Bertamio et al

System and Filters we define a system as a unit that converts an input function f[n,m] into an output (or response) function g[n,m], where (n,m) are the independent variables. In the case for images, (n,m) represents the spatial position in the image.

Images as coordinates Cartesian coordinates Notation for discrete functions

2D discrete-space systems (filters) S is the system operator, defined as a mapping or assignment of a member of the set of possible outputs g[n,m] to each member of the set of possible inputs f[n,m].

Filter example #1: Moving Average

Filter example #1: Moving Average 2D DS moving average over a 3 × 3 window of neighborhood h 1 Board: Input image Output image each pixel results from a neighborhood operation

Filter example #1: Moving Average 90 90 Courtesy of S. Seitz

Filter example #1: Moving Average 90 90 10 37

Filter example #1: Moving Average 90 90 10 20

Filter example #1: Moving Average 90 90 10 20 30

Filter example #1: Moving Average 90 10 20 30

Filter example #1: Moving Average 90 10 20 30 40 60 90 50 80 What is the effect on the output? What happens to the sharp edges?

Filter example #1: Moving Average In summary: This filter creates a new pixel with an average of its neighborhood. Achieve smoothing effect (remove sharp features) 1

Filter example #1: Moving Average

Filter example #2: Image Segmentation Image segmentation based on a simple threshold: 255,

Example Properties of systems Amplitude properties: Additivity Homogeneity Superposition Stability Invertibility

Example Properties of linear systems Spatial properties Causality Shift invariance:

These properties have to be true for Linear Systems Amplitude properties: Additivity Homogeneity Superposition

These properties have to be true for Linear SHIFT INVARIANT Systems Amplitude properties: Additivity Homogeneity Superposition Shift invariance:

What does shifting an image look like? Cartesian coordinates

Is the moving average system is shift invariant? 90 10 20 30 40 60 90 50 80

Is the moving average system is shift invariant? 𝑔 𝑛,𝑚 = 1 9 𝑘=𝑛−1 𝑛+1 𝑙=𝑚−1 𝑚+1 𝑓[𝑘,𝑙] = 1 9 𝑘=−1 1 𝑙=−1 1 𝑓[𝑛−𝑘,𝑚−𝑙] Let 𝑓[𝑛− 𝑛 0 ,𝑚− 𝑚 0 ] be a shifted input of 𝑓[𝑛,𝑚] Now let’s pass 𝑓[𝑛− 𝑛 0 ,𝑚− 𝑚 0 ] through the system: 𝑓[𝑛− 𝑛 0 ,𝑚− 𝑚 0 ] 𝑆 1 9 𝑘=−1 1 𝑙=−1 1 𝑓[𝑛− 𝑛 0 −𝑘,𝑚− 𝑚 0 −𝑙] Yes! = g[𝑛− 𝑛 0 ,𝑚− 𝑚 0 ]

Is the moving average system is casual? 𝑔[𝑛,𝑚]= 1 9 𝑘=−1 1 𝑙=−1 1 𝑓[𝑛−𝑘,𝑚−𝑙] f[𝑛,𝑚] g[𝑛,𝑚] 90 10 20 30 40 60 90 50 80

Linear Systems (filters) Linear filtering: Form a new image whose pixels are a weighted sum of original pixel values Use the same set of weights at each point S is a linear system (function) iff it S satisfies Moving average is an example of a linear filter. Here a more general definition. 𝑆[ 𝛼𝑓 𝑖 𝑛,𝑚 + 𝛽 𝑓 𝑗 𝑘,𝑙 ] = 𝛼 𝑆[ 𝑓 𝑖 𝑛,𝑚 ] + 𝛽 𝑆[ 𝑓 𝑗 𝑘,𝑙 ] superposition property

Linear Systems (filters) Is the moving average a linear system? Is thresholding a linear system? f1[n,m] + f2[n,m] > T f1[n,m] < T f2[n,m]<T Show on the board equations for moving average. No!

How do we characterize a linear shift invariant (LSI) system? Mathematically, how do you calculate g[n,m] from f[n,m]

2D impulse function 1 at [0,0]. 0 everywhere else

Impulse response to the moving filter 𝛿 2 𝑆 ℎ 𝑛,𝑚 = 1 9 𝑘=−1 1 𝑙=−1 1 𝛿 2 [𝑛−𝑘,𝑚−𝑙] LSI systems can be characterized by the impulse response. \delta_2 is the impulse (an image with 1 pixel =1, all the rest =0) h is the response

Impulse response to the moving filter 𝛿 2 𝑆 ℎ 𝑛,𝑚 = 1 9 𝑘=−1 1 𝑙=−1 1 𝛿 2 [𝑛−𝑘,𝑚−𝑙] ? h[0,0] LSI systems can be characterized by the impulse response. \delta_2 is the impulse (an image with 1 pixel =1, all the rest =0) h is the response g[0,0]

Impulse response to the moving filter 𝛿 2 𝑆 ℎ 𝑛,𝑚 = 1 9 𝑘=−1 1 𝑙=−1 1 𝛿 2 [𝑛−𝑘,𝑚−𝑙] 1/9 ? h[0,0] h[0,1] LSI systems can be characterized by the impulse response. \delta_2 is the impulse (an image with 1 pixel =1, all the rest =0) h is the response g[0,0]

Impulse response to the moving filter 𝛿 2 𝑆 ℎ 𝑛,𝑚 = 1 9 𝑘=−1 1 𝑙=−1 1 𝛿 2 [𝑛−𝑘,𝑚−𝑙] 1/9 1/9 h[0,0] h[0,1] LSI systems can be characterized by the impulse response. \delta_2 is the impulse (an image with 1 pixel =1, all the rest =0) h is the response ? g[0,0] h[1,1]

Impulse response to the moving filter 𝛿 2 𝑆 ℎ 𝑛,𝑚 = 1 9 𝑘=−1 1 𝑙=−1 1 𝛿 2 [𝑛−𝑘,𝑚−𝑙] 1/9 1/9 h[0,0] h[0,1] LSI systems can be characterized by the impulse response. \delta_2 is the impulse (an image with 1 pixel =1, all the rest =0) h is the response 1/9 g[0,0] h[1,1]

Impulse response to the moving filter 𝛿 2 𝑆 ℎ 𝑛,𝑚 = 1 9 𝑘=−1 1 𝑙=−1 1 𝛿 2 [𝑛−𝑘,𝑚−𝑙] 1/9 1/9 ? h[0,0] h[0,1] h[0,2] LSI systems can be characterized by the impulse response. \delta_2 is the impulse (an image with 1 pixel =1, all the rest =0) h is the response 1/9 g[0,0] h[1,1]

Impulse response to the moving filter 𝛿 2 𝑆 ℎ 𝑛,𝑚 = 1 9 𝑘=−1 1 𝑙=−1 1 𝛿 2 [𝑛−𝑘,𝑚−𝑙] 1/9 1/9 h[0,0] h[0,1] h[0,2] LSI systems can be characterized by the impulse response. \delta_2 is the impulse (an image with 1 pixel =1, all the rest =0) h is the response 1/9 g[0,0] h[1,1]

Impulse response to the moving filter 1/9 1/9 1/9 h[-1,-1] 𝛿 2 𝑆 𝑔 𝑛,𝑚 = 1 9 𝑘=−1 1 𝑙=−1 1 𝛿 2 [𝑛−𝑘,𝑚−𝑙] 1/9 1/9 1/9 h[0,0] h[0,1] h[0,2] LSI systems can be characterized by the impulse response. \delta_2 is the impulse (an image with 1 pixel =1, all the rest =0) h is the response 1/9 1/9 1/9 g[0,0] h[1,1]

Impulse response of the 3 by 3 moving average filter 1

Any linear shift invariant system By passing an impulse into a linear system, we get it’s impulse response. So, if we don’t know what the linear system is doing, we can pass an impulse into it to get a filter ℎ 𝑛,𝑚 that tells us what the system is actually doing. But how do we use ℎ 𝑛,𝑚 to calculate g 𝑛,𝑚 from f 𝑛,𝑚 𝛿 2 [𝑛,𝑚] ℎ[𝑛,𝑚]

General linear shift invariant system Let’s say our input f is a 3x3 image: We can rewrite 𝑓 𝑛,𝑚 as a sum of delta functions: 𝑓 𝑛,𝑚 =𝑓 0,0 × 𝛿 2 [𝑛−0,𝑚−0] + 𝑓 0,1 × 𝛿 2 [𝑛−0,𝑚−1] + 𝑓 0,2 × 𝛿 2 [𝑛−0,𝑚−2] + … f[2,2] f[2,1] f[2,0] f[1,2] f[1,1] f[1,0] f[0,1] f[0,0] 𝑓 𝑛,𝑚 = 𝑘=−∞ ∞ 𝑙=−∞ ∞ 𝑓 𝑘,𝑙 × 𝛿 2 [𝑛−𝑘,𝑚−𝑙] Or you can write it as:

3 properties we need: Now, we know what happens when we send a delta function through a LSI system: 𝛿 2 [𝑛,𝑚] ℎ[𝑛,𝑚] We also know that LSI systems shift the output if the input is shifted: 𝛿 2 [𝑛−𝑘,𝑚−𝑙] ℎ[𝑛−𝑘,𝑚−𝑙] Finally, the superposition principle: 𝑆[ 𝛼𝑓 𝑖 𝑛,𝑚 + 𝛽 𝑓 𝑗 𝑘,𝑙 ] = 𝛼 𝑆[ 𝑓 𝑖 𝑛,𝑚 ] + 𝛽 𝑆[ 𝑓 𝑗 𝑘,𝑙 ]

We can generalize this superposition principle… 𝑆[ 𝛼𝑓 𝑖 𝑛,𝑚 + 𝛽 𝑓 𝑗 𝑘,𝑙 ] = 𝛼 𝑆[ 𝑓 𝑖 𝑛,𝑚 ] + 𝛽 𝑆[ 𝑓 𝑗 𝑘,𝑙 ] … with our summation of deltas… 𝑓 𝑛,𝑚 = 𝑘=−∞ ∞ 𝑙=−∞ ∞ 𝑓 𝑘,𝑙 × 𝛿 2 [𝑛−𝑘,𝑚−𝑙] … as follows: 𝑆 𝑘=−∞ ∞ 𝑙=−∞ ∞ 𝑓 𝑘,𝑙 × 𝛿 2 [𝑛−𝑘,𝑚−𝑙] = 𝑘=−∞ ∞ 𝑙=−∞ ∞ 𝑓 𝑘,𝑙 × 𝑆 𝛿 2 [𝑛−𝑘,𝑚−𝑙]

Linear shift invariant system 𝑆 𝑘=−∞ ∞ 𝑙=−∞ ∞ 𝑓 𝑘,𝑙 × 𝛿 2 [𝑛−𝑘,𝑚−𝑙] = 𝑘=−∞ ∞ 𝑙=−∞ ∞ 𝑓 𝑘,𝑙 × 𝑆 𝛿 2 [𝑛−𝑘,𝑚−𝑙] = 𝑘=−∞ ∞ 𝑙=−∞ ∞ 𝑓 𝑘,𝑙 ×ℎ[𝑛−𝑘,𝑚−𝑙]

Linear Shift Invariant systems An LSI system is completely specified by its impulse response. We can write any function as a sum of impulses… Let’s pass this function over our system.. Using superposition, we get a sum over the impulse responses… Final equation: we call this a convolution. Applying the impulse response h to f at all locations. Discrete convolution 𝑓 𝑛,𝑚 ∗ℎ[𝑛,𝑚]

What we will learn today? Image sampling and quantization Image histograms Images as functions Linear systems (filters) Convolution and correlation Some background reading: Forsyth and Ponce, Computer Vision, Chapter 7

2D convolution 2D convolution is very similar to 1D. The main difference is that we now have to iterate over 2 axis instead of 1.   Assume we have a filter(h[,]) that is 3x3. and an image (f[,]) that is 7x7.

2D convolution 2D convolution is very similar to 1D. The main difference is that we now have to iterate over 2 axis instead of 1.   Assume we have a filter(h[,]) that is 3x3. and an image (f[,]) that is 7x7.

2D convolution 2D convolution is very similar to 1D. The main difference is that we now have to iterate over 2 axis instead of 1.   Assume we have a filter(h[,]) that is 3x3. and an image (f[,]) that is 7x7.

2D convolution 2D convolution is very similar to 1D. The main difference is that we now have to iterate over 2 axis instead of 1.   Assume we have a filter(h[,]) that is 3x3. and an image (f[,]) that is 7x7.

2D convolution 2D convolution is very similar to 1D. The main difference is that we now have to iterate over 2 axis instead of 1.   Assume we have a filter(h[,]) that is 3x3. and an image (f[,]) that is 7x7.

2D convolution 2D convolution is very similar to 1D. The main difference is that we now have to iterate over 2 axis instead of 1.   Assume we have a filter(h[,]) that is 3x3. and an image (f[,]) that is 7x7.

Slide credit: Ulas Bagci

2D convolution example Slide credit: Song Ho Ahn

2D convolution example Slide credit: Song Ho Ahn

2D convolution example Slide credit: Song Ho Ahn

2D convolution example Slide credit: Song Ho Ahn

2D convolution example Slide credit: Song Ho Ahn

2D convolution example Slide credit: Song Ho Ahn

2D convolution example Slide credit: Song Ho Ahn

Convolution in 2D - examples 1 ? = * Original

Convolution in 2D - examples 1 = * Original Filtered (no change)

Convolution in 2D - examples 1 ? = * Original

Convolution in 2D - examples 1 = * Original Shifted right By 1 pixel

Convolution in 2D - examples ? 1 = * Original

Convolution in 2D - examples 1 = * Original Blur (with a box filter)

Convolution in 2D - examples 2 1 = ? (Note that filter sums to 1) Original “details of the image” Original image – blur = details! - 1 1 1 +

What does blurring take away? – = original smoothed (5x5) Detailed Let’s add it back: = + original Detailed Sharpened

Convolution in 2D – Sharpening filter - 2 1 = Original Sharpening filter: Accentuates differences with local average

Image support and edge effect A computer will only convolve finite support signals. That is: images that are zero for n,m outside some rectangular region numpy’s convolution performs 2D DS convolution of finite-support signals. = * (N1 + N2 − 1) × (M1 +M2 − 1) N2 ×M2 N1 ×M1

Image support and edge effect A computer will only convolve finite support signals. What happens at the edge? • zero “padding” • edge value replication • mirror extension • more (beyond the scope of this class) f h

Slide credit: Wolfram Alpha

What we will learn today? Image sampling and quantization Image histograms Images as functions Linear systems (filters) Convolution and correlation Some background reading: Forsyth and Ponce, Computer Vision, Chapter 7

(Cross) correlation (symbol: ) Cross correlation of two 2D signals f[n,m] and h[n,m]: 𝑓 𝑛,𝑚 ∗∗ℎ[𝑛,𝑚]= 𝑘=−∞ ∞ 𝑙=−∞ ∞ 𝑓 𝑛,𝑚 × ℎ[𝑛+𝑘,𝑚+𝑙] Equivalent to a convolution without the flip Equation is about the same. Difference is with the complex conjugate)

(Cross) correlation – example Use: compare similarity between “kernel” and image. Courtesy of J. Fessler

(Cross) correlation – example Use: compare similarity between “kernel” and image. Courtesy of J. Fessler

(Cross) correlation – example Use: compare similarity between “kernel” and image. Courtesy of J. Fessler numpy’s correlate Courtesy of J. Fessler

(Cross) correlation – example Left Right scanline Norm. cross corr. score

f*h f**h    

Cross Correlation Application: Vision system for TV remote control - uses template matching This is a figure from the book, figure 7.16. Read the caption for the story! Figure from “Computer Vision for Interactive Computer Graphics,” W.Freeman et al, IEEE Computer Graphics and Applications, 1998 copyright 1998, IEEE

Properties • Commutative property: • Associative property: • Distributive property: The order doesn’t matter!

Properties • Shift property: • Shift-invariance:

Convolution vs. (Cross) Correlation A convolution is an integral that expresses the amount of overlap of one function as it is shifted over another function. convolution is a filtering operation Correlation compares the similarity of two sets of data. Correlation computes a measure of similarity of two input signals as they are shifted by one another. The correlation result reaches a maximum at the time when the two signals match best . correlation is a measure of relatedness of two signals

What we have learned today? Image sampling and quantization Image histograms Images as functions Linear systems (filters) Convolution and correlation