這個
我打sobel出點問題
但我確定我遮罩應該沒問題
我做出的圖:http://www.wretch.cc/album/album.php?id=willydog029&book=5&page=1
做出的圖 和正確的sobel出入很多
希望有大大幫我看一下code
============================================================================
private void 邊線邊緣sobelToolStripMenuItem_Click(object sender, EventArgs e)
{
//定義變數 陣列
Bitmap sobel = new Bitmap(curBitmap);
int [,] arr_r;
int [,] arr_g;
int [,] arr_b;
byte[,] temp_array;
arr_r = new int[sobel.Width, sobel.Height];
arr_g = new int[sobel.Width, sobel.Height];
arr_b = new int[sobel.Width, sobel.Height];
temp_array=new byte[sobel.Width, sobel.Height];
//計算Gx 和Gy
double x;
double y;
double grad;
for (int i = 1; i < (sobel.Width-1); i++)
{
for (int j = 1; j < (sobel.Height-1); j++)
{
arr_r[i, j] = sobel.GetPixel(i, j).R;
arr_g[i, j] = sobel.GetPixel(i, j).G;
arr_b[i, j] = sobel.GetPixel(i, j).B;
//先灰階化
arr_r[i, j] =(arr_r[i,j]+arr_g[i,j]+arr_b[i,j])/3;
//sobel的Gx能階
//1 0 -1
//2 0 -2
//1 0 -1
x=System.Math.Abs(1*arr_r[i-1,j-1]+2*arr_r[i-1,j] + 1*arr_r[i-1,j+1]
- arr_r[i+1, j-1] - 2 * arr_r[i+1, j] - arr_r[i + 1, j + 1]);
//sobel的Gy
//1 2 1
//0 0 0
//-1 -2 -1
y=System.Math.Abs(1*arr_r[i-1,j-1]+2*arr_r[i,j-1]+1*arr_r[i+1,j-1]
-1*arr_r[i-1,j+1]-2*arr_r[i,j+1]-1*arr_r[i+1,j+1]);
grad = System.Math.Sqrt(x*x+y*y);
temp_array[i, j] =(byte)(grad);
sobel.SetPixel(i,j,Color.FromArgb(temp_array[i, j],temp_array[i, j],
temp_array[i,j]));
}
}
}
=============================================================================
希望有大大可以幫我看一下code
我知道看別人code很累~~所以我是有先查過資料的
還有我想應該不是沒做2值化才不一樣
希望有大大可幫忙修CODE
真的希望可以學好程式......THX
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 163.25.118.131