Below is a part of my code where I am trying to apply an image filer to clear an image
//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));
}
The problem is that I get the below error when i process the image
Value was either too large or too small for an Int32.
On
int A = lM + Convert.ToInt32(tm2);
Any idea what the problem is?
edit: did some debugging
lM hold 0 and lVAR hold 0