边缘提取算法.docVIP

  • 7
  • 0
  • 约1.24万字
  • 约 11页
  • 2020-03-03 发布于江苏
  • 举报
public class EdgeDetect : ImageInfo ??? { ??????? /************************************************************ ???????? * ???????? * Roberts, Sobel, Prewitt, Kirsch, GaussLaplacian ???????? * 水平检测、垂直检测、边缘增强、边缘均衡化 ???????? * ???????? ************************************************************/ ? ??? /// summary ??? /// 对两幅图像进行梯度运算 ??? /// /summary ??? /// param name=b1位图 1/param ??? /// param name=b2位图 2/param ??? /// returns/returns ??? private Bitmap Gradient(Bitmap b1, Bitmap b2) ??? { ????? ????? int width = b1.Width; ????? int height = b1.Height; ????? BitmapData data1 = b1.LockBits(new Rectangle(0, 0, width, height), ??????? ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); ????? BitmapData data2 = b2.LockBits(new Rectangle(0, 0, width, height), ??????? ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); ????? unsafe ????? { ??????? byte* p1 = (byte*)data1.Scan0; ??????? byte* p2 = (byte*)data2.Scan0; ??????? int offset = data1.Stride - width * BPP; ??????? for (int y = 0; y height; y++) ??????? { ????????? for (int x = 0; x width; x++) ????????? { ??????????? for (int i = 0; i 3; i++) ??????????? { ????????????? int power = (int)Math.Sqrt((p1[i] * p1[i] + p2[i] * p2[i])); ????????????? p1[i] = (byte)(power 255 ? 255 : power); ??????????? } // i ??????????? p1 += BPP; ??????????? p2 += BPP; ????????? } // x ????????? p1 += offset; ????????? p2 += offset; ??????? } // y ????? } ????? b1.UnlockBits(data1); ????? b2.UnlockBits(data2); ????? Bitmap dstImage = (Bitmap)b1.Clone(); ????? b1.Dispose(); ????? b2.Dispose(); ????? return dstImage; ??? } // end of Gradient ??? /// summary ??? /// 按 Roberts 算子进行边缘检测 ??? /// /summary ??? /// param name=b位图流/param ??? /// returns/returns ??? public Bitmap Roberts(Bitmap b) ??? { ????? int width = b.Width; ????? int height = b.Height; ????? Bitmap dstImage = new Bitmap(width, height); ????? BitmapData srcData = b.LockBits(new Rectangle(0, 0, width, height), ??????? ImageLockMode.ReadOnly, PixelFormat.Format3

文档评论(0)

1亿VIP精品文档

相关文档