[函数名称]
图像锐化函数SharpeningProcess(WriteableBitmap src,double sharpenValue)
[函数代码]
///<summary>
/// Sharpening process.
///</summary>
///<param name="src">Source image.</param>
///<returns></returns>
publicstaticWriteableBitmap SharpeningProcess(WriteableBitmap src)////11锐化处理
{
if(src!=null )
{
int w = src.PixelWidth;
int h = src.PixelHeight;
WriteableBitmap sharpenImage =newWriteableBitmap(w,h);
byte[] temp = src.PixelBuffer.ToArray();
byte[] tempMask = (byte[])temp.Clone();
double b = 0, g = 0, r = 0, srR = 0, srG = 0, srB = 0;
for (int j = 1; j < h - 1; j++)
{
for (int i = 4; i < w * 4 - 4; i += 4)
{
srB = tempMask[i + j * w * 4];
srG = tempMask[i + 1 + j * w * 4];
srR = tempMask[i + 2 + j * w * 4];
b =Math.Abs(5 * srB - tempMask[i - 4 + j * w * 4] - tempMask[i + 4 + j * w * 4] - tempMask[i + (j - 1) * w * 4] - tempMask[i + (j + 1) * w * 4]);
g =Math.Abs(5 * srG - tempMask[i - 4 + 1 + j * w * 4] - tempMask[i + 4 + 1 + j * w * 4] - tempMask[i + 1 + (j - 1) * w * 4] - tempMask[i + 1 + (j + 1) * w * 4]);
r =Math.Abs(5 * srR - tempMask[i - 4 + 2 + j * w * 4] - tempMask[i + 4 + 2 + j * w * 4] - tempMask[i + 2 + (j - 1) * w * 4] - tempMask[i + 2 + (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; srR = 0; srG = 0; srB = 0;
}
}
Stream sTemp = sharpenImage.PixelBuffer.AsStream();
sTemp.Seek(0,SeekOrigin.Begin);
sTemp.Write(temp, 0, w * 4 * h);
return sharpenImage;
}
else
{
returnnull;
}
}
[图像效果]