Moravec算子提取特征点
合集下载
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
}
double V2 = 0;
for (int m = 0; m < 4; m++)
{
V2 = V2 + Math.Pow(huiduzhi[i - 2 + m, j - 2 + m] - huiduzhi[i - 1 + m, j - 1 + m], 2); //计算V2方向相邻像素灰度差平方和
}
{
V4 = V4 + Math.Pow(huiduzhi[i - 2 + m, j + 2 - m] - huiduzhi[i - 1 + m, j + 1 - m], 2); //计算V4方向相邻像素灰度差平方和
}
xingquzhi[i, j] = Math.Min(Math.Min(Math.Min(V1, V2), V3), V4); //从V1、V2、V3、V4中取最小值作为该点兴趣值
for (int i = 2; i < Var_W - 2; i++)
{
for (int j = 2; j < Var_H - 2; j++)
{
double V1 = 0;
for (int m = 0; m < 4; m++)
{
V1 = V1 + Math.Pow(huiduzhi[i - 2 + m, j] - huiduzhi[i - 1 + m, j], 2); //计算V1方向相邻像素灰度差平方和
}
}
else
{
a = 0; b = 0;
}
}
}
if ((a != 0) && (b != 0))
{
tezhengzhi1[c, 0] = a; //存储特征点列
tezhengzhi1[c, 1] = b; //存储特征点行
c++; //每有一个既不为0也不重复的最大值特征点数目加一
}
}
}
tezhengzhi = tezhengzhi1;
}
}
double pingjunzhi = sum / (Var_W * Var_H);
toolStripProgressBar1.Value += toolStripProgressBar1.Step;
int houxuan = 0; //统计候选特征点数目
int c = 101; //获取准确特征点数目
{
Image myImage = System.Drawing.Image.FromFile(openFileDialog1.FileName);
pictureBox1.Image = myImage; //显示打开的图片
toolStripProgressBar1.Visible = true; //进度条可视
}
}
/// <summary>
///提取特征点
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, EventArgs e)
if (openFileDialog1.ShowDialog() == DialogResult.OK) //打开文件对话框
{
//根据文件的路径创建Image对象
Image myImage = System.Drawing.Image.FromFile(openFileDialog1.FileName);
for (int i = 0; i < c; i++)
{
for (int j = 0; j < 2; j++)
{
tezhengdian2[i, j] = tezhengzhi[i,j];
///打开图像
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
//设置文件的类型
openFileDialog1.Filter = "*.jpg,*.jpeg,*.bmp,*.gif,*.ico,*.png,*.tif,*.wmf|*.jpg;*.jpeg;*.bmp;*.gif;*.ico;*.png;*.tif;*.wmf";
using System.IO;
using System.Drawing.Imaging;
namespace课程作业3_bk20113268
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// <summary>
{
try
{
//添加行号
SolidBrush v_SolidBrush = new SolidBrush(dataGridView1.RowHeadersDefaultCellStyle.ForeColor);
int v_LineNo = 0;
v_LineNo = e.RowIndex + 1;
string v_Line = v_LineNo.ToString();
{
MAX = xingquzhi[i - mubanbanchuang + m, j - mubanbanchuang + n]; //获取5*5模板中最大值
a = i - mubanbanchuang + m; //获取最大值列
b = j - mubanbanchuang + n; //获取最大值行
pictureBox1.Image = myImage; //显示打开的图片
pictureBox1.Height = myImage.Height;
pictureBox1.Width = myImage.Width;
this.button2.Enabled = true;
}
}
/// <summary>
{
for (int j = 0; j < Var_H; j++)
{
if (xingquzhi[i, j] <= yuzhi)
{
jianding[i, j] = 0; //选取兴趣值大于阈值的点作为特征候选点,其他点兴趣值归零
}
else
{
jianding[i, j] = 1;
houxuan++;
}
}
}
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;
double zeng = 4;
while ( c > 100)
{
c = 0;
double yuzhi = pingjunzhi * zeng; //设定阈值
double[,] jianding = new double[Var_W, Var_H];
for (int i = 0; i < Var_W; i++)
zeng += 1;
}
toolStripProgressBar1.Value += toolStripProgressBar1.Step;
toolStripProgressBar1.Value += toolStripProgressBar1.Step;
int[,] tezhengdian2 = new int[c, 2]; //定义一个数组存储像素坐标
int Var_H = pictureBox1.Image.Height; //获取图象的高度
int Var_W = pictureBox1.Image.Width; //获取图象的宽度
Bitmap Var_bmp = (Bitmap)pictureBox1.Image; //根据图象的大小创建Bitmap对象
///为数据表表头ห้องสมุดไป่ตู้加行号
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
}
}
toolStripProgressBar1.Value += toolStripProgressBar1.Step;
double sum=0;
for (int i = 0; i < Var_W; i++)
{
for (int j = 0; j < Var_H; j++)
{
sum+=xingquzhi[i,j];
huiduzhi[i, j] = tem_color.R * 0.299 + tem_color.G * 0.587 + tem_color.B * 0.114; //各点灰度值
}
}
toolStripProgressBar1.Value += toolStripProgressBar1.Step;
double[,] xingquzhi = new double[Var_W, Var_H]; //用于存储各点兴趣值
for (int m = 0; m < yuzhimuban; m++)
{
for (int n = 0; n < yuzhimuban; n++)
{
if (jianding[i - mubanbanchuang + m, j - mubanbanchuang + n] == 1)
{
if (MAX < xingquzhi[i - mubanbanchuang + m, j - mubanbanchuang + n])
toolStripProgressBar1.Maximum = 7; //设置进度条最大长度值
toolStripProgressBar1.Value = 0; //设置进度条当前值
toolStripProgressBar1.Step = 1; //设置进度条步长
toolStripProgressBar1.Value += toolStripProgressBar1.Step; //进度条前进
{
for (int j = mubanbanchuang; j < Var_H - mubanbanchuang; j = j + yuzhimuban)
{
double MAX = 0; //假定5*5模板最大值起始值为第一个元素值
int a = 0; //设a为最大值行
int b = 0; //设b为最大值列
e.Graphics.DrawString(v_Line, e.InheritedRowStyle.Font, v_SolidBrush, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + 5);
}
catch (Exception ex)
{
MessageBox.Show("添加行号时发生错误,错误信息:" + ex.Message, "操作失败");
int[,] tezhengzhi1 = new int[houxuan, 2]; //假定一个数组能容纳所有点皆为特征点的像素坐标矩阵
int yuzhimuban = 5; //定义阈值模板
int mubanbanchuang = 2;
for (int i = mubanbanchuang; i < Var_W - mubanbanchuang; i = i + yuzhimuban)
double V3 = 0;
for (int m = 0; m < 4; m++)
{
V3 = V3 + Math.Pow(huiduzhi[i, j - 2 + m] - huiduzhi[i, j - 1 + m], 2); //计算V3方向相邻像素灰度差平方和
}
double V4 = 0;
for (int m = 0; m < 4; m++)
double[,] huiduzhi = new double[Var_W, Var_H]; //用于存储各点灰度值
for (int i = 0; i < Var_W; i++)
{
for (int j = 0; j < Var_H; j++)
{
Color tem_color = Var_bmp.GetPixel(i, j); //获取当前像素的颜色值
double V2 = 0;
for (int m = 0; m < 4; m++)
{
V2 = V2 + Math.Pow(huiduzhi[i - 2 + m, j - 2 + m] - huiduzhi[i - 1 + m, j - 1 + m], 2); //计算V2方向相邻像素灰度差平方和
}
{
V4 = V4 + Math.Pow(huiduzhi[i - 2 + m, j + 2 - m] - huiduzhi[i - 1 + m, j + 1 - m], 2); //计算V4方向相邻像素灰度差平方和
}
xingquzhi[i, j] = Math.Min(Math.Min(Math.Min(V1, V2), V3), V4); //从V1、V2、V3、V4中取最小值作为该点兴趣值
for (int i = 2; i < Var_W - 2; i++)
{
for (int j = 2; j < Var_H - 2; j++)
{
double V1 = 0;
for (int m = 0; m < 4; m++)
{
V1 = V1 + Math.Pow(huiduzhi[i - 2 + m, j] - huiduzhi[i - 1 + m, j], 2); //计算V1方向相邻像素灰度差平方和
}
}
else
{
a = 0; b = 0;
}
}
}
if ((a != 0) && (b != 0))
{
tezhengzhi1[c, 0] = a; //存储特征点列
tezhengzhi1[c, 1] = b; //存储特征点行
c++; //每有一个既不为0也不重复的最大值特征点数目加一
}
}
}
tezhengzhi = tezhengzhi1;
}
}
double pingjunzhi = sum / (Var_W * Var_H);
toolStripProgressBar1.Value += toolStripProgressBar1.Step;
int houxuan = 0; //统计候选特征点数目
int c = 101; //获取准确特征点数目
{
Image myImage = System.Drawing.Image.FromFile(openFileDialog1.FileName);
pictureBox1.Image = myImage; //显示打开的图片
toolStripProgressBar1.Visible = true; //进度条可视
}
}
/// <summary>
///提取特征点
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, EventArgs e)
if (openFileDialog1.ShowDialog() == DialogResult.OK) //打开文件对话框
{
//根据文件的路径创建Image对象
Image myImage = System.Drawing.Image.FromFile(openFileDialog1.FileName);
for (int i = 0; i < c; i++)
{
for (int j = 0; j < 2; j++)
{
tezhengdian2[i, j] = tezhengzhi[i,j];
///打开图像
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
//设置文件的类型
openFileDialog1.Filter = "*.jpg,*.jpeg,*.bmp,*.gif,*.ico,*.png,*.tif,*.wmf|*.jpg;*.jpeg;*.bmp;*.gif;*.ico;*.png;*.tif;*.wmf";
using System.IO;
using System.Drawing.Imaging;
namespace课程作业3_bk20113268
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// <summary>
{
try
{
//添加行号
SolidBrush v_SolidBrush = new SolidBrush(dataGridView1.RowHeadersDefaultCellStyle.ForeColor);
int v_LineNo = 0;
v_LineNo = e.RowIndex + 1;
string v_Line = v_LineNo.ToString();
{
MAX = xingquzhi[i - mubanbanchuang + m, j - mubanbanchuang + n]; //获取5*5模板中最大值
a = i - mubanbanchuang + m; //获取最大值列
b = j - mubanbanchuang + n; //获取最大值行
pictureBox1.Image = myImage; //显示打开的图片
pictureBox1.Height = myImage.Height;
pictureBox1.Width = myImage.Width;
this.button2.Enabled = true;
}
}
/// <summary>
{
for (int j = 0; j < Var_H; j++)
{
if (xingquzhi[i, j] <= yuzhi)
{
jianding[i, j] = 0; //选取兴趣值大于阈值的点作为特征候选点,其他点兴趣值归零
}
else
{
jianding[i, j] = 1;
houxuan++;
}
}
}
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;
double zeng = 4;
while ( c > 100)
{
c = 0;
double yuzhi = pingjunzhi * zeng; //设定阈值
double[,] jianding = new double[Var_W, Var_H];
for (int i = 0; i < Var_W; i++)
zeng += 1;
}
toolStripProgressBar1.Value += toolStripProgressBar1.Step;
toolStripProgressBar1.Value += toolStripProgressBar1.Step;
int[,] tezhengdian2 = new int[c, 2]; //定义一个数组存储像素坐标
int Var_H = pictureBox1.Image.Height; //获取图象的高度
int Var_W = pictureBox1.Image.Width; //获取图象的宽度
Bitmap Var_bmp = (Bitmap)pictureBox1.Image; //根据图象的大小创建Bitmap对象
///为数据表表头ห้องสมุดไป่ตู้加行号
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
}
}
toolStripProgressBar1.Value += toolStripProgressBar1.Step;
double sum=0;
for (int i = 0; i < Var_W; i++)
{
for (int j = 0; j < Var_H; j++)
{
sum+=xingquzhi[i,j];
huiduzhi[i, j] = tem_color.R * 0.299 + tem_color.G * 0.587 + tem_color.B * 0.114; //各点灰度值
}
}
toolStripProgressBar1.Value += toolStripProgressBar1.Step;
double[,] xingquzhi = new double[Var_W, Var_H]; //用于存储各点兴趣值
for (int m = 0; m < yuzhimuban; m++)
{
for (int n = 0; n < yuzhimuban; n++)
{
if (jianding[i - mubanbanchuang + m, j - mubanbanchuang + n] == 1)
{
if (MAX < xingquzhi[i - mubanbanchuang + m, j - mubanbanchuang + n])
toolStripProgressBar1.Maximum = 7; //设置进度条最大长度值
toolStripProgressBar1.Value = 0; //设置进度条当前值
toolStripProgressBar1.Step = 1; //设置进度条步长
toolStripProgressBar1.Value += toolStripProgressBar1.Step; //进度条前进
{
for (int j = mubanbanchuang; j < Var_H - mubanbanchuang; j = j + yuzhimuban)
{
double MAX = 0; //假定5*5模板最大值起始值为第一个元素值
int a = 0; //设a为最大值行
int b = 0; //设b为最大值列
e.Graphics.DrawString(v_Line, e.InheritedRowStyle.Font, v_SolidBrush, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + 5);
}
catch (Exception ex)
{
MessageBox.Show("添加行号时发生错误,错误信息:" + ex.Message, "操作失败");
int[,] tezhengzhi1 = new int[houxuan, 2]; //假定一个数组能容纳所有点皆为特征点的像素坐标矩阵
int yuzhimuban = 5; //定义阈值模板
int mubanbanchuang = 2;
for (int i = mubanbanchuang; i < Var_W - mubanbanchuang; i = i + yuzhimuban)
double V3 = 0;
for (int m = 0; m < 4; m++)
{
V3 = V3 + Math.Pow(huiduzhi[i, j - 2 + m] - huiduzhi[i, j - 1 + m], 2); //计算V3方向相邻像素灰度差平方和
}
double V4 = 0;
for (int m = 0; m < 4; m++)
double[,] huiduzhi = new double[Var_W, Var_H]; //用于存储各点灰度值
for (int i = 0; i < Var_W; i++)
{
for (int j = 0; j < Var_H; j++)
{
Color tem_color = Var_bmp.GetPixel(i, j); //获取当前像素的颜色值