+15
-11
@@ -20,19 +20,19 @@ int main()
|
||||
fread(grey, sizeof(unsigned char), H * W, f);
|
||||
fclose(f);
|
||||
|
||||
// 模板
|
||||
// prewitt模板
|
||||
int tw = 3;
|
||||
int th = 3;
|
||||
int template1[9]={-1,0,1,-1,0,1,-1,0,1};
|
||||
int template2[9]={-1,-1,-1,0,0,0,1,1,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++)
|
||||
{
|
||||
@@ -53,23 +53,27 @@ int main()
|
||||
sum=abs(sum1)+abs(sum2);
|
||||
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, "./数据/prewitt.raw", "wb");
|
||||
if (fnew)
|
||||
|
||||
// 将结果写入文件
|
||||
FILE *fresult;
|
||||
fopen_s(&fresult, "./数据/prewitt.raw", "wb");
|
||||
if (fresult)
|
||||
{
|
||||
fwrite(result_grey, sizeof(unsigned char), H * W, fnew);
|
||||
fwrite(result, sizeof(unsigned char), H * W, fresult);
|
||||
fclose(fresult);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "创建文件失败" << endl;
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user