Win8Metro(C#)数字图像处理--2.12Sobel边缘检测
原文:Win8Metro(C#)数字图像处理--2.12Sobel边缘检测
[函数名称]
图像Sobel边缘检测函数SobelEdgeProcess(WriteableBitmap
src)
[函数代码]
///<summary>
///
Sobel edge detection.
///</summary>
///<param
name="src">Source image.</param>
///<returns></returns>
publicstaticWriteableBitmap
SobelEdgeProcess(WriteableBitmap src)////12
Sobel边缘检测
{
if(src!=null
)
{
int
w = src.PixelWidth;
int
h = src.PixelHeight;
WriteableBitmap
sobelImage =newWriteableBitmap(w,h);
byte[]
temp = src.PixelBuffer.ToArray();
byte[]
tempMask = (byte[])temp.Clone();
int
b = 0, g = 0, r = 0;
for
(int j = 1; j < h - 1; j++)
{
for
(int i = 4; i < w * 4 - 4; i += 4)
{
if
(i == 0 || i == w - 4 || j == 0 || j == h - 1)
{
temp[i + j * w * 4] = (byte)0;
temp[i + 1 + j * w * 4] = (byte)0;
temp[i + 2 + j * w * 4] = (byte)0;
}
else
{
b =Math.Abs(tempMask[i
- 4 + (j - 1) * w * 4] + 2 * tempMask[i - 4 + j * w * 4] + tempMask[i - 4 + (j + 1) * w * 4] - tempMask[i + 4 + (j - 1) * w * 4]
- 2 * tempMask[i + 4 + j * w * 4] - tempMask[i + 4 + (j + 1)
* w * 4]) + Math.Abs(tempMask[i - 4 + (j - 1) *
w * 4] + 2 * tempMask[i + (j - 1) * w * 4]
+ tempMask[i + 4 + (j - 1) * w * 4] - tempMask[i - 4 + (j + 1)
* w * 4] - 2 * tempMask[i + (j + 1) * w * 4] - tempMask[i + 4 + (j + 1) * w * 4]);
g =Math.Abs(tempMask[i
- 4 + 1 + (j - 1) * w * 4] + 2 * tempMask[i - 4 + 1 + j * w * 4] + tempMask[i - 4 + 1 + (j + 1) * w * 4] - tempMask[i + 4 + 1 + (j - 1) * w * 4]
- 2 * tempMask[i + 4 + 1 + j * w * 4] - tempMask[i + 4 + 1 + (j
+ 1) * w * 4]) +Math.Abs(tempMask[i - 4 + 1 + (j
- 1) * w * 4] + 2 * tempMask[i + 1 + (j - 1) * w * 4]
+ tempMask[i + 4 + 1 + (j - 1) * w * 4] - tempMask[i - 4 + 1 +
(j + 1) * w * 4] - 2 * tempMask[i + 1 + (j + 1) * w * 4] - tempMask[i + 1 + 4 + (j + 1) * w * 4]);
r =Math.Abs(tempMask[i
- 4 + 2 + (j - 1) * w * 4] + 2 * tempMask[i - 4 + 2 + j * w * 4] + tempMask[i - 4 + 2 + (j + 1) *w * 4] - tempMask[i + 4 + 2 + (j - 1) * w * 4]
- 2 * tempMask[i + 4 + 2 + j * w * 4] - tempMask[i + 4 + 2 + (j
+ 1) * w * 4]) +Math.Abs(tempMask[i - 4 + 2 + (j
- 1) * w * 4] + 2 * tempMask[i + 2 + (j - 1) * w * 4]
+ tempMask[i + 4 + 2 + (j - 1) * w * 4] - tempMask[i - 4 + 2 +
(j + 1) * w * 4] - 2 * tempMask[i + 2 + (j + 1) * w * 4] - tempMask[i + 2 + 4 + (j + 1) * w * 4]);
temp[i + j * w * 4] = (byte)(b
> 0 ? (b < 255 ? b : 255) : 0);
temp[i + 1 + j * w * 4] = (byte)(g
> 0 ? (g < 255 ? g : 255) : 0);
temp[i + 2 + j * w * 4] = (byte)(r
> 0 ? (r < 255 ? r : 255) : 0);
}
b = 0; g = 0; r = 0;
}
}
Stream
sTemp = sobelImage.PixelBuffer.AsStream();
sTemp.Seek(0,SeekOrigin.Begin);
sTemp.Write(temp, 0, w * 4 * h);
return
sobelImage;
}
else
{
returnnull;
}
}
Win8Metro(C#)数字图像处理--2.12Sobel边缘检测的更多相关文章
- Win8Metro(C#)数字图像处理--2.14Prewitt 边缘检测
原文:Win8Metro(C#)数字图像处理--2.14Prewitt 边缘检测 [函数名称] 图像Prewitt边缘检测函数PrewittEdgeProcess(WriteableBitmap ...
- Win8Metro(C#)数字图像处理--2.13Roberts边缘检测
原文:Win8Metro(C#)数字图像处理--2.13Roberts边缘检测 [函数名称] 图像Roberts边缘检测函数RobertEdgeProcess(WriteableBitmap s ...
- Win8Metro(C#)数字图像处理--2.33图像非线性变换
原文:Win8Metro(C#)数字图像处理--2.33图像非线性变换 [函数名称] 图像非线性变换函数NonlinearTransformProcess(WriteableBitmap src ...
- Win8Metro(C#)数字图像处理--2.34直方图规定化
原文:Win8Metro(C#)数字图像处理--2.34直方图规定化 [函数名称] WriteableBitmap HistogramSpecificateProcess(WriteableBi ...
- Win8Metro(C#)数字图像处理--2.30直方图均衡化
原文:Win8Metro(C#)数字图像处理--2.30直方图均衡化 [函数名称] 直方图均衡化函数HistogramEqualProcess(WriteableBitmap src) [算法说明] ...
- Win8Metro(C#)数字图像处理--2.31灰度拉伸算法
原文:Win8Metro(C#)数字图像处理--2.31灰度拉伸算法 [函数名称] 灰度拉伸函数GrayStretchProcess(WriteableBitmap src) [算法说明] ...
- Win8Metro(C#)数字图像处理--2.32图像曝光算法
原文:Win8Metro(C#)数字图像处理--2.32图像曝光算法 [函数名称] 图像曝光函数ExposureProcess(WriteableBitmap src,int exposureV ...
- Win8Metro(C#)数字图像处理--2.27图像加法运算
原文:Win8Metro(C#)数字图像处理--2.27图像加法运算 [函数名称] 图像加法函数AddProcess(WriteableBitmap src, WriteableBitmap a ...
- Win8Metro(C#)数字图像处理--2.28图像乘法运算
原文:Win8Metro(C#)数字图像处理--2.28图像乘法运算 [函数名称] 图像乘法函数MultiplicationProcess(WriteableBitmap src, Writea ...
随机推荐
- 【codeforces 750D】New Year and Fireworks
time limit per test2.5 seconds memory limit per test256 megabytes inputstandard input outputstandard ...
- Java爬虫框架WebMagic入门——爬取列表类网站文章
初学爬虫,WebMagic作为一个Java开发的爬虫框架很容易上手,下面就通过一个简单的小例子来看一下. WebMagic框架简介 WebMagic框架包含四个组件,PageProcessor.Sch ...
- 移动应用拉起微信小程序
APP支持打开微信小程序了 最新微信文档 如何实现APP打开小程序 通过文档打开微信开放平台添加移动应用,然后关联小程序,这些步骤按照文档描述走. IOS开发示例参考 android开发示例参考 开发 ...
- Cordova各种事件
原文:Cordova各种事件 Cordova事件 Cordova框架了一组事件,开发者用来对某些运行Cordova应用的设备上的事件作出反应.事件处理的一种情况是硬件相关活动,如电池状态变化或用户按了 ...
- 【17.00%】【codeforces 621D】Rat Kwesh and Cheese
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- JS事件处理函数中return false到底是什么东西
在<JS DOM编程艺术>一书中,用return false来阻止事件默认行为,可是js高程3里没有这种用法,那这到底是什么呢. 先看一下知乎的一个解释 就此问题,首先要纠正两个观点: 1 ...
- 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., ...
- PCI GXL学习之再造篇
作者:朱金灿 来源:http://blog.csdn.net/clever101 再造一个PCI GXL?听起来是一件颇有难度的事,实际上并非不可能.本文拟从必要性.可行性和技术路线等方面谈谈再造PC ...
- Node child_process Study.2
child_process 模块用于新建子进程.子进程的运行结果存储在系统缓存之中,等到子进程运行结束之后,主进程再用回调函数读取子进程的运行结果 1.exec() exec 方法用于执行base命令 ...
- backbone Model
requirejs.config({ baseUrl: 'js/lib', paths:{ app: '../app' } }) // Start the main app logic. //requ ...