资源简介
LOG算子 Kirsch算子 Laplace算子 Prewitt算子 Sobel算子 Hough变换 最佳阈值分割 差影法 运用上述方法进行边缘检测
代码片段和文件信息
/************************************************************************
* 数字图像处理--VC#.NET编程与实验 第8章 图像分割
* ImageSegmentation.Form1.cs
* Version 1.0 2010.01.29
* Author Xie-Hua Sun
************************************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ImageSegmenation
{
public partial class Form1 : Form
{
Bitmap curBitmap = null;
int iw ih;
public Form1()
{
InitializeComponent();
label1.Text = ““;
label2.Text = ““;
}
//打开
private void menuItem2_Click(object sender EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.Filter = “图像文件(*.bmp;*.jpg;*gif;*png;*.tif;*.wmf)|“
+ “*.bmp;*jpg;*gif;*png;*.tif;*.wmf“;
if (open.ShowDialog() == DialogResult.OK)
{
try
{
curBitmap = (Bitmap)Image.FromFile(open.FileName);
}
catch (Exception exp) { MessageBox.Show(exp.Message); }
pictureBox1.Refresh();
pictureBox1.Image = curBitmap;
label1.Text = “原图“;
iw = curBitmap.Width;
ih = curBitmap.Height;
}
}
//保存
private void menuItem3_Click(object sender EventArgs e)
{
string str;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = “图像文件(*.BMP)|*.BMP|All File(*.*)|*.*“;
saveFileDialog1.ShowDialog();
str = saveFileDialog1.FileName;
pictureBox2.Image.Save(str);
}
//退出
private void menuItem4_Click(object sender EventArgs e)
{
this.Close();
}
//8.1 边缘检测===========================================================
//Kirsch算子
private void menuItem10_Click(object sender EventArgs e)
{
if (curBitmap != null)
{
this.Text = “第8章 图像分割 边缘检测 Kirsch算子 作者 孙燮华“;
Bitmap bm = new Bitmap(pictureBox1.Image);
//1: Kirsch边缘检测
bm = detect(bm iw ih 1 500);
pictureBox2.Refresh();
pictureBox2.Image = bm;
label2.Text = “边缘检测结果“;
}
}
/*-------------------------------------------------------------------------
* pix --待检测图像数组
* iw ih --待检测图像宽高
* num --算子代号.1:Kirsch算子;2:Laplace算子;3:Prewitt算子;5:Sobel算子
* thresh --边缘检测阈值T
* flag --锐化与边缘检测标志 false:锐化; tru
- 上一篇:C#调用OpenCV开发简易版美图工具
- 下一篇:c#日期推算
评论
共有 条评论