原文: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变换直线检测的更多相关文章

  1. Win8 Metro(C#)数字图像处理--2.35图像肤色检测算法

    原文:Win8 Metro(C#)数字图像处理--2.35图像肤色检测算法  [函数名称] 肤色检测函数SkinDetectProcess(WriteableBitmap src) [算法说明] ...

  2. Win8 Metro(C#)数字图像处理--2.36角点检测算法

    原文:Win8 Metro(C#)数字图像处理--2.36角点检测算法  [函数名称] Harris角点检测函数    HarrisDetect(WriteableBitmap src, int  ...

  3. Win8 Metro(C#)数字图像处理--2.53图像傅立叶变换

    原文:Win8 Metro(C#)数字图像处理--2.53图像傅立叶变换  [函数名称] 1,一维FFT变换函数         Complex[] FFT(Complex[] sourceDat ...

  4. Win8 Metro(C#)数字图像处理--2.61哈哈镜效果

    原文:Win8 Metro(C#)数字图像处理--2.61哈哈镜效果  [函数名称] 哈哈镜效果函数  WriteableBitmap DistortingMirrorProcess(Writea ...

  5. Win8 Metro(C#)数字图像处理--2.42图像光照效果算法

    原文:Win8 Metro(C#)数字图像处理--2.42图像光照效果算法  [函数名称] 图像光照效果  SunlightProcess(WriteableBitmap src,int X,in ...

  6. Win8 Metro(C#)数字图像处理--2.75灰度图像的形态学算法

    原文:Win8 Metro(C#)数字图像处理--2.75灰度图像的形态学算法 前面章节中介绍了二值图像的形态学算法,这里讲一下灰度图的形态学算法,主要是公式,代码略. 1,膨胀算法 2,腐蚀算法 3 ...

  7. Win8 Metro(C#)数字图像处理--4图像颜色空间描述

    原文:Win8 Metro(C#)数字图像处理--4图像颜色空间描述  图像颜色空间是图像颜色集合的数学表示,本小节将针对几种常见颜色空间做个简单介绍. /// <summary> / ...

  8. Win8 Metro(C#)数字图像处理--3.2图像方差计算

    原文:Win8 Metro(C#)数字图像处理--3.2图像方差计算 /// <summary> /// /// </summary>Variance computing. / ...

  9. Win8 Metro(C#)数字图像处理--3.3图像直方图计算

    原文:Win8 Metro(C#)数字图像处理--3.3图像直方图计算 /// <summary> /// Get the array of histrgram. /// </sum ...

随机推荐

  1. LeetCode -- 删除链表中值为k的元素

    本题目比較直接,一次遍历遇到匹配的元素直接删除(通过n.next = n.next.next)就能够了,仅仅是须要考虑到:1.首节点的情况2.末节点的情况 下面为实现: public ListNode ...

  2. Facial keypoints detection Kaggle 竞赛系列

    3.2# Facial keypoints detection 作者:Stu. Rui QQ: 1026163725 原文链接:http://blog.csdn.net/i_love_home/art ...

  3. linux 登录windows跳板机

    rdesktop -u 用户 -p 密码 ip -r sound:on/off -g 1200:830

  4. [Ramda] Convert a Promise.all Result to an Object with Ramda's zip and zipObj

    In this lesson, we'll use Promise.all to get an array that contains the resolved values from multipl ...

  5. Erlang中的record与宏

    http://www.cnblogs.com/me-sa/archive/2011/07/20/erlang0006.html 在Erlang中使用Tuple ,数据项的顺序\数量都是确定的,一旦数据 ...

  6. 小强的HTML5移动开发之路(29)—— JavaScript回顾4

    一.变量的作用域 javascript脚本的执行过程分为两个阶段: 第一阶段,js引擎()先扫描整个javascript代码.当碰到<script>时,会先创建一个全局的活动对象,将< ...

  7. 使用PowerDesigner15在win7下的系统MySQL p相反roject(一)

    使用PowerDesigner15在win7下的系统MySQL 相反project 1.首先.安装下面的驱动 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv ...

  8. App各种Icon及Launch image的尺寸和用途

    App各种Icon及Launch image的尺寸和用途 IOS7,8 Asset iPhone 6 Plus (@3x) iPhone 6 and iPhone 5 (@2x) iPhone 4s ...

  9. hdu 1418(抱歉)(欧拉公式,定点数,棱数,面数的关系)(水题)

    抱歉 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...

  10. PHP中的加密方式有如下几种

    1. MD5加密 string md5 ( string $str [, bool $raw_output = false ] ) 参数 str  --  原始字符串. raw_output  --  ...