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 ...
随机推荐
- [Most.js] Create Streams From Single Values With Most.js
Most provides many means for creating streams, the simplest of which is the offunction. In this less ...
- winfrom RichTextBox每行字体的颜色
public static void AppendTextColorful(this RichTextBox rtBox, string text, Color color, bool addNewL ...
- 【U205】最大值
Time Limit: 1 second Memory Limit: 128 MB [问题描述] 找到一个数组的最大值的一种方法是从数组开头从前到后对数组进行扫描,令max=a[0](数组下表从0.. ...
- 【codeforces 546A】Soldier and Bananas
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- layer弹框在实际项目中的一些应用
官方介绍:layer至今仍作为layui的代表作,受众广泛并非偶然,而是这五年多的坚持,不断完善和维护.不断建设和提升社区服务,使得猿们纷纷自发传播,乃至于成为今天的Layui最强劲的源动力.目前,l ...
- Spring处理跨域请求
[nio-8080-exec-8] o.s.web.cors.DefaultCorsProcessor : Skip CORS processing: request is from s ...
- 浏览器加载js文件顺序
在默认情况下,下载和执行js都会阻塞页面的渲染,当然现在浏览器支持并行下载,但仍然会阻塞图片等的下载和渲染,所以通常建议把js文件放body底.对于执行顺序,不管是外部js还是内部,只要 遇到< ...
- win10 uwp 使用 msbuild 命令行编译 UWP 程序
原文:win10 uwp 使用 msbuild 命令行编译 UWP 程序 版权声明:博客已迁移到 http://lindexi.gitee.io 欢迎访问.如果当前博客图片看不到,请到 http:// ...
- RabbitMQ及其.NET客户端——几个小例子
一.简单生产者-消费者(使用direct交换器) 1.生产者 var factory = new ConnectionFactory();//实例化一个工厂 factory.HostName = &q ...
- Spring Boot中集成Spring Security 专题
check to see if spring security is applied that the appropriate resources are permitted: @Configurat ...