Ejemplo n.º 1
0
main(int argc, char **argv)
{
  GrayImage gim;
  
  if(argc != 3)
    error("main: wrong command line architecture");
  
  /* read PGM image */  
  read_pgm_image(&gim, argv[1]);
  write_pbm_image(&gim, argv[2]);
}
Ejemplo n.º 2
0
main(int argc, char *argv[])
{
   char *infilename = NULL;  /* Name of the input image */
   char *dirfilename = NULL; /* Name of the output gradient direction image */
   char outfilename[128];    /* Name of the output "edge" image */
   char composedfname[128];  /* Name of the output "direction" image */
   unsigned char *image;     /* The input image */
   unsigned char *edge;      /* The output edge image */
   int rows, cols;           /* The dimensions of the image. */
   float sigma,              /* Standard deviation of the gaussian kernel. */
	 tlow,               /* Fraction of the high threshold in hysteresis. */
	 thigh;              /* High hysteresis threshold control. The actual
			        threshold is the (100 * thigh) percentage point
			        in the histogram of the magnitude of the
			        gradient image that passes non-maximal
			        suppression. */

   /****************************************************************************
   * Get the command line arguments.
   ****************************************************************************/
   if(argc < 5){
   fprintf(stderr,"\n<USAGE> %s image sigma tlow thigh [writedirim]\n",argv[0]);
      fprintf(stderr,"\n      image:      An image to process. Must be in ");
      fprintf(stderr,"PGM format.\n");
      fprintf(stderr,"      sigma:      Standard deviation of the gaussian");
      fprintf(stderr," blur kernel.\n");
      fprintf(stderr,"      tlow:       Fraction (0.0-1.0) of the high ");
      fprintf(stderr,"edge strength threshold.\n");
      fprintf(stderr,"      thigh:      Fraction (0.0-1.0) of the distribution");
      fprintf(stderr," of non-zero edge\n                  strengths for ");
      fprintf(stderr,"hysteresis. The fraction is used to compute\n");
      fprintf(stderr,"                  the high edge strength threshold.\n");
      fprintf(stderr,"      writedirim: Optional argument to output ");
      fprintf(stderr,"a floating point");
      fprintf(stderr," direction image.\n\n");
      exit(1);
   }

   infilename = argv[1];
   sigma = atof(argv[2]);
   tlow = atof(argv[3]);
   thigh = atof(argv[4]);

   if(argc == 6) dirfilename = infilename;
   else dirfilename = NULL;

   /****************************************************************************
   * Read in the image. This read function allocates memory for the image.
   ****************************************************************************/
   if(VERBOSE) printf("Reading the image %s.\n", infilename);
   if(read_pgm_image(infilename, &image, &rows, &cols) == 0){
      fprintf(stderr, "Error reading the input image, %s.\n", infilename);
      exit(1);
   }

   /****************************************************************************
   * Perform the edge detection. All of the work takes place here.
   ****************************************************************************/
   if(VERBOSE) printf("Starting Canny edge detection.\n");
   if(dirfilename != NULL){
      sprintf(composedfname, "%s_s_%3.2f_l_%3.2f_h_%3.2f.fim", infilename,
      sigma, tlow, thigh);
      dirfilename = composedfname;
   }
   canny(image, rows, cols, sigma, tlow, thigh, &edge, dirfilename);

   /****************************************************************************
   * Write out the edge image to a file.
   ****************************************************************************/
   sprintf(outfilename, "%s_s_%3.2f_l_%3.2f_h_%3.2f.pgm", infilename,
      sigma, tlow, thigh);
   if(VERBOSE) printf("Writing the edge iname in the file %s.\n", outfilename);
   if(write_pgm_image(outfilename, edge, rows, cols, "", 255) == 0){
      fprintf(stderr, "Error writing the edge image, %s.\n", outfilename);
      exit(1);
   }
   
}
int main (int argc, char* argv[])
{
	int maxgv;
	char * console_string = (char*)calloc(3000,sizeof(char));
	lastclickx=lastclicky=-1;
	active_param='\0';
	num_images_side_by_side=2;
	int no_frontend;
	parse_arg_int   (argc,argv,"bordersizex",&bx,2,console_string);
	parse_arg_int   (argc,argv,"bordersizey",&by,2,console_string);
	parse_arg_float (argc,argv,"alpha",&alpha,100,console_string);
	parse_arg_float (argc,argv,"epsilon_d",&epsilon_d,0.01f,console_string);
	parse_arg_int   (argc,argv,"diffusivity_type_d",&diffusivity_type_d,0,console_string);
	parse_arg_int   (argc,argv,"iterations_inner",&num_iterations_inner,30,console_string);
	parse_arg_int   (argc,argv,"iterations_outer",&num_iterations_outer,5,console_string);
	parse_arg_float (argc,argv,"omega",&omega,1.9f,console_string);
	parse_arg_float (argc,argv,"eta",&warp_eta,0.5f,console_string);
	parse_arg_int   (argc,argv,"max_warp_levels",&max_warp_levels,200,console_string);
	parse_arg_float (argc,argv,"max_displacement",&max_displacement,5.0f,console_string);
	parse_arg_string(argc,argv,"basename",basename,"../images/yos",console_string);
	parse_arg_int   (argc,argv,"no_frontend",&no_frontend,0,console_string);
	char filename[200];
	printf("------\n%s---------\n",console_string);
	
	sprintf(filename,"%s1.pgm",basename);
	f1 = read_pgm_image(filename,&nx,&ny,bx,by,&maxgv);
	
	sprintf(filename,"%s2.pgm",basename);
	f2 = read_pgm_image(filename,&nx,&ny,bx,by,&maxgv);
        
	//printf("f1[100][150] =%f\n",f1[100][150]);
	//printf("f1[150][20] =%f\n",f1[150][20]);
	calloc_multi(1,3,sizeof(float),3,nx,ny,0,bx,by,0,0,0,&of_rgb);
	calloc_multi(4,2,sizeof(float),nx,ny,bx,by,0,0,&u,&v,&u_truth,&v_truth);
	calloc_multi(1,3,sizeof(uchar),num_images_side_by_side*nx,ny,
				 3, 0,0,0, 0,0,0, &p6);
//		printf("f1[150][20] =%f\n",f1[150][20]);
	sprintf(filename,"%st.F",basename);
	read_barron_data(filename,u_truth,v_truth,nx,ny,bx,by);//------------------------------uncomment for computing errors.!!!!!!!!!!!!!!!!!!!!

/*	rewrite the barron file to txt file	*/
//	FILE* UT;
//	FILE* VT;
//	int i,j;
//	UT = fopen("utruth.txt","w");
//	VT = fopen("vtruth.txt","w");
//	for(i = bx; i <nx+bx; i++){
//		for(j = by; j < by+ny; j++)
//		{
//			fprintf(UT,"%f\t",u_truth[i][j]);
//			fprintf(VT,"%f\t",v_truth[i][j]);
//		}
//		fprintf(UT,"\n");
//		fprintf(VT,"\n");
//	}
//	fclose(UT);
//	fclose(VT);

	if(!no_frontend)
	{
		glutInit(&argc, argv);
		glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);

		glutInitWindowSize(num_images_side_by_side*nx,ny);
		glutCreateWindow("Frontend Skeleton");

		glutDisplayFunc(handleDraw);
		glutKeyboardFunc(handleKeyboard);
		glutSpecialFunc(handleKeyboardspecial);
		glutMouseFunc(handleMouse);
		glutReshapeFunc(ReSizeGLScene);

		glEnable(GL_TEXTURE_2D);
		glGenTextures(1, &gl_rgb_tex);
		glBindTexture(GL_TEXTURE_2D, gl_rgb_tex);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		if(ny%4) glPixelStorei(GL_UNPACK_ALIGNMENT, 1) ;
		compute();
		showParams();
		glutMainLoop();
	}
	else
	{
		compute();
		showParams();
	}

	return(0);
}
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{
    char *infilename = NULL;  /* Name of the input image */
    char *dirfilename = NULL; /* Name of the output gradient direction image */
    char outfilename[128];    /* Name of the output "edge" image */
    char composedfname[128];  /* Name of the output "direction" image */
    unsigned char *image;     /* The input image */
    unsigned char *edge;      /* The output edge image */
    int rows, cols;           /* The dimensions of the image. */
    float sigma=2.5,              /* Standard deviation of the gaussian kernel. */
          tlow=0.5,               /* Fraction of the high threshold in hysteresis. */
          thigh=0.5;              /* High hysteresis threshold control. The actual
			        threshold is the (100 * thigh) percentage point
			        in the histogram of the magnitude of the
			        gradient image that passes non-maximal
			        suppression. */

    /****************************************************************************
    * Get the command line arguments.
    ****************************************************************************/
    if(argc < 2)
    {
        fprintf(stderr,"\n<USAGE> %s image sigma tlow thigh [writedirim]\n",argv[0]);
        fprintf(stderr,"\n      image:      An image to process. Must be in ");
        fprintf(stderr,"PGM format.\n");
        exit(1);
    }

    infilename = argv[1];

    Timer totalTime;
    initTimer(&totalTime, "Total Time");

    /****************************************************************************
    * Read in the image. This read function allocates memory for the image.
    ****************************************************************************/
    if(VERBOSE) printf("Reading the image %s.\n", infilename);
    if(read_pgm_image(infilename, &image, &rows, &cols) == 0)
    {
        fprintf(stderr, "Error reading the input image, %s.\n", infilename);
        exit(1);
    }

    /****************************************************************************
    * Perform the edge detection. All of the work takes place here.
    ****************************************************************************/
    if(VERBOSE) printf("Starting Canny edge detection.\n");
    if(dirfilename != NULL)
    {
        sprintf(composedfname, "%s_s_%3.2f_l_%3.2f_h_%3.2f.fim", infilename,
                sigma, tlow, thigh);
        dirfilename = composedfname;
    }

    
 //   MCPROF_START();
    canny(image, rows, cols, sigma, tlow, thigh, &edge, dirfilename);
   // MCPROF_STOP();
    
    


    /****************************************************************************
    * Write out the edge image to a file.
    ****************************************************************************/
    sprintf(outfilename, "%s_s_%3.2f_l_%3.2f_h_%3.2f.pgm", infilename,
            sigma, tlow, thigh);
    if(VERBOSE) printf("Writing the edge iname in the file %s.\n", outfilename);
    if(write_pgm_image(outfilename, edge, rows, cols, "", 255) == 0)
    {
        fprintf(stderr, "Error writing the edge image, %s.\n", outfilename);
        exit(1);
    }

    free(image);
    free(edge);
    return 0;
}