You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.2 KiB
53 lines
1.2 KiB
#include<stdio.h>
|
|
#include<time.h>
|
|
void applySeparableGaussianBlur(float src[5][5], float dst[5][5], int h, int w, float kx[3], float ky[3])
|
|
{
|
|
float buf[3][5] = { 0 };
|
|
for (int i = 1; i < h - 1; i++)
|
|
{
|
|
for (int j = 1; i < h - 1; i++)
|
|
{
|
|
for (int j = 0; j < w; j++)
|
|
{
|
|
if (j == 0 || j == 1 || j == 2)
|
|
{
|
|
buf[j][i] = src[i - 1][j] * kx[0] + src[i][j] * kx[1] + src[i + 1][j] * kx[2];
|
|
}
|
|
}
|
|
}
|
|
if (i >= 1)
|
|
{
|
|
for (int j = 1; j < w - 1; j++)
|
|
{
|
|
float sum = 0;
|
|
for (int k = 0; k < 3; k++)
|
|
{
|
|
sum += buf[k][j] * ky[k];
|
|
}
|
|
dst[i][j] = sum;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
int main()
|
|
{
|
|
float src[5][5] = {{1,2,3,4,5},{6,7,8,9,10},{11,12,13,14,15},{16,17,18,19,20},{21,22,23,24,25}};
|
|
float dst[5][5] = { 0 };
|
|
float kx[3]= { 1 / 16.0, 2 / 16.0, 1 / 16.0 };
|
|
float ky[3]= { 1 / 16.0, 2 / 16.0, 1 / 16.0 };
|
|
clock_t start = clock();
|
|
applySeparableGaussianBlur (src,dst, 5, 5, kx,ky);
|
|
clock_t end = clock();
|
|
printf("模糊后的图像矩阵:\n");
|
|
for (int i = 0; i <5; i++)
|
|
{
|
|
for (int j = 0; j < 5; j++)
|
|
{
|
|
printf("%.2f", dst[i][j]);
|
|
}
|
|
printf("\n");
|
|
}
|
|
double time_taken = ((double)(end - start)) / CLOCKS_PER_SEC;
|
|
printf("运行时间:%f 秒\n", time_taken);
|
|
return 0;
|
|
} |