您的位置:首页 > 编程语言 > C#

AForge.NET SobelEdgeDetector (C#)

2012-09-16 08:18 232 查看
http://zip.nvp.com.tw/forum.php?mod=viewthread&tid=2301&extra=page%3D15


 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Drawing.Imaging;

using AForge;

using AForge.Imaging;

using AForge.Imaging.Filters;

namespace AForge_SobelEdgeDetector_CSharp

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)

        {

            Bitmap sourceImage, filteredImage;

            Bitmap temp;

            SobelEdgeDetector filter = new SobelEdgeDetector();

            sourceImage = (Bitmap)System.Drawing.Image.FromFile(Application.StartupPath + @"..\..\..\sample2.jpg");

            if (pictureBox1.Image != null)

            {

                pictureBox1.Image.Dispose();

                pictureBox1.Image = null;

            }

            if (pictureBox2.Image != null)

            {

                pictureBox2.Image.Dispose();

                pictureBox2.Image = null;

            }

            temp = AForge.Imaging.Image.Clone(sourceImage, sourceImage.PixelFormat);

            sourceImage.Dispose();

            sourceImage = temp;

            pictureBox1.Image = sourceImage;

            filteredImage = filter.Apply(sourceImage.PixelFormat != PixelFormat.Format8bppIndexed ? Grayscale.CommonAlgorithms.BT709.Apply(sourceImage) : sourceImage);

            pictureBox2.Image = filteredImage;

        }

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息