//
/// 按 Kirsch 算子进行边缘检测
///
/// 位图流
///
public Bitmap Kirsch(Bitmap b)
{
Matrix3x3 m = new Matrix3x3();
// 5 5 5
// -3 0 -3
// -3 -3 -3
m.Init(-3);
m.Center = 0;
m.TopLeft = m.TopMid = m.TopRight = 5;
Bitmap b1 = m.Convolute((Bitmap)b.Clone());
// -3 5 5
// -3 0 5
// -3 -3 -3
m.Init(-3);
m.Center = 0;
m.TopMid = m.TopRight = m.MidRight = 5;
Bitmap b2 = m.Convolute((Bitmap)b.Clone());
// -3 -3 5
// -3 0 5
// -3 -3 5
m.Init(-3);
m.Center = 0;
m.TopRight = m.MidRight = m.BottomRight = 5;
Bitmap b3 = m.Convolute((Bitmap)b.Clone());
// -3 -3 -3
// -3 0 5
// -3 5 5
m.Init(-3);
m.Center = 0;
m.MidRight = m.BottomRight = m.BottomMid = 5;
Bitmap b4 = m.Convolute((Bitmap)b.Clone());
// -3 -3 -3
// -3 0 -3
// 5 5 5
m.Init(-3);
m.Center = 0;
m.BottomLeft = m.BottomMid = m.BottomRight = 5;
Bitmap b5 = m.Convolute((Bitmap)b.Clone());
// -3 -3 -3
// 5 0 -3
// 5 5 -3
m.Init(-3);
m.Center = 0;
m.MidLeft = m.BottomLeft = m.BottomMid = 5;
Bitmap b6 = m.Convolute((Bitmap)b.Clone());
// 5 -3 -3
// 5 0 -3
// 5 -3 -3
m.Init(-3);
m.Center = 0;
m.TopLeft = m.MidLeft = m.BottomLeft = 5;
Bitmap b7 = m.Convolute((Bitmap)b.Clone());
// 5 5 -3
// 5 0 -3
// -3 -3 -3
m.Init(-3);
m.Center = 0;
m.TopLeft = m.MidLeft = m.TopMid = 5;
Bitmap b8 = m.Convolute((Bitmap)b.Clone());
// 梯度运算
Bitmap b9 = Gradient(Gradient(b1, b2), Gradient(b3, b4));
Bitmap b10 = Gradient(Gradient(b5, b6), Gradient(b7, b8));
b = Gradient(b9, b10);
b1.Dispose(); b2.Dispose(); b3.Dispose(); b4.Dispose();
b5.Dispose(); b6.Dispose(); b7.Dispose(); b8.Dispose();
b9.Dispose(); b10.Dispose();
return b;
} // end of Kirsch
///
/// 按 GaussLaplacian 算子进行边缘检测
///
///
///
public Bitmap GaussLaplacian(Bitmap b)
{
int[,] kernel = {
{-2, -4, -4, -4, -2},
{-4, 0, 8, 0, -4},
{-4, 8, 24, 8, -4},
{-4, 0, 8, 0, -4},
{-2, -4, -4, -4, -2}
};
MatrixNxN m = new MatrixNxN();
m.Kernel = kernel;
return m.Convolute(b);
} // end of GaussLaplacian
评论 (0)