Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. void criarGaussiano(float **mascara, int largura, int altura){
  2. // adotando desvio padrão = 1,0
  3. float sigma = 1.0;
  4. float r, s = 2.0 * sigma * sigma;
  5.  
  6. // variável para somatório
  7. float soma = 0.0;
  8.  
  9. // delimitadores para máscara simétrica com média em (0,0)
  10. int m = (largura-1)/2;
  11. int n = (altura-1)/2;
  12.  
  13. // geração dos valores da máscara
  14. for (int x = -m; x <= m; x++) {
  15. for (int y = -n; y <= n; y++) {
  16. r = sqrt(x * x + y * y);
  17. mascara[x + m][y + n] = (exp(-(r * r) / s)) / (M_PI * s);
  18. soma += mascara[x + m][y + n];
  19. }
  20. }
  21.  
  22. // normalizando a máscara
  23. for (int i = 0; i < largura; ++i)
  24. for (int j = 0; j < altura; ++j)
  25. mascara[i][j] /= soma;
  26. }
  27.  
  28. Mat filtroGauss(Mat img, int x, int y){
  29. Mat processada = img.clone();
  30.  
  31. // Cria dinamicamente uma matriz com as dimenções passadas por parametro
  32. float **Kernel;
  33. Kernel = (float**) malloc (x * sizeof(float*) );
  34. for (int i=0; i<x; i++){
  35. Kernel[i] = (float*) malloc (y * sizeof(float) );
  36. }
  37.  
  38. criarGaussiano(Kernel, x, y); // Atribuição de valores a mascara
  39. processada = convoluirGenerica(img, Kernel, x, y); // Processamento da imagem
  40.  
  41. return processada;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement