parent
c153a39530
commit
0a261b8e5b
@ -0,0 +1,42 @@
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
float inputImage[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 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}
|
||||
};
|
||||
|
||||
void applyGaussianBlur(float src[][5], int w, int h, float dst[][5], float kernel[][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 outputImage[5][5] = { 0 };
|
||||
clock_t start, end;
|
||||
start = clock();
|
||||
applyGaussianBlur(inputImage, 5, 5, outputImage, kernel);
|
||||
end = clock();
|
||||
double timeSpent = (double)(end - start) / CLOCKS_PER_SEC;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
printf("%-4.1f ", outputImage[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("The timeSpent is %1.32f second\n", timeSpent);
|
||||
}
|
Loading…
Reference in new issue