C#图像处理之边缘检测(Smoothed)的方法

这篇文章主要介绍了C#图像处理之边缘检测(Smoothed)的方法,使用自定义smoothed算子实现对图像边缘检测的功能,需要的朋友可以参考下

本文实例讲述了C#图像处理之边缘检测(Smoothed)的方法。分享给大家供大家参考。具体如下:

 //定义smoothed算子边缘检测函数 private static Bitmap smoothed(Bitmap a) { int w = a.Width; int h = a.Height; try { Bitmap dstBitmap = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format24bppRgb); System.Drawing.Imaging.BitmapData srcData = a.LockBits(new Rectangle (0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); System.Drawing.Imaging.BitmapData dstData = dstBitmap.LockBits(new Rectangle (0, 0, w, h), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); unsafe { byte* pIn = (byte*)srcData.Scan0.ToPointer(); byte* pOut = (byte*)dstData.Scan0.ToPointer(); byte* p; int stride = srcData.Stride; for (int y = 0; y  0) { vR = Math.Min(255, vR); } else { vR = Math.Max(0, vR); } if (vG > 0) { vG = Math.Min(255, vG); } else { vG = Math.Max(0, vG); } if (vB > 0) { vB = Math.Min(255, vB); } else { vB = Math.Max(0, vB); } pOut[0] = (byte)vB; pOut[1] = (byte)vG; pOut[2] = (byte)vR; } pIn += 3; pOut += 3; } pIn += srcData.Stride - w * 3; pOut += srcData.Stride - w * 3; } } a.UnlockBits(srcData); dstBitmap.UnlockBits(dstData); return dstBitmap; } catch { return null; } }

希望本文所述对大家的C#程序设计有所帮助。

以上就是C#图像处理之边缘检测(Smoothed)的方法的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » 其他教程