Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement