opencv实现分水岭,金字塔,均值漂移算法进行分割

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

using System;

using System.Collections.Generic;

using ponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Diagnostics;

using System.Runtime.InteropServices;

using Emgu.CV;

using Emgu.CV.CvEnum;

using Emgu.CV.Structure;

using Emgu.CV.UI;

namespace ImageProcessLearn

{

public partial class FormImageSegment : Form

{

//成员变量

private string sourceImageFileName = "wky_tms_2272x1704.jpg";//源图像文件名

private Image imageSource = null; //源图像

private Image imageSourceClone = null; //源图像的克隆

private Image imageMarkers = null; //标记图像

private double xScale = 1d; //原始图像与PictureBox在x轴方向上的缩放

private double yScale = 1d; //原始图像与PictureBox在y轴方向上的缩放

private Point previousMouseLocation = new Point(-1, -1); //上次绘制线条时,鼠标所处的位置private const int LineWidth = 5; //绘制线条的宽度

private int drawCount = 1; //用户绘制的线条数目,用于指定线条的颜色

public FormImageSegment()

{

InitializeComponent();

}

//窗体加载时

private void FormImageSegment_Load(object sender, EventArgs e)

{

//设置提示

toolTip.SetToolTip(rbWatershed, "可以在源图像上用鼠标绘制大致分割区域线条,该线条用于分水岭算法");

toolTip.SetToolTip(txtPSLevel, "金字塔层数跟图像尺寸有关,该值只能是图像尺寸被2整除的次数,否则将得出错误结果");

toolTip.SetToolTip(txtPSThreshold1, "建立连接的错误阀值");

toolTip.SetToolTip(txtPSThreshold2, "分割簇的错误阀值");

toolTip.SetToolTip(txtPMSFSpatialRadius, "空间窗的半径");

toolTip.SetToolTip(txtPMSFColorRadius, "色彩窗的半径");

toolTip.SetToolTip(btnClearMarkers, "清除绘制在源图像上,用于分水岭算法的大致分割区域线条");

//加载图像

LoadImage();

}

//当窗体关闭时,释放资源

private void FormImageSegment_FormClosing(object sender, FormClosingEventArgs e)

{

if (imageSource != null)

imageSource.Dispose();

if (imageSourceClone != null)

imageSourceClone.Dispose();

if (imageMarkers != null)

imageMarkers.Dispose();

}

//加载源图像

private void btnLoadImage_Click(object sender, EventArgs e)

{

OpenFileDialog ofd = new OpenFileDialog();

ofd.CheckFileExists = true;

ofd.DefaultExt = "jpg";

ofd.Filter = "图片文件|*.jpg;*.png;*.bmp|所有文件|*.*";

if (ofd.ShowDialog(this) == DialogResult.OK)

{

if (ofd.FileName != "")

{

sourceImageFileName = ofd.FileName;

LoadImage();

}

}

ofd.Dispose();

}

//清除分割线条

private void btnClearMarkers_Click(object sender, EventArgs e)

{

if (imageSourceClone != null)

imageSourceClone.Dispose();

imageSourceClone = imageSource.Copy();

pbSource.Image = imageSourceClone.Bitmap;

相关文档
最新文档