锐化图像滤镜
本文关键字:滤镜 图像 锐化 | 更新日期: 2023-09-27 18:18:45
我有一个代码,可以保存在我的计算机上的图像,并将其处理成灰度,平滑的灰度和巧妙的边缘图像。我想做的是通过给图像添加某种类型的滤镜来锐化图像,然后转换为灰色和精明的边缘帧。我相信我的代码是正确的,但当我运行程序时,它似乎没有什么不同。锐化图像是否在错误的地方?它是不是被忽视了?有什么建议请告诉我。
private void ProcessFrame()
{
String fileName = @"C:'filename";
**Sharpen Image Filter code**
public static Bitmap sharp(Bitmap img)
{
Bitmap sharpenImage = new Bitmap(img.Width, img.Height);
int filterWidth = 3;
int filterHeight = 3;
int w = img.Width;
int h = img.Height;
double[,] filter = new double[filterWidth, filterHeight];
filter[0, 0] = filter[0, 1] = filter[0, 2] = filter[1, 0] = filter[1, 2] =
filter[2,0] = filter[2, 1] = filter[2, 2] = -1;
filter[1, 1] = 9;
double factor = 1.0;
double bias = 0.0;
Color[,] result = new Color[img.Width, img.Height];
for (int x = 0; x < w; ++x)
{
for (int y = 0; y < h; ++y)
{
double red = 0.0, green = 0.0, blue = 0.0;
for (int filterX = 0; filterX < filterWidth; filterX++)
{
for (int filterY = 0; filterY < filterHeight; filterY++)
{
int imageX = (x - filterWidth / 2 + filterX + w) % w;
int imageY = (y - filterHeight / 2 + filterY + h) % h;
Color imageColor = img.GetPixel(imageX, imageY);
red += imageColor.R * filter[filterX, filterY];
green += imageColor.G * filter[filterX, filterY];
blue += imageColor.B * filter[filterX, filterY];
}
int r = Math.Min(Math.Max((int)(factor * red + bias), 0), 255);
int g = Math.Min(Math.Max((int)(factor * green + bias), 0), 255);
int b = Math.Min(Math.Max((int)(factor * blue + bias), 0), 255);
result[x, y] = Color.FromArgb(r, g, b);
}
}
}
for (int i = 0; i < w; ++i)
{
for (int j = 0; j < h; ++j)
{
sharpenImage.SetPixel(i, j, result[i, j]);
}
}
return sharpenImage;
}
**Sharpen Image Code Ends**
我想我可能错过了它,但它看起来不像你曾经调用你的图像锐化代码。这当然可以解释为什么结果没有改变!