From 39fb1c83897f35bc2c969f8c4545c2257a4236c1 Mon Sep 17 00:00:00 2001 From: pmfsq5yrv <1159971203@qq.com> Date: Fri, 6 Dec 2024 14:06:05 +0800 Subject: [PATCH] ADD file via upload --- yang/2.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 yang/2.c diff --git a/yang/2.c b/yang/2.c new file mode 100644 index 0000000..5cdb302 --- /dev/null +++ b/yang/2.c @@ -0,0 +1,63 @@ +#include +#include + +const int h = 5, w = 5; +float kx[3] = {0.25f, 0.5f, 0.25f}; +float ky[3] = {0.25f, 0.5f, 0.25f}; + +void separableGaussianBlur(float src[h][w], float dst[h][w], int h, int w, float kx[3], float ky[3]) { + float buf[3][w]; + int x, y; + + #define BUF_INDEX(i) ((i) % 3) + + for(y = 0; y < h; ++y){ + for(x = 0; x < w; ++x){ + buf[BUF_INDEX(y)][x] = + src[y][x] * kx[1] + + (x > 0 ? src[y][x - 1] * kx[0] : 0) + + (x < w - 1 ? src[y][x + 1] * kx[2] : 0); + } + + if(y >= 2){ + for(x = 1; x < w - 1; ++x){ + dst[y - 1][x] = + buf[BUF_INDEX(y - 2)][x] * ky[0] + + buf[BUF_INDEX(y - 1)][x] * ky[1] + + buf[BUF_INDEX(y)][x] * ky[2]; + } + } + } +} + +int main() { + int i, j; + float dst[h][w]; + for(i = 0; i < h; i++){ + for (j = 0; j < w; j++){ + dst[i][j] = 0.0; + } + } + 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} + }; + + clock_t start, end; + start = clock(); + separableGaussianBlur(src, dst, h, w, kx, ky); + end = clock(); + + printf("Blurred result:\n"); + for(i = 0; i < h; i++){ + for(j = 0; j < w; j++){ + printf("%.2f ", dst[i][j]); + } + printf("\n"); + } + printf("Time: %f s\n", (float)(end - start) / CLOCKS_PER_SEC); + return 0; +}