影像處理C#程式碼相關問題請大大幫忙修正哪裡錯誤 [論壇 - Ubuntu 程式設計]


正在瀏覽:   1 名遊客


 到底部   前一個主題   下一個主題  [無發表權] 請登錄或者註冊



影像處理C#程式碼相關問題請大大幫忙修正哪裡錯誤
會員一級
註冊日期:
2015/5/30 12:20
所屬群組:
已註冊使用者
等級: 1
HP : 0 / 0
MP : 0 / 0
EXP: 0
離線
公式如圖片程式碼如下:
我已經先把
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;

附件:



png  未命名.png (6.82 KB)
42838_556955ffdbbea.png 1008X630 px

2015/5/30 14:23
應用擴展 工具箱
回覆: 影像處理C#程式碼相關問題請大大幫忙修正哪裡錯誤
會員一級
註冊日期:
2015/6/16 19:39
所屬群組:
已註冊使用者
等級: 1
HP : 0 / 0
MP : 0 / 0
EXP: 0
離線
感謝大大無私的分享~~~~~~
qwayne2012 寫到:
公式如圖片程式碼如下:
我已經先把
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;

2015/6/16 20:21
應用擴展 工具箱


 [無發表權] 請登錄或者註冊


可以查看帖子.
不可發帖.
不可回覆.
不可編輯自己的帖子.
不可刪除自己的帖子.
不可發起投票調查.
不可在投票調查中投票.
不可上傳附件.
不可不經審核直接發帖.