原文:Win8 Metro(C#)数字图像处理--2.65形态学轮廓提取算法



[函数名称]

  形态学轮廓提取函数

      WriteableBitmap MorcontourextractionProcess(WriteableBitmap src)

       /// <summary>
/// Morgraphy contour extraction process.
/// </summary>
/// <param name="src">The source image.</param>
/// <returns></returns>
public static WriteableBitmap MorcontourextractionProcess(WriteableBitmap src)////形态学轮廓提取
{
if (src != null)
{
int w = src.PixelWidth;
int h = src.PixelHeight;
WriteableBitmap corrosionImage = new WriteableBitmap(w, h);
byte[] temp = src.PixelBuffer.ToArray();
byte[] tempMask = (byte[])temp.Clone();
for (int j = 0; j < h; j++)
{
for (int i = 0; i < w; i++)
{
if (i == 0 || i == w - 1 || j == 0 || j == h - 1)
{
temp[i * 4 + j * w * 4] = (byte)255;
temp[i * 4 + 1 + j * w * 4] = (byte)255;
temp[i * 4 + 2 + j * w * 4] = (byte)255;
}
else
{
if (tempMask[i * 4 - 4 + j * w * 4] == 255 && tempMask[i * 4 + j * w * 4] == 255 && tempMask[i * 4 + 4 + j * w * 4] == 255
&& tempMask[i * 4 + (j - 1) * w * 4] == 255 && tempMask[i * 4 + (j + 1) * w * 4] == 255)
{
temp[i * 4 + j * w * 4] = (byte)255;
temp[i * 4 + 1 + j * w * 4] = (byte)255;
temp[i * 4 + 2 + j * w * 4] = (byte)255;
}
else
{
temp[i * 4 + j * w * 4] = 0;
temp[i * 4 + 1 + j * w * 4] = 0;
temp[i * 4 + 2 + j * w * 4] = 0;
}
}
}
}
for (int i = 0; i < temp.Length; i++)
{
temp[i] = (byte)(tempMask[i]-temp[i]);
}
Stream sTemp = corrosionImage.PixelBuffer.AsStream();
sTemp.Seek(0, SeekOrigin.Begin);
sTemp.Write(temp, 0, w * 4 * h);
return corrosionImage;
}
else
{
return null;
}
}

最后,分享一个专业的图像处理网站(微像素),里面有很多源代码下载:

最新文章

  1. openssl evp 对称加密(AES_ecb,ccb)
  2. [JS]递归对象或数组
  3. C#EXCEL 操作类--C#ExcelHelper操作类
  4. 整合Spring与Hibernate
  5. 合并JS和CSS
  6. Activity跳转
  7. rmq问题模板处理
  8. scrapy流程
  9. LeetCode算法扫题系列19
  10. 第一次使用Git上传本地项目到github上
  11. 吸血鬼日记第一季/全集The Vampire Diaries迅雷下载
  12. 为Docker容器中运行的gitlab添加ssh的一些问题记录
  13. POJ 2240 - Arbitrage - [bellman-ford求最短路]
  14. C# unity 的 IInterceptionBehavior实现aop拦截器
  15. hdu 4435 第37届ACM/ICPC天津现场赛E题
  16. 黄聪:win7 64位系统PS、AI、PSD缩略图预览补丁
  17. 8.7 正确使用索引(no)
  18. python 常用 time, datetime处理
  19. Java Web用Freemarker生成带图片的Word文档
  20. zookeeper 编程框架 curator

热门文章

  1. 01_Git的安装和简单使用(命令行模式+图形化模式)
  2. simple java mail
  3. Spring处理跨域请求
  4. Struts2——(4)OGNL与struts标签
  5. Qt中(图片)资源的三种使用方式
  6. IIS相关优化
  7. Qt浅谈之十八:GraphicsView框架事件处理(有源码下载)
  8. Python 金融数据分析 (一)—— 股票数据
  9. xcode代码统计行
  10. 局部QEventLoop帮助QWidget不消失(也就是有一个局部事件循环始终在运行,导致程序被卡住那里,但仍可以接受事件。说白了就是有一个while语句死活不肯退出,直到收到退出信号)