From 9478efbfc092603cad5851928421bef4e54b76f5 Mon Sep 17 00:00:00 2001 From: p7cx2jokr <2160925370@qq.com> Date: Sat, 30 Nov 2024 23:22:46 +0800 Subject: [PATCH] ADD file via upload --- 1.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 1.cpp diff --git a/1.cpp b/1.cpp new file mode 100644 index 0000000..839eec1 --- /dev/null +++ b/1.cpp @@ -0,0 +1,47 @@ +#include +#include +#include + +void applyGaussianBlur(float src[5][5], float dst[5][5], 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] = 0; + for (int ki = -1; ki <= 1; ki++) { + for (int kj = -1; kj <= 1; kj++) { + dst[i][j] += src[i + ki][j + kj] * kernel[1 + ki][1 + kj]; + } + } + } + } +} + +int main() { + float src[5][5] = { + {0, 0, 0, 0, 0}, + {0, 1, 2, 3, 0}, + {0, 4, 5, 6, 0}, + {0, 7, 8, 9, 0}, + {0, 0, 0, 0, 0} + }; + float dst[5][5] = {0}; + float kernel[3][3] = { + {1.0/16, 2.0/16, 1.0/16}, + {2.0/16, 4.0/16, 2.0/16}, + {1.0/16, 2.0/16, 1.0/16} + }; + + clock_t start = clock(); + applyGaussianBlur(src, dst, 5, 5, kernel); + 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"); + } + printf("步骤1运行时间:%f秒\n", (double)(end - start) / CLOCKS_PER_SEC); + + return 0; +}