Top Banner
Other Filters, etc. Winter in Kraków photographed by Marcin Ryczek Alexei Efros, Fall 2014
55

Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Sep 26, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 2: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Taking derivative by convolution

Page 3: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Partial derivatives with convolution

For 2D function f(x,y), the partial derivative is:

For discrete data, we can approximate using finite differences: To implement above as convolution, what would be the associated filter?

εε

ε

),(),(lim),(0

yxfyxfx

yxf −+=

∂∂

1),(),1(),( yxfyxf

xyxf −+

≈∂

Source: K. Grauman

Page 4: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Partial derivatives of an image

Which shows changes with respect to x?

-1 1

1 -1 or -1 1

xyxf

∂∂ ),(

yyxf

∂∂ ),(

Page 5: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Finite difference filters Other approximations of derivative filters exist:

Source: K. Grauman

Page 6: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

The gradient points in the direction of most rapid increase in intensity

Image gradient

The gradient of an image:

The gradient direction is given by

Source: Steve Seitz

The edge strength is given by the gradient magnitude

• How does this direction relate to the direction of the edge?

Page 7: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Image Gradient

xyxf

∂∂ ),(

yyxf

∂∂ ),(

Page 8: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Effects of noise Consider a single row or column of the image

• Plotting intensity as a function of position gives a signal

Where is the edge? Source: S. Seitz

Page 9: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Solution: smooth first

• To find edges, look for peaks in )( gfdxd

f

g

f * g

)( gfdxd

Source: S. Seitz

Page 10: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Derivative theorem of convolution

This saves us one operation:

This image cannot currently be displayed.

Page 11: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Derivative of Gaussian filter

* [1 -1] =

Page 12: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Derivative of Gaussian filter

Which one finds horizontal/vertical edges?

x-direction y-direction

Page 13: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Example

input image (“Lena”)

Page 14: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Compute Gradients (DoG)

X-Derivative of Gaussian

Y-Derivative of Gaussian

Gradient Magnitude

Page 15: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Get Orientation at Each Pixel Threshold at minimum level Get orientation

theta = atan2(-gy, gx)

Page 16: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

MATLAB demo

im = im2double(imread(filemane)); g = fspecial('gaussian',15,2); imagesc(g); surfl(g); gim = conv2(im,g,'same'); imagesc(conv2(im,[-1 1],'same')); imagesc(conv2(gim,[-1 1],'same')); dx = conv2(g,[-1 1],'same'); Surfl(dx); imagesc(conv2(im,dx,'same'));

Page 17: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Review: Smoothing vs. derivative filters Smoothing filters

• Gaussian: remove “high-frequency” components; “low-pass” filter

• Can the values of a smoothing filter be negative? • What should the values sum to?

– One: constant regions are not affected by the filter

Derivative filters • Derivatives of Gaussian • Can the values of a derivative filter be negative? • What should the values sum to?

– Zero: no response in constant regions • High absolute value at points of high contrast

Page 18: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Early processing in humans filters for various orientations and scales of frequency

Perceptual cues in the mid 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

Clues from Human Perception

Page 19: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Frequency Domain and Perception

Campbell-Robson contrast sensitivity curve

Page 20: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Da Vinci and Peripheral Vision

Page 21: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Leonardo playing with peripheral vision

Page 22: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Freq. Perception Depends on Color

R G B

Page 23: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Lossy Image Compression (JPEG)

Block-based Discrete Cosine Transform (DCT)

Page 24: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Using DCT in JPEG The first coefficient B(0,0) is the DC component,

the average intensity The top-left coeffs represent low frequencies,

the bottom right – high frequencies

Page 25: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Image compression using DCT Quantize

• More coarsely for high frequencies (which also tend to have smaller values)

• Many quantized high frequency values will be zero

Encode • Can decode with inverse dct

Quantization table

Filter responses

Quantized values

Page 26: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

JPEG Compression Summary Subsample color by factor of 2

• People have bad resolution for color

Split into blocks (8x8, typically), subtract 128 For each block

a. Compute DCT coefficients for b. Coarsely quantize

– Many high frequency components will become zero

c. Encode (e.g., with Huffman coding)

http://en.wikipedia.org/wiki/YCbCr http://en.wikipedia.org/wiki/JPEG

Page 27: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Block size in JPEG Block size

• small block – faster – correlation exists between neighboring pixels

• large block – better compression in smooth regions

• It’s 8x8 in standard JPEG

Page 28: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

JPEG compression comparison

89k 12k

Page 29: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Denoising

Additive Gaussian Noise

Gaussian Filter

Page 30: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Smoothing with larger standard deviations suppresses noise, but also blurs the image

Reducing Gaussian noise

Source: S. Lazebnik

Page 31: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Reducing salt-and-pepper noise by Gaussian smoothing

3x3 5x5 7x7

Page 32: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Alternative idea: Median filtering A median filter operates over a window by

selecting the median intensity in the window

• Is median filtering linear? Source: K. Grauman

Page 33: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Median filter What advantage does median filtering

have over Gaussian filtering? • Robustness to outliers

Source: K. Grauman

Page 34: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Median filter Salt-and-pepper

noise Median filtered

Source: M. Hebert

MATLAB: medfilt2(image, [h w])

Page 35: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Median vs. Gaussian filtering 3x3 5x5 7x7

Gaussian

Median

Page 36: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

A Gentle Introduction to Bilateral Filtering and its Applications

“Fixing the Gaussian Blur”: the Bilateral Filter

Sylvain Paris – MIT CSAIL

Page 37: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Blur Comes from Averaging across Edges

*

*

*

input output

Same Gaussian kernel everywhere.

Page 38: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Bilateral Filter No Averaging across Edges

*

*

*

input output

The kernel shape depends on the image content.

[Aurich 95, Smith 97, Tomasi 98]

Page 39: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

space weight

not new

range weight

I

new

normalization factor

new

Bilateral Filter Definition: an Additional Edge Term

( ) ( )∑∈

−−=S

IIIGGW

IBFq

qqpp

p qp ||||||1][rs σσ

Same idea: weighted average of pixels.

Page 40: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Illustration a 1D Image

• 1D image = line of pixels

• Better visualized as a plot

pixel intensity

pixel position

Page 41: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

space

Gaussian Blur and Bilateral Filter

space range normalization

Gaussian blur

( ) ( )∑∈

−−=S

IIIGGW

IBFq

qqpp

p qp ||||||1][rs σσ

Bilateral filter [Aurich 95, Smith 97, Tomasi 98]

space

space range

p

p

q

q

( )∑∈

−=S

IGIGBq

qp qp ||||][ σ

Page 42: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

q

The image part with relationship ID rId10 was not found in the file.

Bilateral Filter on a Height Field

output input

( ) ( )∑∈

−−=S

IIIGGW

IBFq

qqpp

p qp ||||||1][rs σσ

p

reproduced from [Durand 02]

Page 43: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Space and Range Parameters

• space σs : spatial extent of the kernel, size of the considered neighborhood.

• range σr : “minimum” amplitude of an edge

( ) ( )∑∈

−−=S

IIIGGW

IBFq

qqpp

p qp ||||||1][rs σσ

Page 44: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

Influence of Pixels

p

Only pixels close in space and in range are considered.

space

range

Page 45: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

σs = 2

σs = 6

σs = 18

σr = 0.1 σr = 0.25 σr = ∞

(Gaussian blur)

input

Exploring the Parameter Space

Page 46: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

σs = 2

σs = 6

σs = 18

σr = 0.1 σr = 0.25 σr = ∞

(Gaussian blur)

input

Varying the Range Parameter

Page 47: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

input

Page 48: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

σr = 0.1

Page 49: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

σr = 0.25

Page 50: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

σr = ∞ (Gaussian blur)

Page 51: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

σs = 2

σs = 6

σs = 18

σr = 0.1 σr = 0.25 σr = ∞

(Gaussian blur)

input

Varying the Space Parameter

Page 52: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

input

Page 53: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

σs = 2

Page 54: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

σs = 6

Page 55: Other Filters, etc.cs194-26/fa14/Lectures/MiscFilters.pdf · Image compression using DCT Quantize • More coarsely for high frequencies (which also tend to have smaller values) •

σs = 18