Kaynağa Gözat

matriz mentirosa

David 11 yıl önce
ebeveyn
işleme
0adfecb965
1 değiştirilmiş dosya ile 16 ekleme ve 8 silme
  1. 16 8
      filtros/blur_c.c

+ 16 - 8
filtros/blur_c.c

@@ -3,7 +3,7 @@
 #include <math.h>
 #define M_PI 3.14159265358979323846
 #include "../tp2.h"
-
+#define DEBUG 0
 /**
 *	Calculo la matriz de convulsión.
 *	Hago el calculo de todos los componentes.
@@ -13,19 +13,27 @@
 float* convulcion_matrix(float sigma, int r) {
 	unsigned int contador = 0;
 	unsigned int largo = 2*r + 1;
-	float* conv_matrix = malloc(sizeof(float)*largo*largo);
+	unsigned int diff = largo+ 4-(largo % 4);
+	unsigned int tam = diff*largo;
+	float* conv_matrix = malloc(sizeof(float)*tam);
 
-	printf("Sigma: %f | Radio: %d \n", sigma,r);
-	//printf("| X: %d | Y: %d | Gauss: %f \n", sigma, r, x, y, (1 / (2*M_PI*sigma*sigma)) * exp(- (pow(x,2)+pow(y,2))/(2*sigma*sigma)));
+	if (DEBUG)
+		printf("Sigma: %f | Radio: %d \n", sigma,r);
 	// Recorro cada pixel
 	for (int y = -r; y <= r; y++) {
-		for (int x = -r; x <= r; x++) {
+		for (int x = -r; x <= r+1; x++) {
 			// Por cada pixel obtengo la sub-matriz de convulsion para cada componente
-			printf("%.8f\t",(1 / (2*M_PI*sigma*sigma)) * exp(- (pow(x,2)+pow(y,2))/(2*sigma*sigma)));
-			conv_matrix[contador] = (1 / (2*M_PI*sigma*sigma)) * exp(- (pow(x,2)+pow(y,2))/(2*sigma*sigma));
+			if (x==r+1) { //Con esta idea, la matriz siempre tiene mult de 4 columnas, son todas 0 entonces no me afecta
+				conv_matrix[contador] = 0;
+			} else {
+				conv_matrix[contador] = (1 / (2*M_PI*sigma*sigma)) * exp(- (pow(x,2)+pow(y,2))/(2*sigma*sigma));
+			}
+			if (DEBUG)
+				printf("%.8f\t", conv_matrix[contador]);
 			contador++;
 		}
-		printf("\n");
+		if (DEBUG)
+			printf("\n");
 	}
 	return conv_matrix;
 }