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.
64 lines
1.6 KiB
64 lines
1.6 KiB
#include <stdio.h>
|
|
#include <time.h>
|
|
|
|
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;
|
|
}
|