Last active
March 16, 2019 14:53
-
-
Save johnnyferreiradev/26287ad56b8958370fda4ece6a5be758 to your computer and use it in GitHub Desktop.
Funções responsáveis pela criação de um filtro gaussiano de dimensões dinâmicas para processamento digital de imagens. Seu funcionamento depende de uma função para convolução de forma genérica.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void criarGaussiano(float **mascara, int largura, int altura){ | |
// adotando desvio padrão = 1,0 | |
float sigma = 1.0; | |
float r, s = 2.0 * sigma * sigma; | |
// variável para somatório | |
float soma = 0.0; | |
// delimitadores para máscara simétrica com média em (0,0) | |
int m = (largura-1)/2; | |
int n = (altura-1)/2; | |
// geração dos valores da máscara | |
for (int x = -m; x <= m; x++) { | |
for (int y = -n; y <= n; y++) { | |
r = sqrt(x * x + y * y); | |
mascara[x + m][y + n] = (exp(-(r * r) / s)) / (M_PI * s); | |
soma += mascara[x + m][y + n]; | |
} | |
} | |
// normalizando a máscara | |
for (int i = 0; i < largura; ++i) | |
for (int j = 0; j < altura; ++j) | |
mascara[i][j] /= soma; | |
} | |
Mat filtroGauss(Mat img, int x, int y){ | |
Mat processada = img.clone(); | |
// Cria dinamicamente uma matriz com as dimenções passadas por parametro | |
float **Kernel; | |
Kernel = (float**) malloc (x * sizeof(float*) ); | |
for (int i=0; i<x; i++){ | |
Kernel[i] = (float*) malloc (y * sizeof(float) ); | |
} | |
criarGaussiano(Kernel, x, y); // Atribuição de valores a mascara | |
processada = convoluirGenerica(img, Kernel, x, y); // Processamento da imagem | |
return processada; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment