|
|
@@ -4,47 +4,62 @@
|
|
|
#define M_PI 3.14159265358979323846
|
|
|
#include "../tp2.h"
|
|
|
|
|
|
-void blur_c (
|
|
|
- unsigned char *src,
|
|
|
- unsigned char *dst,
|
|
|
- int cols,
|
|
|
- int filas,
|
|
|
- float sigma,
|
|
|
- int r)
|
|
|
-{
|
|
|
- unsigned char (*src_matrix)[cols*4] = (unsigned char (*)[cols*4]) src;
|
|
|
- unsigned char (*dst_matrix)[cols*4] = (unsigned char (*)[cols*4]) dst;
|
|
|
|
|
|
- unsigned int i,j=0,x,y;
|
|
|
- float tmp[3];
|
|
|
-
|
|
|
- float val;
|
|
|
- float *mc=malloc(sizeof(float)*40*r*r);
|
|
|
-
|
|
|
- printf("r: %d, plsgiv %d\n", r, sizeof(float)*r*r);
|
|
|
- unsigned int indice_de_mierda=0;
|
|
|
- for(y=-r;y<r;y++) {
|
|
|
- for(x=-r;x<r;x++){
|
|
|
- val=(1/(2*M_PI*sigma*sigma) * exp(- ((x*x)+(y*y))/(2*sigma*sigma)));
|
|
|
- mc[indice_de_mierda]= val;
|
|
|
- indice_de_mierda++;
|
|
|
+float gauss(float sigma, int x, int y) {
|
|
|
+ return (1 / (2*M_PI*sigma*sigma)) * exp(- ((x*x)+(y*y))/2*sigma*sigma);
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+* Calculo la matriz de convulsión.
|
|
|
+* Hago el calculo de todos los componentes.
|
|
|
+* PRE: Esto asume que existen "r" pixeles para cada lado del pixel actual para hacer la cuenta
|
|
|
++ TODO: Hay que hacer free de la matriz
|
|
|
+*/
|
|
|
+float* convulcion_matrix(float sigma, int r) {
|
|
|
+ unsigned int contador = 0;
|
|
|
+ unsigned int largo = 2*r + 1;
|
|
|
+ float* conv_matrix = malloc(sizeof(float)*largo);
|
|
|
+
|
|
|
+ // Recorro cada pixel
|
|
|
+ for (int y = 1; y <= largo; y++) {
|
|
|
+ for (int x = 1; x <= largo; x++) {
|
|
|
+ // Por cada pixel obtengo la sub-matriz de convulsion para cada componente
|
|
|
+ conv_matrix[contador] = gauss(sigma, r - x, r - y); // B
|
|
|
+ contador++;
|
|
|
+ printf("Sigma: %f | Radio: %d | X: %d | Y: %d | Gauss: %f \n", sigma, r, x, y, gauss(sigma, r-x,r-y));
|
|
|
}
|
|
|
}
|
|
|
+ return conv_matrix;
|
|
|
+}
|
|
|
|
|
|
- for(i=r;i<filas-r-1;i++){ //
|
|
|
- for(j=r;j<cols-r;j++) { //ignoro los bordes de tamaño R
|
|
|
|
|
|
+void blur_c(unsigned char *src, unsigned char *dst, int cols, int filas, float sigma, int r) {
|
|
|
+ unsigned char (*src_matrix)[cols*4] = (unsigned char (*)[cols*4]) src;
|
|
|
+ unsigned char (*dst_matrix)[cols*4] = (unsigned char (*)[cols*4]) dst;
|
|
|
+
|
|
|
+ float tmp[3];
|
|
|
+ int i,j=0,x,y;
|
|
|
+ float* mc = convulcion_matrix(sigma, r);
|
|
|
+
|
|
|
+ for(i=r;i<filas-r;i++) {
|
|
|
+ for(j=r;j<cols-r;j++) { // Ignoro los bordes de tamaño R
|
|
|
tmp[0]=0;
|
|
|
tmp[1]=0;
|
|
|
tmp[2]=0;
|
|
|
- for(y=0;y<2*r;y++){
|
|
|
- for(x=0;x<2*r;x++){
|
|
|
- tmp[0]+=src_matrix[i+y][4*(x+j)+0]*mc[x+(r*y*2)];
|
|
|
- tmp[1]+=src_matrix[i+y][4*(x+j)+1]*mc[x+(r*y*2)];
|
|
|
- tmp[2]+=src_matrix[i+y][4*(x+j)+2]*mc[x+(r*y*2)];
|
|
|
+ for(y=-r;y<=r;y++){
|
|
|
+ for(x=-r;x<=r;x++){
|
|
|
+ int img=src_matrix[i+y][4*(x+j)+0];
|
|
|
+ int mat_pos=x+(r+y+2);
|
|
|
+ float mat=mc[mat_pos];
|
|
|
+ float val= img * mat;
|
|
|
+// tmp[0]+=src_matrix[i+y][4*(x+j)+0]*mc[x+(r*y*2)];
|
|
|
+ tmp[0]+=src_matrix[i+y][4*(x+j)+0] * mat;
|
|
|
+ tmp[1]+=src_matrix[i+y][4*(x+j)+1] * mat;
|
|
|
+ tmp[2]+=src_matrix[i+y][4*(x+j)+2] * mat;
|
|
|
+ printf("IMG: %d | MATPOS: %d | MATVAL: %f| VAL: %f | TMP[0] %f\n", img, mat_pos, mat, val, tmp[0]);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ exit(0);
|
|
|
printf("%f\n",tmp[0]);
|
|
|
dst_matrix[i][4*j+0]=(int)tmp[0];
|
|
|
dst_matrix[i][4*j+1]=(int)tmp[1];
|