+15
-11
@@ -24,18 +24,20 @@ int main()
|
||||
return 0;
|
||||
}
|
||||
|
||||
// sobel模板
|
||||
int tw = 3;
|
||||
int th = 3;
|
||||
// xy方向的sobel模板
|
||||
int sobel_x[9]={-1,0,1,-2,0,2,-1,0,1};
|
||||
int sobel_y[9]={-1,-2,-1,0,0,0,1,2,1};
|
||||
|
||||
int i,j,k,l;
|
||||
unsigned char *result_grey;
|
||||
result_grey = new unsigned char[H * W];
|
||||
int i,j,k,l; // 中间变量
|
||||
unsigned char *result;
|
||||
result = new unsigned char[H * W];
|
||||
|
||||
for (i = 0; i < H * W; i++)
|
||||
{
|
||||
result_grey[i] = 255;
|
||||
result[i] = 255;
|
||||
}
|
||||
for (i = th / 2; i < H - th / 2; i++)
|
||||
{
|
||||
@@ -56,20 +58,22 @@ int main()
|
||||
int sum = (int)sqrt(gx * gx + gy * gy);
|
||||
if (sum > 100)
|
||||
{
|
||||
result_grey[i * W + j] = 0;
|
||||
result[i * W + j] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
result_grey[i * W + j] = 255;
|
||||
result[i * W + j] = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
FILE *fnew;
|
||||
fopen_s(&fnew, "./数据/sobel.raw", "wb");
|
||||
if (fnew)
|
||||
|
||||
// 将结果写入文件
|
||||
FILE *fresult;
|
||||
fopen_s(&fresult, "./数据/sobel.raw", "wb");
|
||||
if (fresult)
|
||||
{
|
||||
fwrite(result_grey, sizeof(unsigned char), H * W, fnew);
|
||||
fclose(fnew);
|
||||
fwrite(result, sizeof(unsigned char), H * W, fresult);
|
||||
fclose(fresult);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user