图像提取C语言程序

来源:百度知道 编辑:UC知道 时间:2024/05/29 07:52:28
LOG算子,Roberts算子,Canny算子都可以

抄来给你:

/// 按 Roberts 算子进行边缘检测
///
/// 位图流
///
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.Format32bppArgb);
BitmapData dstData = dstImage.LockBits(new Rectangle(0, 0, width, height),
ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
int stride = srcData.Stride;
int offset = stride - width * BPP;
unsafe
{
byte* src = (byte*)srcData.Scan0;
byte* dst = (byte*)dstData.Scan0;
int A, B; // A(x-1, y-1) B(x, y-1)
int C, D; // C(x-1, y) D(x, y)
// 指向第一行
src += stride;
dst += stride;
// 不处理最上边和最左边
for (int y = 1; y < height; y++)
{
// 指向每行第一列
src += BPP;
dst += BPP;
for (int x = 1; x < width; x++)
{
for