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.

64 lines
1.5 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <stdio.h>
#include <ctime>
#include <stdlib.h>
#define H 5
#define W 5
void applyGaussianBlur(float src[H][W], float dst[H][W], int h, int w, float kernel[3][3])
{
for(int i=1;i<h-1;++i)
{
for (int j = 1; j< w - 1; ++j)
{
dst[i][j] =
src[i - 1][j - 1] * kernel[0][0] + src[i - 1][j] * kernel[0][1] + src[i - 1][j + 1] * kernel[0][2]+
src[i][j - 1] * kernel[1][0] + src[i][j]* kernel[1][1] + src[i][j + 1] * kernel[1][2] +
src[i + 1][j - 1] * kernel[2][0] + src[i + 1][j] * kernel[2][1] + src[i + 1][j + 1] * kernel[2][2];
}
}
}
int main()
{
float inputImage[H][W]=
{
{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 kernel[3][3]=
{
{1.0f/16,2.0f/16,1.0f/16},
{2.0f/16,4.0f/16,2.0f/16},
{1.0f/16,2.0f/16,1.0f/16}
};
float dst[H][W]=
{
{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}
};
clock_t start = clock();
applyGaussianBlur(inputImage, dst, H,W, kernel);
clock_t end = clock();
double time_spent = double(end - start) / CLOCKS_PER_SEC;
printf("运行时间:%lf秒\n不考虑边界dst矩阵结果为\n",time_spent);
for(int i=0;i<H;i++)
{
for(int j=0;j<W;j++)
{
printf("%f ",dst[i][j]);
}
printf("\n");
}
}