|
@@ -1,9 +1,11 @@
|
|
|
#include <stdlib.h>
|
|
#include <stdlib.h>
|
|
|
#include <stdio.h>
|
|
#include <stdio.h>
|
|
|
#include <math.h>
|
|
#include <math.h>
|
|
|
-#define M_PI 3.14159265358979323846
|
|
|
|
|
#include "../tp2.h"
|
|
#include "../tp2.h"
|
|
|
|
|
+
|
|
|
|
|
+#define M_PI 3.14159265358979323846
|
|
|
#define DEBUG 0
|
|
#define DEBUG 0
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Calculo la matriz de convulsión.
|
|
* Calculo la matriz de convulsión.
|
|
|
* Hago el calculo de todos los componentes.
|
|
* Hago el calculo de todos los componentes.
|
|
@@ -13,22 +15,16 @@
|
|
|
float* convulcion_matrix(float sigma, int r) {
|
|
float* convulcion_matrix(float sigma, int r) {
|
|
|
unsigned int contador = 0;
|
|
unsigned int contador = 0;
|
|
|
unsigned int largo = 2*r + 1;
|
|
unsigned int largo = 2*r + 1;
|
|
|
- unsigned int diff = largo+ 4-(largo % 4);
|
|
|
|
|
- unsigned int tam = diff*largo;
|
|
|
|
|
- float* conv_matrix = malloc(sizeof(float)*tam);
|
|
|
|
|
|
|
+ float* conv_matrix = malloc(sizeof(float)*largo*largo);
|
|
|
|
|
|
|
|
#if DEBUG
|
|
#if DEBUG
|
|
|
printf("Sigma: %f | Radio: %d \n", sigma,r);
|
|
printf("Sigma: %f | Radio: %d \n", sigma,r);
|
|
|
#endif
|
|
#endif
|
|
|
// Recorro cada pixel
|
|
// Recorro cada pixel
|
|
|
for (int y = -r; y <= r; y++) {
|
|
for (int y = -r; y <= r; y++) {
|
|
|
- for (int x = -r; x <= r+1; x++) {
|
|
|
|
|
|
|
+ for (int x = -r; x <= r; x++) {
|
|
|
// Por cada pixel obtengo la sub-matriz de convulsion para cada componente
|
|
// Por cada pixel obtengo la sub-matriz de convulsion para cada componente
|
|
|
- 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));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ conv_matrix[contador] = (1 / (2*M_PI*sigma*sigma)) * exp(- (pow(x,2)+pow(y,2))/(2*sigma*sigma));
|
|
|
#if DEBUG
|
|
#if DEBUG
|
|
|
printf("%.8f\t", conv_matrix[contador]);
|
|
printf("%.8f\t", conv_matrix[contador]);
|
|
|
#endif
|
|
#endif
|
|
@@ -53,16 +49,12 @@ void blur_c(unsigned char *src, unsigned char *dst, int cols, int filas, float s
|
|
|
for(i=r; i<filas-r; i++) {
|
|
for(i=r; i<filas-r; i++) {
|
|
|
for(j=r; j<cols-r; j++) {
|
|
for(j=r; j<cols-r; j++) {
|
|
|
tmp[0]=0; tmp[1]=0; tmp[2]=0; matPos = 0;
|
|
tmp[0]=0; tmp[1]=0; tmp[2]=0; matPos = 0;
|
|
|
-
|
|
|
|
|
// Recorro la submatriz que le corresponde al pixel actual y hago las multiplicaciones
|
|
// Recorro la submatriz que le corresponde al pixel actual y hago las multiplicaciones
|
|
|
for(y=-r; y<=r; y++) {
|
|
for(y=-r; y<=r; y++) {
|
|
|
- for(x=-r; x<=r+1; x++) {
|
|
|
|
|
- //En C nunca veo la ultima posicion (0) de la matriz
|
|
|
|
|
- if (x<=r){
|
|
|
|
|
- tmp[0]+=src_matrix[i+y][4*(x+j)+0] * mc[matPos];
|
|
|
|
|
- tmp[1]+=src_matrix[i+y][4*(x+j)+1] * mc[matPos];
|
|
|
|
|
- tmp[2]+=src_matrix[i+y][4*(x+j)+2] * mc[matPos];
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ for(x=-r; x<=r; x++) {
|
|
|
|
|
+ tmp[0]+=src_matrix[i+y][4*(x+j)+0] * mc[matPos];
|
|
|
|
|
+ tmp[1]+=src_matrix[i+y][4*(x+j)+1] * mc[matPos];
|
|
|
|
|
+ tmp[2]+=src_matrix[i+y][4*(x+j)+2] * mc[matPos];
|
|
|
matPos++; // Aumento una posición en la matriz de convulsion
|
|
matPos++; // Aumento una posición en la matriz de convulsion
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|