C# 3x3平均值滤波器(C)#
我已经编写了平滑图像的代码,它使用3x3平均滤波器。但它似乎不起作用 这幅画几乎是黑色的C# 3x3平均值滤波器(C)#,c#,image,C#,Image,我已经编写了平滑图像的代码,它使用3x3平均滤波器。但它似乎不起作用 这幅画几乎是黑色的 public void Smooth(Bitmap bmpInput){ Bitmap temp; Color c; float sum = 0; for (int i = 0; i < bmpInput.Width; i++) { for (int j = 0; j < bmpInput
public void Smooth(Bitmap bmpInput){
Bitmap temp;
Color c;
float sum = 0;
for (int i = 0; i < bmpInput.Width; i++)
{
for (int j = 0; j < bmpInput.Height; j++)
{
c = bmpInput.GetPixel(i, j);
byte gray = (byte)(.333 * c.R + .333 * c.G + .333 * c.B);
bmpInput.SetPixel(i, j, Color.FromArgb(gray, gray, gray));
}
}
temp = bmpInput;
for (int i = 0; i <= bmpInput.Width - 3; i++)
for (int j = 0; j <= bmpInput.Height - 3; j++)
{
for (int x = i; x <= i + 2; x++)
for (int y = j; y <= j + 2; y++)
{
c = bmpInput.GetPixel(x,y);
sum = sum + c.R ;
}
int color = (int)Math.Round(sum/9,10);
temp.SetPixel(i + 1, j + 1, Color.FromArgb(color, color, color));
sum = 0;
}
bmpInput = temp;
}
public void平滑(位图bmpInput){
位图温度;
颜色c;
浮点数和=0;
for(int i=0;i 对于(int i=0;i变量temp
仍然引用完全相同的位图。您必须将temp
分配给新位图图像并使用它。或者,您可以将新像素值存储在临时数组中,然后将此数组的内容传输回图像。您能否详细说明它是如何工作的?非常感谢你:D