Convolution, Edge Detection, Sampling
Transcript of Convolution, Edge Detection, Sampling
![Page 1: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/1.jpg)
Convolution, Edge Detection, Sampling
15-463: Computational PhotographyAlexei Efros, CMU, Fall 2006Some slides from Steve Seitz
![Page 2: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/2.jpg)
Fourier spectrum
![Page 3: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/3.jpg)
Fun and games with spectra
![Page 4: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/4.jpg)
4
Gaussian filteringA Gaussian kernel gives less weight to pixels further from the center of the window
This kernel is an approximation of a Gaussian function:
0000000000
00000009000
0000000000
009090909090000
00909090090000
009090909090000
009090909090000
009090909090000
0000000000
0000000000
121
242
121
![Page 5: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/5.jpg)
ConvolutionRemember cross-correlation:
A convolution operation is a cross-correlation where the filter is flipped both horizontally and vertically before being applied tothe image:
It is written:
Suppose H is a Gaussian or mean kernel. How does convolution differ from cross-correlation?
![Page 6: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/6.jpg)
The Convolution TheoremThe greatest thing since sliced (banana) bread!
• The Fourier transform of the convolution of two functions is the product of their Fourier transforms
• The inverse Fourier transform of the product of two Fourier transforms is the convolution of the two inverse Fourier transforms
• Convolution in spatial domain is equivalent to multiplication in frequency domain!
]F[]F[]F[ hghg =∗
][F][F][F 111 hggh −−− ∗=
![Page 7: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/7.jpg)
Fourier Transform pairs
![Page 8: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/8.jpg)
2D convolution theorem example
*
f(x,y)
h(x,y)
g(x,y)
|F(sx,sy)|
|H(sx,sy)|
|G(sx,sy)|
![Page 9: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/9.jpg)
Low-pass, Band-pass, High-pass filterslow-pass:
band-pass:
what’s high-pass?
![Page 10: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/10.jpg)
Edges in images
![Page 11: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/11.jpg)
Image gradientThe gradient of an image:
The gradient points in the direction of most rapid change in intensity
The gradient direction is given by:
• how does this relate to the direction of the edge?The edge strength is given by the gradient magnitude
![Page 12: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/12.jpg)
Effects of noiseConsider a single row or column of the image
• Plotting intensity as a function of position gives a signal
Where is the edge?
How to compute a derivative?
![Page 13: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/13.jpg)
Where is the edge?
Solution: smooth first
Look for peaks in
![Page 14: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/14.jpg)
Derivative theorem of convolution
This saves us one operation:
![Page 15: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/15.jpg)
Laplacian of Gaussian
Consider
Laplacian of Gaussianoperator
Where is the edge? Zero-crossings of bottom graph
![Page 16: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/16.jpg)
2D edge detection filters
is the Laplacian operator:
Laplacian of Gaussian
Gaussian derivative of Gaussian
![Page 17: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/17.jpg)
MATLAB demo
g = fspecial('gaussian',15,2);imagesc(g)surfl(g)gclown = conv2(clown,g,'same');imagesc(conv2(clown,[-1 1],'same'));imagesc(conv2(gclown,[-1 1],'same'));dx = conv2(g,[-1 1],'same');imagesc(conv2(clown,dx,'same'));lg = fspecial('log',15,2);lclown = conv2(clown,lg,'same');imagesc(lclown)imagesc(clown + .2*lclown)
![Page 18: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/18.jpg)
Image Scaling
This image is too big tofit on the screen. Howcan we reduce it?
How to generate a half-sized version?
![Page 19: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/19.jpg)
Image sub-sampling
Throw away every other row and column to create a 1/2 size image
- called image sub-sampling
1/4
1/8
![Page 20: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/20.jpg)
Image sub-sampling
1/4 (2x zoom) 1/8 (4x zoom)
Why does this look so crufty?
1/2
![Page 21: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/21.jpg)
Even worse for synthetic images
![Page 22: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/22.jpg)
Really bad in video
![Page 23: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/23.jpg)
Alias: n., an assumed name
Picket fence recedingInto the distance willproduce aliasing…
Input signal:
x = 0:.05:5; imagesc(sin((2.^x).*x))
Matlab output:
WHY?
Aj-aj-aj:Alias!
Not enough samples
![Page 24: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/24.jpg)
Aliasing• occurs when your sampling rate is not high enough to capture the
amount of detail in your image• Can give you the wrong signal/image—an alias
Where can it happen in images?• During image synthesis:
• sampling continous singal into discrete signal• e.g. ray tracing, line drawing, function plotting, etc.
• During image processing: • resampling discrete signal at a different rate• e.g. Image warping, zooming in, zooming out, etc.
To do sampling right, need to understand the structure of your signal/image
Enter Monsieur Fourier…
![Page 25: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/25.jpg)
Fourier transform pairs
![Page 26: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/26.jpg)
Sampling
w
Spatial domain Frequency domain
1/w
samplingpattern
sampledsignal
![Page 27: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/27.jpg)
Reconstruction
Frequency domain
1/ww
Spatial domain
sincfunction
reconstructedsignal
![Page 28: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/28.jpg)
What happens whenthe sampling rate is too low?
![Page 29: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/29.jpg)
Nyquist RateWhat’s the minimum Sampling Rate 1/w to get rid of
overlaps?
Frequency domain
1/ww
Spatial domain
sincfunction
Sampling Rate ≥ 2 * max frequency in the image• this is known as the Nyquist Rate
![Page 30: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/30.jpg)
AntialiasingWhat can be done?
Sampling rate ≥ 2 * max frequency in the image
1. Raise sampling rate by oversampling• Sample at k times the resolution• continuous signal: easy• discrete signal: need to interpolate
2. Lower the max frequency by prefiltering• Smooth the signal enough• Works on discrete signals
3. Improve sampling quality with better sampling• Nyquist is best case!• Stratified sampling (jittering)• Importance sampling (salaries in Seattle)• Relies on domain knowledge
![Page 31: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/31.jpg)
Sampling
Good sampling:•Sample often or,•Sample wisely
Bad sampling:•see aliasing in action!
![Page 32: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/32.jpg)
Gaussian pre-filtering
G 1/4
G 1/8
Gaussian 1/2Solution: filter the image, then subsample
![Page 33: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/33.jpg)
Subsampling with Gaussian pre-filtering
G 1/4 G 1/8Gaussian 1/2Solution: filter the image, then subsample
![Page 34: Convolution, Edge Detection, Sampling](https://reader034.fdocuments.in/reader034/viewer/2022051506/587c9e0b1a28ab18048b79b4/html5/thumbnails/34.jpg)
Compare with...
1/4 (2x zoom) 1/8 (4x zoom)1/2