-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathfilters.tex
162 lines (158 loc) · 3.97 KB
/
filters.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
%!TEX root = cv-sheet.tex
\section{Digital Filters}
\subsection{Convolution}
For an $n\times m$ kernel $K$:
\[
I(x,y) = \sum_{k=-\frac{m}{2}}^{\frac{m}{2}}{\sum_{l=-\frac{n}{2}}^{\frac{n}{2}}{I_1(x+k,y+l)K(k,l)}}
\]
\subsection{Noise}
\begin{enumerate}
\item Salt \& pepper noise: the color of a noisy pixel has no relation to surrounding pixels.
\item Gaussian noise: each pixel is changed from its original value by a small amount.
\end{enumerate}
\subsubsection{Smoothing Filters}
\subsubsection{Linear Filters}
$LFilter(I_1 + I_2) = LFilter(I_1) + LFilter(I_2)$
\begin{enumerate}
\item Uniform (mean) filter
\item Triangular filter
\item Gaussian filter
\end{enumerate}
\subsubsection{Non-linear Filters}
\begin{enumerate}
\item Median filter
\item Kuwahara filter
\end{enumerate}
\subsection{Uniform (Mean) Filter}
\begin{itemize}
\item replace each pixel with the mean of its neighbourhood.
\item all coeffs. in kernel have same weights.
\item smoothing effect increases with kernel size.
\item filter is always normalized (divide by sum of weights).
\end{itemize}
\begin{tabular}{c|c}
\begin{tabular}{|c|c|c|}
\hline
1 & 1 & 1\\
\hline
1 & 1 & 1\\
\hline
1 & 1 & 1\\
\hline
\end{tabular}$\ *\ \frac{1}{9}$
& $3 \times 3$ rectang. \emph{OR} circ. kernel $(R=1.5)$
\end{tabular}
\begin{tabular}{c|c}
\begin{tabular}{|c|c|c|c|c|}
\hline
1 & 1 & 1 & 1 & 1\\
\hline
1 & 1 & 1 & 1 & 1\\
\hline
1 & 1 & 1 & 1 & 1\\
\hline
1 & 1 & 1 & 1 & 1\\
\hline
1 & 1 & 1 & 1 & 1\\
\hline
\end{tabular}$\ *\ \frac{1}{25}$
& $5 \times 5$ rectang. kernel
\end{tabular}
\begin{tabular}{c|c}
\begin{tabular}{|c|c|c|c|c|}
\hline
0 & 1 & 1 & 1 & 0\\
\hline
1 & 1 & 1 & 1 & 1\\
\hline
1 & 1 & 1 & 1 & 1\\
\hline
1 & 1 & 1 & 1 & 1\\
\hline
0 & 1 & 1 & 1 & 0\\
\hline
\end{tabular}$\ *\ \frac{1}{21}$
& $5 \times 5$ circ. kernel $(R=2.5)$
\end{tabular}
\subsection{Triangular Filter}
\begin{itemize}
\item similar to mean filter, but weights are diff.
\item filter is always normalized (divide by sum of weights).
\end{itemize}
\begin{tabular}{c|c}
\begin{tabular}{|c|c|c|c|c|}
\hline
1 & 2 & 3 & 2 & 1\\
\hline
2 & 4 & 6 & 4 & 2\\
\hline
3 & 6 & 9 & 6 & 3\\
\hline
2 & 4 & 6 & 4 & 2\\
\hline
1 & 2 & 3 & 2 & 1\\
\hline
\end{tabular}$\ *\ \frac{1}{81}$
& $5 \times 5$ pyramid. kernel
\end{tabular}
\begin{tabular}{c|c}
\begin{tabular}{|c|c|c|c|c|}
\hline
0 & 0 & 1 & 0 & 0\\
\hline
0 & 2 & 2 & 2 & 0\\
\hline
1 & 2 & 5 & 2 & 1\\
\hline
0 & 2 & 2 & 2 & 0\\
\hline
0 & 0 & 1 & 0 & 0\\
\hline
\end{tabular}$\ *\ \frac{1}{25}$
& $5 \times 5$ cone kernel $(R=2.5)$
\end{tabular}
\subsection{Gaussian Filter (Blur)}
Gaussian in 1D:
\[
G(x) = \frac{1}{\sqrt{2\pi}\sigma}e^{-\frac{x^2}{2\sigma^{2}}}
\]
Gaussian in 2D:
\[
G(x,y) = \frac{1}{\sqrt{2\pi}\sigma}e^{-\frac{x^2+y^2}{2\sigma^{2}}}
\]
\begin{tabular}{c|c}
\begin{tabular}{|c|c|c|c|c|}
\hline
1 & 4 & 7 & 4 & 1\\
\hline
4 & 16 & 26 & 16 & 4\\
\hline
7 & 26 & 40 & 26 & 7\\
\hline
4 & 16 & 26 & 16 & 4\\
\hline
1 & 4 & 7 & 4 & 1\\
\hline
\end{tabular}$\ *\ \frac{1}{272}$
& $5 \times 5$ Gauss. $(\sigma = 1)$
\end{tabular}
\subsection{Median Filter}
\begin{itemize}
\item reduces noise, but preserves details.
\item replace each pixel with the median of its neighbourhood.
\item sort values {\color{red} (keep duplicates)} and pick the middle one (or average of two middles if even).
\item $median(I_1+I_2)\neq median(I_1)+median(I_2)$.
\end{itemize}
\subsection{Kuwahara Filter}
\begin{itemize}
\item edge-preserving filter, doesn't disturb sharpness and position of edges.
\end{itemize}
\[
\text{Variance: }\sigma^2 = \frac{\sum_{i=1}^{N}{(I(x_i) - mean)^2}}{N}
\]
\begin{enumerate}
\item Calculate mean and variance of each $3 \times 3$ region (upper left, upper right, lower left, \& lower right).
\item Output value of center pixel = mean value of region of smallest variance.
\end{enumerate}
%end of section
\hrule