原文:Win8Metro(C#)数字图像处理--2.7图像伪彩色



2.7图像伪彩色函数

[函数名称]

图像伪彩色函数PseudoColorProcess(WriteableBitmap
src)

[算法说明]

  伪彩色是为改善视觉效果,利用计算机图像增强技术对图像的灰度赋予的不同假色彩,即,将一张灰度图转化为彩色图。主要原理是把灰度图像的各个不同灰度级按照线性或非线性的映射函数变换成为不同的彩色空间。

  本文采用基于RGB颜色空间的伪彩色映射算法。过程如下:

 [函数代码]

       ///<summary>

       ///
Pseudo color process.

       ///</summary>

       ///<param
name="src">Source image.</param>

       ///<returns></returns>

       publicstaticWriteableBitmap
PseudoColorProcess(WriteableBitmap src)////7伪彩色处理

       {

           if(src!=null
)

           {

           int
w = src.PixelWidth;

           int
h = src.PixelHeight;

           WriteableBitmap
pseudoImage =newWriteableBitmap(w,
h);

           byte[]
temp = src.PixelBuffer.ToArray();

           int
tGray = 0;

           for
(int i = 0; i < temp.Length; i += 4)

           {

               tGray = (int)(temp[i]
* 0.114 + temp[i + 1] * 0.587 + temp[i + 2] * 0.299);

               if
(tGray >= 0 && tGray <= 63)

               {

                   temp[i] = (byte)255;

                   temp[i + 1] = (byte)(254
- 4 * tGray);

                   temp[i + 2] = 0;

               }

               if
(tGray >= 64 && tGray <= 127)

               {

                   temp[i] = (byte)(510
- 4 * tGray);

                   temp[i + 1] = (byte)(4
* tGray - 254);

                   temp[i + 2] = (byte)0;

               }

               if
(tGray >= 128 && tGray <= 191)

               {

                   temp[i] = (byte)0;

                   temp[i + 1] = (byte)255;

                   temp[i + 2] = (byte)(4
* tGray - 510);

               }

               if
(tGray >= 192 && tGray <= 255)

               {

                   temp[i] = (byte)0;

                   temp[i + 1] = (byte)(1022
- 4 * tGray);

                   temp[i + 2] = (byte)255;

               }

               tGray = 0;

           }

           Stream
sTemp = pseudoImage.PixelBuffer.AsStream();

           sTemp.Seek(0,SeekOrigin.Begin);

           sTemp.Write(temp, 0, w * 4 * h);

           return
pseudoImage;

           }

           else

           {

               returnnull;

           }  

       }


 




Win8Metro(C#)数字图像处理--2.7图像伪彩色的更多相关文章

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

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

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

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

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

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

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

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

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

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

  6. Win8Metro(C#)数字图像处理--2.29图像除法运算

    原文:Win8Metro(C#)数字图像处理--2.29图像除法运算  [函数名称] 图像除法函数DivisionProcess(WriteableBitmap src, WriteableBit ...

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

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

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

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

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

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

随机推荐

  1. [SQL]远程使用PostgreSQL Studio可视化查看PostgreSQL数据库

    1.下载 前往官网地址下载最新的PostgreSQL Studio,我下载的是 pgstudio_1.2-bin .zip,由于我的电脑里面没有tomcat. 假设电脑里有配置好tomcat,能够下载 ...

  2. [Node.js] Initialize a LoopBack Node.js Project through the CLI

    LoopBack is a framework built on top of Express for creating APIs. It allows you to create end-to-en ...

  3. 前端切图:手机端自适应布局demo

    手机端自适应布局demo原型如下: 图片发自简书App 要求如下:适应各种机型源码如下: <!DOCTYPE html > <html> <head> <me ...

  4. Android View框架的measure机制

    概述 Android中View框架的工作机制中,主要有三个过程: 1.View树的測量(measure)Android View框架的measure机制 2.View树的布局(layout) Andr ...

  5. [转]mnesia数据库学习笔记

    mnesia数据库学习笔记一 mnesia数据库学习笔记二 mnesia数据库学习笔记三 mnesia数据库学习笔记四

  6. [GeekBand] C++ 基础知识之 The Big Three

    本文是GeekBand课程体系中,侯捷老师讲课内容的部分内容总结. 参考书籍如下:Effitive C++ C++ Primer 第五版 http://blog.csdn.net/lwbeyond/a ...

  7. springboot启动tomcat报错java.lang.NoClassDefFoundError: javax/el/ELManager仅记录

    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'o ...

  8. iOS CALayer使用

    CALayer使用 iOS的设备中,我们之所以能看到各种各样的控件.文字.图片,都是Core Animation框架的功劳.它通过图层的合成,最终显示在屏幕上.而今天这篇文章讲的就是Core Anim ...

  9. nextSibling.focus()报错的问题

    <body> <div> <input type="button" tabindex="-1" value="点点点点点 ...

  10. window.url.createobjecturl 兼容多种浏览器(IE,google,360,Safari,firefox)

    <script type="text/javascript"> function setImagePreview() { var docObj = document.g ...