微分フィルタ; Differential Filter
概要
微分フィルタは差分フィルタの一つで、画像のエッジを抽出することができる。プリューウィットフィルタやソーベルフィルタに比べノイズに弱い。
空間フィルタについてはこちらを参照のこと。
重み
微分フィルタにおける重み\(w_{i j}\)は以下で与えられる。
\(\quad \displaystyle \boldsymbol{w} = \begin{bmatrix} 0 & 1 & 0 \\ 0 & 0 & 0 \\ 0 & -1 & 0 \end{bmatrix}, \begin{bmatrix} 0 & -1 & 0 \\ 0 & 0 & 0 \\ 0 & 1 & 0 \end{bmatrix}, \begin{bmatrix} 0 & 0 & 0 \\ 1 & 0 & -1 \\ 0 & 0 & 0 \end{bmatrix}, \begin{bmatrix} 0 & 0 & 0 \\ -1 & 0 & 1 \\ 0 & 0 & 0 \end{bmatrix} \)
横方向と縦方向の微分フィルタの結果を相乗平均することで全方向のエッジが得られる。
結果
ソースコード
GraphicRGB src_graph, dst_graph;
ImageIO.Read(out src_graph, "graph/pepper.png");
var filter_h = new FilterSubtractive(1, new double[,] { { 0, -1, 0 }, { 0, 0, 0 }, { 0, +1, 0 } } );
var filter_v = new FilterSubtractive(1, new double[,] { { 0, 0, 0 }, { -1, 0, +1 }, { 0, 0, 0 } } );
GraphicRGB hdir_graph = Filtering.SubtractFiltering(src_graph, filter_h);
GraphicRGB vdir_graph = Filtering.SubtractFiltering(src_graph, filter_v);
dst_graph = new GraphicRGB(src_graph.Width, src_graph.Height);
for(int x, y = 0, w = dst_graph.Width, h = dst_graph.Height; y < h; y++) {
for(x = 0; x < w; x++) {
RGB ch = hdir_graph.Graph[x, y], cv = vdir_graph.Graph[x, y];
dst_graph.Graph[x, y] = new RGB(Math.Sqrt(ch.R * ch.R + cv.R * cv.R), Math.Sqrt(ch.R * ch.G + cv.G * cv.G), Math.Sqrt(ch.B * ch.B + cv.B * cv.B), 1);
}
}
ImageIO.Write(hdir_graph, "graph/pepper_hdir.png");
ImageIO.Write(vdir_graph, "graph/pepper_vdir.png");
ImageIO.Write(dst_graph, "graph/pepper_edge.png");
関連項目
RGB空間
RGBグラフィックおよびその入出力
フィルタ
グレースケール
ガウシアンフィルタ
バイラテラルフィルタ
モーションブラーフィルタ
ソーベルフィルタ
鮮鋭化フィルタ