原文: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. Cocos2d-x 3.0final 终结者系列教程05-AppDelegate入口类

    下面是Cocos2d-x的程序入口: class  AppDelegate : private cocos2d::Application { public: AppDelegate(); virtua ...

  2. Python正則表達式

    Python正則表達式 正則表達式是一个特殊的字符序列,它能帮助你方便的检查一个字符串是否与某种模式匹配. Python 自1.5版本号起添加了re 模块,它提供 Perl 风格的正則表達式模式. r ...

  3. [Angular] Content Projection with ng-content

    For example there is tow form compoennts on the page, and what we want to do is reusing the form com ...

  4. 【t064】最勇敢的机器人

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] [背景] Wind设计了很多机器人.但是它们都认为自己是最强的,于是,一场比赛开始了~ [问题描述] ...

  5. Xamarin.Forms开发APP

    Xamarin.Forms+Prism(1)—— 开发准备 准备: 1.VS2017(推荐)或VS2015: 2.JDK 1.8以上: 3.Xamarin.Forms 最新版: 4.Prism 扩展, ...

  6. zxl2431 指向函数的指针

    (一) 用函数指针变量调用函数 可以用指针变量指向整形变量.字符串.数组.结构体.也可以指向一个函数.一个函数在编译时被分配一个入口地址.这个入口地址就称为函数指针.可以用一个指针变量指向函数,然后通 ...

  7. 5.1 入门整合案例(SpringBoot+Spring-data-elasticsearch) ---- good

    本节讲解SpringBoot与Spring-data-elasticsearch整合的入门案例. 一.环境搭建 新建maven项目,名字随意 pom.xml <parent> <gr ...

  8. pushbutton成为可点击的图标(实现全透明,不论点击与否都只显示Icon)(也就是一个万能控件)

    需求 需要2个按钮,一个是音乐开关,一个是关闭窗口,此文章关闭pushButton的透明问题(hovered+pressed都不会有背景色和边框的变化) 原理 使窗口完全透明 代码 _pPushBut ...

  9. Android GPS获取当前位置信息

    package com.example.gpstest; import org.apache.http.util.LangUtils; import android.content.Context; ...

  10. yii联查

    $count = Acticle::find()->select("acticle_type.act_type,acticle.act_id,acticle.act_title,act ...