fb52de1e8f
Co-authored-by: Copilot <copilot@github.com>
80 lines
1.6 KiB
C++
80 lines
1.6 KiB
C++
#include<iostream>
|
|
#include<cmath>
|
|
#include<cstdio>
|
|
|
|
#define H 265
|
|
#define W 272
|
|
|
|
using namespace std;
|
|
|
|
int main()
|
|
{
|
|
unsigned char *grey;
|
|
grey = new unsigned char[H * W];
|
|
FILE *f;
|
|
fopen_s(&f, "./数据/blood.raw", "rb");
|
|
if (f)
|
|
{
|
|
fread(grey, sizeof(unsigned char), H * W, f);
|
|
fclose(f);
|
|
}
|
|
else
|
|
{
|
|
cout << "无法打开文件" << endl;
|
|
return 0;
|
|
}
|
|
|
|
// 拉普拉斯模板
|
|
int tw = 3;
|
|
int th = 3;
|
|
int template1[9]={0,1,0,1,-4,1,0,1,0};
|
|
|
|
int i,j,k,l; // 中间变量
|
|
unsigned char *result;
|
|
result = new unsigned char[H * W];
|
|
|
|
for (i = 0; i < H * W; i++)
|
|
{
|
|
result[i] = 255;
|
|
}
|
|
for (i = th / 2; i < H - th / 2; i++)
|
|
{
|
|
for (j = tw / 2; j < W - tw / 2; j++)
|
|
{
|
|
// 应用拉普拉斯模板
|
|
int sum = 0;
|
|
for (k = -th / 2; k <= th / 2; k++)
|
|
{
|
|
for (l = -tw / 2; l <= tw / 2; l++)
|
|
{
|
|
sum += grey[(i + k) * W + (j + l)] * template1[(k + th / 2) * tw + (l + tw / 2)];
|
|
}
|
|
}
|
|
sum = abs(sum);
|
|
if (sum < 1)
|
|
{
|
|
result[i * W + j] = 0;
|
|
}
|
|
else
|
|
{
|
|
result[i * W + j] = 255;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 将结果写入文件
|
|
FILE *fresult;
|
|
fopen_s(&fresult, "./数据/laplacian.raw", "wb");
|
|
if (fresult)
|
|
{
|
|
fwrite(result, sizeof(unsigned char), H * W, fresult);
|
|
fclose(fresult);
|
|
}
|
|
else
|
|
{
|
|
cout << "创建文件失败" << endl;
|
|
return 0;
|
|
}
|
|
|
|
return 0;
|
|
} |