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 ...
随机推荐
- ajax 发送请求无法重定向问题
原因: ajax请求默认就是不支持重定向的,因为它是局部刷新,不重新加载页面. 解决方案: 开发中需要多处使用重定向的情况下,大多都是在Spring mvc 的拦截器中,或过滤器中使用,此方法是在sp ...
- Go语言:正則表達式的使用
Go语言的正則表達式使用非常easy.演示样例代码: package test import ( "fmt" "regexp" ) func RegixBase ...
- unresolved external symbol __forceAtlDllManifest错误的解决
作者:朱金灿 来源:http://blog.csdn.net/clever101 晚上编译一个ATL程序,出现一些诡异的错误: 1>CGreet.obj : error LNK2001: unr ...
- 【hdu 2177】取(2堆)石子游戏
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s) ...
- 选择性编译代码:如 #ifdef __IPHONE_7_0
选择性编译代码: 选择性编译代码和选择性运行代码是不一样的,区别在于: 1.选择性编译代码是在硬件或者系统不支持的情况下不会对该段代码进行编译,也就不会由于不兼容的问题导致报错 #import < ...
- erlang浅谈
优点: 1.面向并发,有成熟而且久经考验的框架可供使用,网络部分已经经过了良好封装 2.内存缓存解决方案进程字典,前者的读写速度是50NS-100Ns级别的 3.对二进制数据解析的语法是直观,简单,强 ...
- 【87.65%】【codeforces 731A】Night at the Museum
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- hdu 2037 这个夏天不AC
这个夏天不AC Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- hdu - 4971 - A simple brute force problem.(最大权闭合图)
题意:n(n <= 20)个项目,m(m <= 50)个技术问题,做完一个项目能够有收益profit (<= 1000),做完一个项目必须解决对应的技术问题,解决一个技术问题须要付出 ...
- 【翻译自mos文章】对于每个文件的 file.id and file.incarnation number,重命名文件别名
对于每个文件的 file.id and file.incarnation number,重命名文件别名 參考原文: Rename Alias of Datafile as Per file.id an ...