Win8 Metro(C#)数字图像处理--2.38Hough变换直线检测
原文:Win8 Metro(C#)数字图像处理--2.38Hough变换直线检测
[函数名称]
Hough 变换直线检测 HoughLineDetect(WriteableBitmap src, int threshould)
[算法说明]
Hough变换是数字图像处理中一种常用的几何形状识别方法,它可以识别直线,圆,椭圆,弧线等
等几何形状,其基本原理是利用图像二维空间和Hough参数空间的点-线对偶性,把图像空间中的形
状检测问题转换到Hough的参数空间中去,最终以寻找参数空间中的峰值问题,得到形状检测的最优
结果。
/// <summary>
/// Hough transform of line detectting process.
/// </summary>
/// <param name="src">The source image.</param>
/// <param name="threshould">The threshould to adjust the number of lines.</param>
/// <returns></returns>
public static WriteableBitmap HoughLineDetect(WriteableBitmap src, int threshould)////2 Hough 变换直线检测
{
if (src != null)
{
int w = src.PixelWidth;
int h = src.PixelHeight;
WriteableBitmap srcImage = new WriteableBitmap(w, h);
byte[] temp = src.PixelBuffer.ToArray();
int roMax = (int)Math.Sqrt(w * w + h * h) + 1;
int[,] mark = new int[roMax, 180];
double[] theta = new double[180];
for (int i = 0; i < 180; i++)
{
theta[i] = (double)i * Math.PI / 180.0;
}
double roValue = 0.0;
int transValue=0;
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
if (temp[x * 4 + y * w*4] == 0)
{
for (int k = 0; k < 180; k++)
{
roValue = (double)x * Math.Cos(theta[k]) + (double)y * Math.Sin(theta[k]);
transValue = (int)Math.Round(roValue / 2 + roMax / 2);
mark[transValue, k]++;
}
}
}
}
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
int T = x * 4 + y * w * 4;
if (temp[T] == 0)
{
for (int k = 0; k < 180; k++)
{
roValue = (double)x * Math.Cos(theta[k]) + (double)y * Math.Sin(theta[k]);
transValue = (int)Math.Round(roValue / 2 + roMax / 2);
if (mark[transValue, k] > threshould)
{
temp[T + 2] = (byte)255;
}
}
}
}
}
Stream sTemp = srcImage.PixelBuffer.AsStream();
sTemp.Seek(0, SeekOrigin.Begin);
sTemp.Write(temp, 0, w * 4 * h);
return srcImage;
}
else
{
return null;
}
}
<strong><span style="font-size:14px;">[图像效果]</span></strong>
注意:图中没有标红的线,是因为threshold=80,如果这个值改变,会影响检测结果,这个值足够小,另外两条直线也将被标红。
Win8 Metro(C#)数字图像处理--2.38Hough变换直线检测的更多相关文章
- Win8 Metro(C#)数字图像处理--2.35图像肤色检测算法
原文:Win8 Metro(C#)数字图像处理--2.35图像肤色检测算法 [函数名称] 肤色检测函数SkinDetectProcess(WriteableBitmap src) [算法说明] ...
- Win8 Metro(C#)数字图像处理--2.36角点检测算法
原文:Win8 Metro(C#)数字图像处理--2.36角点检测算法 [函数名称] Harris角点检测函数 HarrisDetect(WriteableBitmap src, int ...
- Win8 Metro(C#)数字图像处理--2.53图像傅立叶变换
原文:Win8 Metro(C#)数字图像处理--2.53图像傅立叶变换 [函数名称] 1,一维FFT变换函数 Complex[] FFT(Complex[] sourceDat ...
- Win8 Metro(C#)数字图像处理--2.61哈哈镜效果
原文:Win8 Metro(C#)数字图像处理--2.61哈哈镜效果 [函数名称] 哈哈镜效果函数 WriteableBitmap DistortingMirrorProcess(Writea ...
- Win8 Metro(C#)数字图像处理--2.42图像光照效果算法
原文:Win8 Metro(C#)数字图像处理--2.42图像光照效果算法 [函数名称] 图像光照效果 SunlightProcess(WriteableBitmap src,int X,in ...
- Win8 Metro(C#)数字图像处理--2.75灰度图像的形态学算法
原文:Win8 Metro(C#)数字图像处理--2.75灰度图像的形态学算法 前面章节中介绍了二值图像的形态学算法,这里讲一下灰度图的形态学算法,主要是公式,代码略. 1,膨胀算法 2,腐蚀算法 3 ...
- Win8 Metro(C#)数字图像处理--4图像颜色空间描述
原文:Win8 Metro(C#)数字图像处理--4图像颜色空间描述 图像颜色空间是图像颜色集合的数学表示,本小节将针对几种常见颜色空间做个简单介绍. /// <summary> / ...
- Win8 Metro(C#)数字图像处理--3.2图像方差计算
原文:Win8 Metro(C#)数字图像处理--3.2图像方差计算 /// <summary> /// /// </summary>Variance computing. / ...
- Win8 Metro(C#)数字图像处理--3.3图像直方图计算
原文:Win8 Metro(C#)数字图像处理--3.3图像直方图计算 /// <summary> /// Get the array of histrgram. /// </sum ...
随机推荐
- 【codeforces 604D】Moodular Arithmetic
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【网络】无法解析服务器的DNS地址?;能登陆QQ,无法打开网页
1. 无法解析服务器的DNS地址 手动设置 DNS(域名解析服务器) 8.8.8.8 114.114.114.114 清除浏览器缓存: 重启主机: 无法解析服务器的DNS地址?DNS解析错误怎么办? ...
- Xor - Trie树
题目描述 求一棵带边权的树的一条最大 Xor 路径的值.这里的"路径"不一定从根到叶子结点,中间一段路径只要满足条件也可以. 输入格式 第一行,一个整数 N ,表示一颗树有 N 个 ...
- python io操作
一次性读取 # 读取文件 # 默认打开文件的方式是只读 file = None try: file = open("f:/test.sql") print(file.name) # ...
- Java反射xml数据类
我们做自己的自动化测试.遇到使用xml存储数据,然而,这些数据可以被封装成一个类.将数据传递.通过下面的实际例子,展示给大家.请欣赏. 第一步:xml数据存储将被使用 第二步:读取xml文件的方法 第 ...
- matlab 求解线性规划问题
线性规划 LP(Linear programming,线性规划)是一种优化方法,在优化问题中目标函数和约束函数均为向量变量的线性函数,LP问题可描述为: minf(x):待最小化的目标函数(如果问题本 ...
- 【37.00%】【vijos p1425】子串清除
P1425子串清除Accepted 标签:[显示标签] 描述 我们定义字符串A是字符串B的子串当且仅当我们能在B串中找到A串.现在给你一个字符串A,和另外一个字符串B,要你每次从B串中从左至右找第一个 ...
- Android 平台下Ftp 使用模拟器需要注意的问题
以下代码在pc上测试通过,可是在android模拟器上就不工作,不过还可以链接到服务器但不能得到文件 纠结了半天,原来是模式的问题,具体请Google 模拟器中采用建议被动模式 public void ...
- Jsp bug_001
报错: The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path 解 ...
- 各种工具的使用 tricks
1. 搜狗搜索引擎 因为搜狗与腾讯的合作关系,搜狗搜索引擎提供了"微信"的搜索选项,可直接定位到相关文章,或者公众号. weixin.sougou.com 2. PyCharm P ...