@@ -0,0 +1,75 @@
|
||||
#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)
|
||||
{
|
||||
cout << "无法打开文件" << endl;
|
||||
return 0;
|
||||
}
|
||||
fread(grey, sizeof(unsigned char), H * W, f);
|
||||
fclose(f);
|
||||
|
||||
// 模板
|
||||
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];
|
||||
|
||||
for (i = 0; i < H * W; i++)
|
||||
{
|
||||
result_grey[i] = 255;
|
||||
}
|
||||
for (i = th / 2; i < H - th / 2; i++)
|
||||
{
|
||||
for (j = tw / 2; j < W - tw / 2; j++)
|
||||
{
|
||||
// 应用prewitt模板
|
||||
int sum1 = 0;
|
||||
int sum2 = 0;
|
||||
int sum=0;
|
||||
for (k = -th / 2; k <= th / 2; k++)
|
||||
{
|
||||
for (l = -tw / 2; l <= tw / 2; l++)
|
||||
{
|
||||
sum1 += grey[(i + k) * W + (j + l)] * template1[(k + th / 2) * tw + (l + tw / 2)];
|
||||
sum2 += grey[(i + k) * W + (j + l)] * template2[(k + th / 2) * tw + (l + tw / 2)];
|
||||
}
|
||||
}
|
||||
sum=abs(sum1)+abs(sum2);
|
||||
if(sum>100)
|
||||
{
|
||||
result_grey[i * W + j] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
result_grey[i * W + j] = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
FILE *fnew;
|
||||
fopen_s(&fnew, "./数据/prewitt.raw", "wb");
|
||||
if (fnew)
|
||||
{
|
||||
fwrite(result_grey, sizeof(unsigned char), H * W, fnew);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "创建文件失败" << endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
#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;
|
||||
}
|
||||
fread(grey, sizeof(unsigned char), H * W, f);
|
||||
fclose(f);
|
||||
|
||||
// 模板
|
||||
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_grey;
|
||||
result_grey = new unsigned char[H * W];
|
||||
|
||||
for (i = 0; i < H * W; i++)
|
||||
{
|
||||
result_grey[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)];
|
||||
}
|
||||
}
|
||||
if (sum > 100)
|
||||
{
|
||||
result_grey[i * W + j] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
result_grey[i * W + j] = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
FILE *fnew;
|
||||
fopen_s(&fnew, "./数据/laplacian.raw", "wb");
|
||||
if (fnew)
|
||||
{
|
||||
fwrite(result_grey, sizeof(unsigned char), H * W, fnew);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "创建文件失败" << endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
#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 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];
|
||||
|
||||
for (i = 0; i < H * W; i++)
|
||||
{
|
||||
result_grey[i] = 255;
|
||||
}
|
||||
for (i = th / 2; i < H - th / 2; i++)
|
||||
{
|
||||
for (j = tw / 2; j < W - tw / 2; j++)
|
||||
{
|
||||
int gx = 0;
|
||||
int gy = 0;
|
||||
for (k = -th / 2; k <= th / 2; k++)
|
||||
{
|
||||
for (l = -tw / 2; l <= tw / 2; l++)
|
||||
{
|
||||
int pixel = grey[(i + k) * W + (j + l)];
|
||||
int index = (k + th / 2) * tw + (l + tw / 2);
|
||||
gx += pixel * sobel_x[index];
|
||||
gy += pixel * sobel_y[index];
|
||||
}
|
||||
}
|
||||
int sum = (int)sqrt(gx * gx + gy * gy);
|
||||
if (sum > 100)
|
||||
{
|
||||
result_grey[i * W + j] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
result_grey[i * W + j] = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
FILE *fnew;
|
||||
fopen_s(&fnew, "./数据/sobel.raw", "wb");
|
||||
if (fnew)
|
||||
{
|
||||
fwrite(result_grey, sizeof(unsigned char), H * W, fnew);
|
||||
fclose(fnew);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "创建文件失败" << endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 71 KiB |
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user