原文:Win8Metro(C#)数字图像处理--2.29图像除法运算



[函数名称]

图像除法函数DivisionProcess(WriteableBitmap src, WriteableBitmap divSrc)

[函数代码]

        /// <summary>
/// Division of two images.
/// </summary>
/// <param name="src">The frist source image.</param>
/// <param name="divSrc">The second source image.</param>
/// <returns></returns>
public static WriteableBitmap DivisionProcess(WriteableBitmap src,WriteableBitmap divSrc)////29图像除法
{
if (src != null)
{
int w = src.PixelWidth;
int h = src.PixelHeight;
WriteableBitmap divImage = new WriteableBitmap(w, h);
byte[] temp = src.PixelBuffer.ToArray();
byte[] divTemp = divSrc.PixelBuffer.ToArray();
byte[] dst = new byte[w * h * 4];
int r = 0, g = 0, b = 0, graySrc = 0, grayDiv = 0;
for (int i = 0; i < w; i++)
{
for (int j = 0; j < h; j++)
{
graySrc = temp[i * 4 + (h - 1 - j) * w * 4] + temp[i * 4 + 1 + (h - 1 - j) * w * 4] + temp[i * 4 + 2 + (h - 1 - j) * w * 4];
grayDiv = divTemp[i * 4 + (h - 1 - j) * w * 4] + divTemp[i * 4 + 1 + (h - 1 - j) * w * 4] + divTemp[i * 4 + 2 + (h - 1 - j) * w * 4];
if (grayDiv + graySrc != 0)
{
b = temp[i * 4 + (h - 1 - j) * w * 4] * (temp[i * 4 + (h - 1 - j) * w * 4] - divTemp[i * 4 + (h - 1 - j) * w * 4]) / (temp[i * 4 + (h - 1 - j) * w * 4] + divTemp[i * 4 + (h - 1 - j) * w * 4]);
g = temp[i * 4 + 1 + (h - 1 - j) * w * 4] * (temp[i * 4 + 1 + (h - 1 - j) * w * 4] - divTemp[i * 4 + 1 + (h - 1 - j) * w * 4]) / (temp[i * 4 + 1 + (h - 1 - j) * w * 4] + divTemp[i * 4 + 1 + (h - 1 - j) * w * 4]);
r = temp[i * 4 + 2 + (h - 1 - j) * w * 4] * (temp[i * 4 + 2 + (h - 1 - j) * w * 4] - divTemp[i * 4 + 2 + (h - 1 - j) * w * 4]) / (temp[i * 4 + 2 + (h - 1 - j) * w * 4] + divTemp[i * 4 + 2 + (h - 1 - j) * w * 4]);
dst[i * 4 + j * w * 4] = (byte)(b > 0 ? (b < 255 ? b : 255) : 0);
dst[i * 4 + 1 + j * w * 4] = (byte)(g > 0 ? (g < 255 ? g : 255) : 0);
dst[i * 4 + 2 + j * w * 4] = (byte)(r > 0 ? (r < 255 ? r : 255) : 0);
dst[i * 4 + 3 + j * w * 4] = 0;
b = 0; g = 0; r = 0;
}
}
}
Stream sTemp = divImage.PixelBuffer.AsStream();
sTemp.Seek(0, SeekOrigin.Begin);
sTemp.Write(dst, 0, w * 4 * h);
return divImage;
}
else
{
return null;
}
}

Win8Metro(C#)数字图像处理--2.29图像除法运算的更多相关文章

  1. Win8Metro(C#)数字图像处理--2.27图像加法运算

    原文:Win8Metro(C#)数字图像处理--2.27图像加法运算  [函数名称] 图像加法函数AddProcess(WriteableBitmap src, WriteableBitmap a ...

  2. Win8Metro(C#)数字图像处理--2.3图像反色

    原文:Win8Metro(C#)数字图像处理--2.3图像反色 [函数名称] 图像反色函数ContraryProcess(WriteableBitmap src) [算法说明]     反色公式如下: ...

  3. Win8Metro(C#)数字图像处理--2.33图像非线性变换

    原文:Win8Metro(C#)数字图像处理--2.33图像非线性变换  [函数名称] 图像非线性变换函数NonlinearTransformProcess(WriteableBitmap src ...

  4. Win8Metro(C#)数字图像处理--2.32图像曝光算法

    原文:Win8Metro(C#)数字图像处理--2.32图像曝光算法  [函数名称] 图像曝光函数ExposureProcess(WriteableBitmap src,int exposureV ...

  5. Win8Metro(C#)数字图像处理--2.28图像乘法运算

    原文:Win8Metro(C#)数字图像处理--2.28图像乘法运算  [函数名称] 图像乘法函数MultiplicationProcess(WriteableBitmap src, Writea ...

  6. Win8Metro(C#)数字图像处理--2.26图像减法

    原文:Win8Metro(C#)数字图像处理--2.26图像减法  [函数名称] 图像减法函数SubtractionProcess(WriteableBitmap src, WriteableBi ...

  7. Win8Metro(C#)数字图像处理--2.19图像水平镜像

    原文:Win8Metro(C#)数字图像处理--2.19图像水平镜像  [函数名称] 图像水平镜像函数MirrorXProcess(WriteableBitmap src) [函数代码]      ...

  8. Win8Metro(C#)数字图像处理--2.20图像垂直镜像

    原文:Win8Metro(C#)数字图像处理--2.20图像垂直镜像  [函数名称] 图像垂直镜像函数MirrorYProcess(WriteableBitmap src) [函数代码]      ...

  9. Win8Metro(C#)数字图像处理--2.18图像平移变换

    原文:Win8Metro(C#)数字图像处理--2.18图像平移变换  [函数名称] 图像平移变换函数TranslationProcess(WriteableBitmap src,int x,in ...

随机推荐

  1. 解决duilib水平布局(HorizontalLayout)中控件位置计算错误的问题

    水平布局中的控件无法布满整个布局,右側留有缝隙 修正后的样子 原因是布局中的代码计算Padding时候逻辑不对导致 修正后的代码到https://github.com/CodeBees/duilib- ...

  2. [Typescript] Sorting arrays in TypeScript

    In this lesson we cover all the details of how to sort a list of items using TypeScript. We also pre ...

  3. 数据结构与算法——常用高级数据结构及其Java实现

    前文 数据结构与算法--常用数据结构及其Java实现 总结了基本的数据结构,类似的,本文准备总结一下一些常见的高级的数据结构及其常见算法和对应的Java实现以及应用场景,务求理论与实践一步到位. 跳跃 ...

  4. [React Router v4] Render Catch-All Routes with the Switch Component

    There are many cases where we will need a catch-all route in our web applications. This can include ...

  5. oracle中imp导入数据中文乱码问题(转)

    (转自  http://blog.chinaunix.net/uid-186064-id-2823338.html) oracle中imp导入数据中文乱码问题 用imp命令向oracle中导入数据后, ...

  6. tomcat 去除端口和项目名/使用域名访问/修改超链接为IP地址

    1.打开tomcat/conf/server.xml 在host标签中加入 <Context  docBase="项目名" path="" reloada ...

  7. 一起学Python:协程

    一:协程-yield 协程,又称微线程,纤程.英文名Coroutine. 协程是啥 协程是python个中另外一种实现多任务的方式,只不过比线程更小占用更小执行单元(理解为需要的资源). 为啥说它是一 ...

  8. sqoop 创建job时 java.lang.NoClassDefFoundError: org/json/JSONObject

    缺少jar包 到maven仓库下载json in java 之后把jar包上传至sqoop的lib目录下即可

  9. Android Studio官方文档: 如何在你的设备上运行你的程序

    在实体设备上运行您的应用 设置您的设备,如下所示: 使用一根 USB 电缆将您的设备连接到您的开发机器. 如果您是在 Windows 上开发,可能需要为您的设备安装相应的 USB 驱动程序.如需帮助安 ...

  10. JScript分割字符串

    作者:朱金灿 来源:http://blog.csdn.net/clever101 不废话了,直接用代码说明吧: try { var ss = new Array(); var str="12 ...