下面是我的代码的一部分,我正在尝试应用图像过滤器来清除图像
//Convert the image to integer array
uint[,] image = new uint[use.Width, use.Height];
for (i = 0; i < use.Width; i++)
{
for (j = 0; j < use.Height; j++)
{
image[i, j] = Convert.ToUInt32(use.GetPixel(i, j).R);
}
}
int Block = 5;
int BlockSqr = 25;
// Internal Block Processing
for (i = Block; i < use.Width- Block; i = i + 1)
for (j = Block; j < use.Height- Block; j = j + 1)
{
int lM, lVAR;
// Calculating the Mean of the Block
tmp = 0;
for (int k = i - Block; k < i + Block; k = k + 1)
{
for (int l = j - Block; l < j + Block; l = l + 1)
{
tmp = tmp + image[k, l];
}
}
lM = Convert.ToInt32(Math.Abs(tmp / BlockSqr));
// Calculating the Variance of the Block
tmp = 0;
M1 = 0;
for (int k = i - Block; k < Block + i; k = k + 1)
{
for (int l = j - Block; l < Block + j; l = l + 1)
{
M1 = ((image[k, l] - Convert.ToUInt32(lM)) * (image[k, l] - Convert.ToUInt32(lM)));
tmp = tmp + M1;
}
}
lVAR = Convert.ToInt32(Math.Abs(tmp / BlockSqr));
//Putting the filtered value
float tm = (lVAR - mVAR);
float tm1 = tm / lVAR;
int mm = Convert.ToInt32(image[i, j] - lM);
float tm2 = tm1 * (image[i, j] - lM);
int A = lM + Convert.ToInt32(tm2);
if (A < 255)
Wiener.SetPixel(i, j, Color.FromArgb(255, A, A, A));
}
问题是我在处理图像时收到以下错误
对于 Int32,值太大或太小。
上
int A = lM + Convert.ToInt32(tm2);
知道问题是什么吗?
编辑:做了一些调试
lM 保持 0 和 lVAR 保持 0