大家好,我是小根根,我来为大家解答以上问题。sobel算子是什么意思,Sobel算子是什么很多人还不知道,现在让我们一起来看看吧!
C++Builder下的sobel算子的程序如下:
/// <summary>
/// 按 Sobel 算子进行边缘检测
/// </summary>
/// <param name= "b "> 位图流 </param>
/// <returns> </returns>
public Bitmap Sobel(Bitmap b)
{
Matrix3x3 m = new Matrix3x3();
// -1 -2 -1
// 0 0 0
// 1 2 1
m.Init(0);
m.TopLeft = m.TopRight = -1;
m.BottomLeft = m.BottomRight = 1;
m.TopMid = -2;
m.BottomMid = 2;
Bitmap b1 = m.Convolute((Bitmap)b.Clone());
// -1 0 1
// -2 0 2
// -1 0 1
m.Init(0);
m.TopLeft = m.BottomLeft = -1;
m.TopRight = m.BottomRight = 1;
m.MidLeft = -2;
m.MidRight = 2;
Bitmap b2 = m.Convolute((Bitmap)b.Clone());
// 0 1 2
// -1 0 1
// -2 -1 0
m.Init(0);
m.TopMid = m.MidRight = 1;
m.MidLeft = m.BottomMid = -1;
m.TopRight = 2;
m.BottomLeft = -2;
Bitmap b3 = m.Convolute((Bitmap)b.Clone());
// -2 -1 0
// -1 0 1
// 0 1 2
m.Init(0);
m.TopMid = m.MidLeft = -1;
m.MidRight = m.BottomMid = 1;
m.TopLeft = -2;
m.BottomRight = 2;
Bitmap b4 = m.Convolute((Bitmap)b.Clone());
// 梯度运算
b = Gradient(Gradient(b1, b2), Gradient(b3, b4));
b1.Dispose(); b2.Dispose(); b3.Dispose(); b4.Dispose();
return b;
} // end of Sobel
本文到此讲解完毕了,希望对大家有帮助。