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.
39 lines
1.2 KiB
39 lines
1.2 KiB
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <time.h>
|
|
#include <string.h>
|
|
#include "render.h"
|
|
#define IDX(n) ((n) % 3)
|
|
|
|
void applySeparableGaussianBlur(float[][MAT_SIZE], float[][MAT_SIZE], float[3], float[3]);
|
|
int main() {
|
|
float inputImage[MAT_SIZE][MAT_SIZE];
|
|
Render(inputImage);
|
|
|
|
float kx[3] = {1.0f/4, 1.0f/2, 1.0f/4};
|
|
float ky[3] = {1.0f/4, 1.0f/2, 1.0f/4};
|
|
float outputImage[MAT_SIZE][MAT_SIZE] = {0};
|
|
clock_t start = clock();
|
|
applySeparableGaussianBlur(inputImage, outputImage, kx, ky);
|
|
clock_t end = clock();
|
|
printf("Time: %lf s\n", (double)(end-start) / CLOCKS_PER_SEC);
|
|
Print(outputImage);
|
|
}
|
|
|
|
void applySeparableGaussianBlur(float src[][MAT_SIZE], float dst[][MAT_SIZE], float kx[3], float ky[3]) {
|
|
float buf[3][MAT_SIZE+3];
|
|
int i, j;
|
|
// 计算前两行的行内卷积
|
|
for(i=0; i<2; i++)
|
|
for(j=1; j<MAT_SIZE-1; j++) {
|
|
buf[i][j] = src[i][j-1]*kx[0]+src[i][j]*kx[1]+src[i][j+1]*kx[2];
|
|
}
|
|
// 利用buf进行累计
|
|
for(i=1; i<MAT_SIZE-1; i++) {
|
|
for(j=1; j<MAT_SIZE-1; j++)
|
|
buf[IDX(i+1)][j] = src[i+1][j-1]*kx[0]+src[i+1][j]*kx[1]+src[i+1][j+1]*kx[2];
|
|
for(j=1; j<MAT_SIZE-1; j++)
|
|
dst[i][j] = buf[IDX(i-1)][j]*ky[0]+buf[IDX(i)][j]*ky[1]+buf[IDX(i+1)][j]*ky[2];
|
|
}
|
|
}
|