forked from pi7mcrg2k/opcomplex
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.
59 lines
1.4 KiB
59 lines
1.4 KiB
#include <stdio.h>
|
|
#include <time.h>
|
|
|
|
void gaussianBlur(float src[5][5], float dst[5][5], int h, int w, float kernel[3][3]) {
|
|
int i,j, ki, kj;
|
|
for (i = 1; i < h - 1; i++) {
|
|
for (j = 1; j < w - 1; j++) {
|
|
float sum = 0.0;
|
|
for (ki = -1; ki <= 1; ki++) {
|
|
for (kj = -1; kj <= 1; kj++) {
|
|
sum += src[i + ki][j + kj] * kernel[ki + 1][kj + 1];
|
|
}
|
|
}
|
|
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 kernel[3][3] = {
|
|
{1 / 16.0, 2 / 16.0, 1 / 16.0},
|
|
{2 / 16.0, 4 / 16.0, 2 / 16.0},
|
|
{1 / 16.0, 2 / 16.0, 1 / 16.0}
|
|
};
|
|
|
|
int i, j;
|
|
float dst[5][5];
|
|
for (i = 0; i < 5; i++){
|
|
for (j = 0; j < 5; j++){
|
|
dst[i][j] = 0.0;
|
|
}
|
|
}
|
|
|
|
clock_t start, end;
|
|
start = clock();
|
|
gaussianBlur(src, dst, 5, 5, kernel);
|
|
end = clock();
|
|
double time = (double)(end - start) / CLOCKS_PER_SEC;
|
|
|
|
printf("Dst matrix:\n");
|
|
for (i = 0; i < 5; i++) {
|
|
for (j = 0; j < 5; j++) {
|
|
printf("%.2f ", dst[i][j]);
|
|
}
|
|
printf("\n");
|
|
}
|
|
|
|
printf("Time: %f s\n", time);
|
|
return 0;
|
|
}
|