影像處理C#程式碼相關問題麻煩大大修正錯誤

公式如圖片程式碼如下:
我已經先把
pictureBox2.Image是IL ==>也是放大後影像
pictureBox3.Image是Iold ==>濾波後的影像

height = this.pictureBox2.Image.Height;
width = this.pictureBox2.Image.Width;
Bitmap bitmap1 = new Bitmap(pictureBox2.Image);
Bitmap bitmap2 = new Bitmap(pictureBox3.Image); 
Bitmap bitmap = new Bitmap(width, height);
double[,] image = new double[width, height];
double[,] image0 = new double[width, height];
double[,] image1 = new double[width, height];
double[, ,] image2 = new double[width, height, 30];
double[, ,] image3 = new double[width, height, 30];
double[,] image4 = new double[width, height];
double[, ,] image5 = new double[width, height, 30];
double[, ,] image6 = new double[width, height, 30];

double[,] image1R = new double[width, height];
double[,] image1G = new double[width, height];
double[,] image1B = new double[width, height];

double[,] image2R = new double[width, height];
double[,] image2G = new double[width, height];
double[,] image2B = new double[width, height];

double[,] image3R = new double[width, height];
double[,] image3G = new double[width, height];
double[,] image3B = new double[width, height];

double[,] image4R = new double[width, height];
double[,] image4G = new double[width, height];
double[,] image4B = new double[width, height];

double[, ,] image5R = new double[width, height,30];
double[, ,] image5G = new double[width, height, 30];
double[, ,] image5B = new double[width, height,30];

double[, ,] image6R = new double[width, height,30];
double[, ,] image6G = new double[width, height, 30];
double[, ,] image6B = new double[width, height,30];

double sum = 0;
double sumb = 0;
double dev = 0;
double devb = 0;
double sum0 = 0;
double sum2 = 0;
double dev0 = 0;
double dev1 = 0;
double gray1 = 0;
double graytest0 = 0;
int v = width * height;
//double B = Convert.ToDouble(textBox1.Text);
double C = Convert.ToDouble(textBox2.Text);
for (x = 0; x < width; x++)
{
for (y = 0; y < height; y++)
{
Color c = bitmap1.GetPixel(x, y);
Color c1 = bitmap2.GetPixel(x, y);
image1R[x, y] = c.R;
image1G[x, y] = c.G;
image1B[x, y] = c.B;

image2R[x, y] = c1.R;
image2G[x, y] = c1.G;
image2B[x, y] = c1.B;

image4R[x, y] = c.R;
image4G[x, y] = c.G;
image4B[x, y] = c.B; 
}
}
for (int L = 0; L < C; L++)
{
for (x = 0; x < width; x++)
{
for (y = 0; y < height; y++)

image3R[x, y] = 0.01 * ((int)(image1R[x, y] - image2R[x, y]));
image3G[x, y] = 0.01 * ((int)(image1G[x, y] - image2G[x, y]));
image3B[x, y] = 0.01 * ((int)(image1B[x, y] - image2B[x, y]));
image4R[x, y] += image3R[x, y];
image4G[x, y] += image3G[x, y];
image4B[x, y] += image3B[x, y]; 

image0[x, y] = (image1R[x, y] * 0.299 + image1G[x, y] * 0.587 + image1B[x, y] * 0.114);
image4[x, y] = (image4R[x, y] * 0.299 + image4G[x, y] * 0.587 + image4B[x, y] * 0.114);
image2[x, y, L] = image4[x, y];
image5[x, y, L] = image0[x, y];
image5R[x, y, L] = image4[x, y];
image6R[x, y, L] = image4[x, y];
}
}
for (x = 0; x < width; x++)
{
for (y = 0; y < height; y++)
{
image4[x, y] = 0;
}
}
for (x = 0; x < width; x++)
{
for (y = 0; y < height; y++)
{
sum0 += image5R[x, y, L]; 
}
}
sum2 = sum0 / v;
for (x = 0; x < width; x++)
{
for (y = 0; y < height; y++)
{
dev0 += Math.Pow((image6R[x, y, L]-sum2 ), 2); 
}
}
dev1 = Math.Sqrt(dev0 / v)*0.2;//絕對值
for (x = 0; x < width; x++)
{
for (y = 0; y < height; y++)
{
image6[x, y, L] = image5[x, y, L];
image3[x, y, L] = image2[x, y, L];
gray1 += image3[x, y, L]/v;
graytest0 += image6[x, y, L]/v ;
}
}
for (x = 0; x < width; x++)
{
for (y = 0; y < height; y++)
{
Color c = bitmap1.GetPixel(x, y);
image1R[x, y] = c.R;
image1G[x, y] = c.G;
image1B[x, y] = c.B;
image[x, y] = (image1R[x, y] * 0.299 + image1G[x, y] * 0.587 + image1B[x, y] * 0.114);
}
}
for (x = 0; x < width; x++)
{
for (y = 0; y < height; y++)
{
sum += image[x, y];
}
}
sumb = sum / v;
for (x = 0; x < width; x++)
{
for (y = 0; y < height; y++)
{
dev += Math.Pow((image[x, y] -sumb ), 2);
}
}
devb = Math.Sqrt(dev / v)*0.2;

Benjamin42159.4747453704