예제 #1
0
파일: aan_mascara.c 프로젝트: aruiz/AAN
void
aan_mascara_imagen (float *red_input,
                    float *green_input,
                    float *blue_input,
                    float *red_output,
                    float *green_output,
                    float *blue_output,
                    int width,
                    int height,
                    float **m)
{
	aan_mascara_canal (red_input,   red_output,   width, height, m);
	aan_mascara_canal (green_input, green_output, width, height, m);
	aan_mascara_canal (blue_input,  blue_output,  width, height, m);
}
예제 #2
0
파일: practica9.c 프로젝트: groteck/perona
void calcular_gradiente(float *canal_input,float *canal_output,int width,int height){

  float masc_horizontal[3][3]= {{-(2.-sqrt(2.))/4.,0.,(2.-sqrt(2.))/4.},{-2.*(sqrt(2.)-1.)/4,0.,2.*(sqrt(2.)-1.)/4.},{-(2.-sqrt(2.))/4.,0.,(2.-sqrt(2.))/4.}};
  float masc_vertical[3][3]  = {{-(2.-sqrt(2.))/4.,-2.*(sqrt(2.)-1.)/4.,-(2.-sqrt(2.))/4.},{0.,0.,0.},{(2.-sqrt(2.))/4.,2.*(sqrt(2.)-1.)/4.,(2.-sqrt(2.))/4.}};
  float *h,*v;
  int i;

  h = (float*)malloc((width*height)*sizeof(float));
  v = (float*)malloc((width*height)*sizeof(float));

  aan_mascara_canal(canal_input,h,width,height,masc_horizontal);
  aan_mascara_canal(canal_input,v,width,height,masc_vertical);

  for(i=0;i<(height*width);i++){
    canal_output[i]= sqrt((h[i]*h[i])+(v[i]*v[i]));
  };

  free(h);
  free(v);
}
예제 #3
0
파일: aan_propagacion.c 프로젝트: aruiz/AAN
/* Utilizamos una mascara laplaciana como aproximacion al modulo del gradiente */
float*
grad_horizontal (float *input, int width, int height)
{
	float  *grad;
	float **u_x;

	grad = (float*)malloc (sizeof(float) * width * height);
	ami_malloc2d (u_x, float, 3, 3);

	u_x[0][0] = 0.25 * -(2.0 - sqrt(2.0));     u_x[0][1] = 0; u_x[0][2] = 0.25 * (2.0 - sqrt(2.0));
	u_x[1][0] = 0.25 * -2.0 * (sqrt(2.0) - 1); u_x[1][1] = 0; u_x[1][2] = 0.25 * 2.0 * (sqrt(2.0) - 1);
	u_x[2][0] = 0.25 * -(2.0 - sqrt(2.0));     u_x[2][1] = 0; u_x[2][2] = 0.25 * (2.0 - sqrt(2.0));

/*	u_x[0][0] = -3.0;     u_x[0][1] = 0; u_x[0][2] = 3.0;
	u_x[1][0] = -10.0;     u_x[1][1] = 0; u_x[1][2] = 10.0;
	u_x[2][0] = -3.0;     u_x[2][1] = 0; u_x[2][2] = 3.0;*/

	aan_mascara_canal (input, grad, width, height, u_x);

	ami_free2d(u_x);
	return grad;
}
예제 #4
0
파일: 2_mascara_byn.c 프로젝트: aruiz/AAN
int
main (int argc, char **argv)
{
	int i, w, h;
	unsigned char *red1, *green1, *blue1,
	              *red2, *green2, *blue2,
	              *red3, *green3, *blue3;
	              
	float         *fred1, *fgreen1, *fblue1,
	              *fred2, *fgreen2, *fblue2;
	
	float **u_x, **u_y, **lap;

	if (argc < 2)
	{
		fprintf (stderr, "Usage: %s <BMP file>\n", argv[0]);
		return -1;
	}
	/* Leemos el fichero dado por el primer argumento */	
	if (ami_read_bmp (argv[1], &red1, &green1, &blue1, &w, &h) < 0)
		return -1;
	
	ami_malloc2d (u_x, float, 3, 3);
	ami_malloc2d (u_y, float, 3, 3);
	ami_malloc2d (lap, float, 3, 3);

	/* Gradiente horizontal */
	u_x[0][0] = 0.25 * -(2.0 - sqrt(2.0));     u_x[0][1] = 0; u_x[0][2] = 0.25 * (2.0 - sqrt(2.0));
	u_x[1][0] = 0.25 * -2.0 * (sqrt(2.0) - 1); u_x[1][1] = 0; u_x[1][2] = 0.25 * 2.0 * (sqrt(2.0) - 1);
	u_x[2][0] = 0.25 * -(2.0 - sqrt(2.0));     u_x[2][1] = 0; u_x[2][2] = 0.25 * (2.0 - sqrt(2.0));
	
	/* Gradiente vertical */
	u_y[0][0] = 0.25 * -(2.0 - sqrt(2.0)); u_y[0][1] = 0.25 * -2.0 * (sqrt(2.0) - 1); u_y[0][2] = 0.25 * -(2.0-sqrt(2.0));
	u_y[1][0] = 0;                         u_y[1][1] = 0;                             u_y[1][2] = 0;
	u_y[2][0] = 0.25 *  (2.0 - sqrt(2.0)); u_y[2][1] = 0.25 *  2.0 * (sqrt(2.0) - 1); u_y[2][2] = 0.25 *  (2.0 - sqrt(2.0));
	
	/* Pasamos los canales a precision flotante */
	fred1   = uchar_to_float (red1,   w * h);
	fgreen1 = uchar_to_float (green1, w * h);
	fblue1  = uchar_to_float (blue1,  w * h);

	aan_normalizar_imagen_float (fred1, fgreen1, fblue1, w , h);
	
	fred2   = (float*) malloc (sizeof (float) * w * h);
	fgreen2 = (float*) malloc (sizeof (float) * w * h);
	fblue2  = (float*) malloc (sizeof (float) * w * h);
	
	/* Usamos el gradiente horizontal en el canal verde */
	aan_mascara_canal (fgreen1, fgreen2, w, h, u_x);
	aan_mascara_canal (fred1, fred2, w, h, u_y);
	for (i=0; i < (w * h) ;i++)
		fblue2[i] = 127.0;

	red2   = float_to_uchar (fred2,   w * h);
	green2 = float_to_uchar (fgreen2, w * h);
	blue2  = float_to_uchar (fblue2,  w * h);
	
	aan_normalizar_imagen_float (fred2, fgreen2, fblue2, w , h);
	
	aan_unir_canales_unsigned_char (red1,   red2,   &red3,   w, h);
	aan_unir_canales_unsigned_char (green1, green2, &green3, w, h);
	aan_unir_canales_unsigned_char (blue1,  blue2,  &blue3,  w, h);
	
	ami_write_bmp ("./2_mascara_byn.bmp", red3, green3, blue3, w*2 + 4, h);

	/* Liberamos memoria */
	free (red2); free (green2); free (blue2);
	free (red3); free (green3); free (blue3);

	free (red1); free (green1); free (blue1);
	free (fred1); free (fgreen1); free (fblue1);
	free (fred2); free (fgreen2); free (fblue2);
	ami_free2d (u_x); ami_free2d (u_y);
	return 0;
}