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 ...
随机推荐
- [Javascript] Write a function pipeline
const _pipe = (f, g) => (...args) => g(f(...args)) export const pipe = (...fns) => fns.redu ...
- DOM中Event 对象如何使用
DOM中Event 对象如何使用 一.总结 一句话总结: 1.将event作为参数传递进来,然后就可以调用event对象的各种属性和方法了. <body onmousedown="wh ...
- SQL Server2008生成数据库字典
1.我们在开发过程中可能会遇到这样的一种情况"当我们进行维护其他人的项目时或者项目的二次开发时可能会对原始的数据表进行分析",这里为大家介绍一种方便快捷生成数据库字典的方式. 我们 ...
- Java中的浮点数-科学计数法-加减乘除
上次,提到"元转分"这个浮点数问题,boss倾向于手动把1.23元这种格式,转换成123分. 但实际上,浮点数很容易遇到精度问题. 比如,System.out.prin ...
- Thermally driven workload scheduling in a heterogeneous multi-processor system on a chip
Various embodiments of methods and systems for thermally aware scheduling of workloads in a portable ...
- 一起学Python:多线程-共享全局变量
多线程-共享全局变量 from threading import Thread import time g_num = 100 def work1(): global g_num for i in r ...
- Android Studio 如何打JAR包(修订版)
AndroidStudio项目打包成jar 前言:在eclipse中我们知道如何将一个项目导出为jar包,现在普遍AndroidStuido开发,这里一步一步详加介绍AS项目打包成jar,jar和ar ...
- Swift 中的Closures(闭包)详解
Swift 中的Closures(闭包)详解 在Swift没有发布之前,所有人使用OC语言编写Cocoa上的程序,而其中经常被人们讨论的其中之一 -- Block 一直备受大家的喜爱.在Swift中, ...
- 利用WPF建立自己的3d gis软件(非axhost方式)(十)SDK中一些自带的展示面板应用
原文:利用WPF建立自己的3d gis软件(非axhost方式)(十)SDK中一些自带的展示面板应用 先下载SDK:https://pan.baidu.com/s/1M9kBS6ouUwLfrt0zV ...
- matlab 高阶(三)—— 插值(fft、)
1. FFT 插值 y = interpft(x,n) y = [0, .5, 1., 1.5, 2., 1.5, 1., .5, 0, -.5, -1, -1.5, -2., -1.5, -1., ...