Rather than picking from fixed convolutions, we learn the elements of the filters. A convolution is a linear filter that measures the effect one signal has on another signal.

If $x$ is the $(n,n)$ input signal (image) and $w$ is the $(2m+1,2m+1)$ filter, then the 2D convolution is given by

$z[i_{1},i_{2}]=∑_{j_{1}=−m}∑_{j_{2}=−m}w[j_{1},j_{2}]x[i_{1}+j_{1},i_{2}+j_{2}]$

### Convolutional Layer

Standard is DxWxH

$K$ is the number of filters, $F$ is the spatial extent of filters (kernel size), $S$ is the stride, and $P$ is the padding

- $W_{out}=(W_{input}−F+2P)/S+1$
- $H_{out}=(H_{input}−F+2P)/S+1$
- $D_{out}=K$

Total number of learnable parameters: $(F×F×D_{input})×K+K$.

### Pooling Layer

Makes representation smaller, more manageable and spatially invariant.

- $W_{out}=(W_{input}−F)/S+1$
- $H_{out}=(H_{input}−F)/S+1$
- $D_{out}=D_{input}$

Total number of learnable parameters: 0.

### Layer Summary

- Convolutional Layer: applies a set of learnable filters
- Pooling Layer: performs spatial downsampling
- Fully-connected Layer: same as any regular neural network

A CNN then just learns a hierarchy of filters

### Properties of Convolution

- Associative. $G⊗(F⊗I(x,y))=(G⊗F)⊗I(x,y)$
- Symmetric. $(G⊗F)⊗I(x,y)=(F⊗G)⊗I(x,y)$

Correlation, on the other hand, is generally not associative.

For 1D Gaussians, we note $G_{σ_{1}}(x)⊗G_{σ_{2}}(x)=G_{σ_{1}+σ_{2}}(x)$. Convolving with $G_{σ}(x)⊗G_{σ}(x)=G_{2σ}(x)$

### Boundary Effects

- Ignore these locations: make the computation undefined for the outsize $k$ rows/columns
- Pad with zeroes: return zero whenever of value of $I$ is required at some position outside the image
- Assume periodicity: wrap image around
- Reflect border

### Pillbox

A 2D pillbox is rotationally invariant but not separable

$f(x,y)=πr_{2}1 {10 ifx_{2}+y_{2}≤r_{2}otherwise $An efficient implementation would represent a 2D box filter as the sum of a 2D pillbox and some “extra corner bits”

### Gaussian Filters

- Box filter doesn’t apply well for lens defocus. A circular pillbox is a much better model for defocus
- Gaussian is a good general smoothing model
- for phenomena
- whenever the CLT applies

Gaussian filters are rotationally invariant.

We get $G_{σ}(x,y)=2πσ_{2}1 exp_{−2σx+y}$ where $σ$ is the standard deviation

For a 3x3, we then need to quantize and truncate it, evaluating $G_{σ}(x,y)$ wherever in the filter. Increasing $σ$ means more blur. Problem with 3x3 is that it truncates too much of the distribution (does not sum up to one), this can cause unintentional darkening.

In general, the Gaussian filter should capture $±3σ$ for $σ=1$ which gives us a 7x7 filter.

#### Efficiency

As both the 2D box filter and 2D Gaussian filter are separable, it can be implemented as two 1D convolutions which convolve each row and then each column separately.

A 2D filter is separable if it can be expressed as an outer product of two 1D filters

A seperable 2D Gaussian only does $2m$ multiplications at each pixel (one for each 1D filter). Considering the image has $n×n$ pixels, then this is a $2m×n_{2}$ multiplications. Assuming $m≈n$, this is $O(n_{3})$

#### Fourier Transform

The basic building block of the fourier transform is the periodic function.

$Asin(ωx+ϕ)$

where $A$ is the amplitude, $ω$ is the angular frequency and $ϕ$ is the phase. Fourier’s claim was that you could add enough of these to get any periodic signal!

### The Convolution Theorem

Let $i_{′}(x,y)=f(x,y)⊗i(x,y)$ be the convolution.

Then, $I_{′}(w_{x},w_{y})=F(w_{x},w_{y})I(w_{x},w_{y})$ which is just a simple element-wise multiplication after applying a Fourier transform to each.

At the expense of two Fourier transforms and one inverse Fourier transform, convolution can be reduced to (complex) multiplication. This speeds up the cost of FFT/IFFT for the image and filter to $O(n_{2}gn)$ and $O(m_{2}gm)$ respectively, dropping the total cost of convolution to $O(n_{2})$

### Convolution Sizing

Convolving two filters of size $m×m$ and $n×n$ results in a filter of size

$(n+2⌊2m ⌋)×(n+2⌊2m ⌋)$

More broadly for a set of $K$ filters of sizes $m_{k}×m_{k}$ the resulting filter will have size

$(m_{1}+2∑_{k=2}⌊2m_{k} ⌋)×(m_{1}+2∑_{k=2}⌊2m_{k} ⌋)$