1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Win8Metro(C#)数字图像处理--2.7图像伪彩色

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

时间:2021-11-22 21:57:21

相关推荐

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

Win8Metro(C#)数字图像处理--2.7图像伪彩色 原文: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;

}

}

  posted on -03-13 10:00 NET未来之路 阅读(...) 评论(...) 编辑 收藏

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。