Beispiel #1
0
int main(int argc, char **argv){
    if( argc<6){
        if(argc>1) fprintf(stderr,"Error, not enough arguments\n");
        usage();
        exit(1);
    }

    // read arguments
    color_image_t *im1 = color_image_load(argv[1]);
    color_image_t *im2 = color_image_load(argv[2]);
    float_image edges = read_edges(argv[3], im1->width, im1->height);
    float_image matches = read_matches(argv[4]);
    const char *outputfile = argv[5];

    // prepare variables
    epic_params_t epic_params;
    epic_params_default(&epic_params);
    variational_params_t flow_params;
    variational_params_default(&flow_params);
    image_t *wx = image_new(im1->width, im1->height), *wy = image_new(im1->width, im1->height);
    
    // read optional arguments 
    #define isarg(key)  !strcmp(a,key)
    int current_arg = 6;
    while(current_arg < argc ){
        const char* a = argv[current_arg++];
        if( isarg("-h") || isarg("-help") ) 
            usage();
        else if( isarg("-nw") ) 
            strcpy(epic_params.method, "NW");
        else if( isarg("-p") || isarg("-prefnn") ) 
            epic_params.pref_nn = atoi(argv[current_arg++]);
        else if( isarg("-n") || isarg("-nn") ) 
            epic_params.nn = atoi(argv[current_arg++]); 
        else if( isarg("-k") ) 
            epic_params.coef_kernel = atof(argv[current_arg++]);
        else if( isarg("-i") || isarg("-iter") ) 
            flow_params.niter_outer = atoi(argv[current_arg++]); 
        else if( isarg("-a") || isarg("-alpha") ) 
            flow_params.alpha= atof(argv[current_arg++]);  
        else if( isarg("-g") || isarg("-gamma") ) 
            flow_params.gamma= atof(argv[current_arg++]);                                  
        else if( isarg("-d") || isarg("-delta") ) 
            flow_params.delta= atof(argv[current_arg++]);  
        else if( isarg("-s") || isarg("-sigma") ) 
            flow_params.sigma= atof(argv[current_arg++]); 
        else if( isarg("-sintel") ){ 
            epic_params.pref_nn= 25; 
            epic_params.nn= 160; 
            epic_params.coef_kernel = 1.1f; 
            flow_params.niter_outer = 5;
            flow_params.alpha = 1.0f;
            flow_params.gamma = 0.72f;
            flow_params.delta = 0.0f;
            flow_params.sigma = 1.1f;            
        }  
        else if( isarg("-kitti") ){ 
            epic_params.pref_nn= 25; 
            epic_params.nn= 160; 
            epic_params.coef_kernel = 1.1f;
            flow_params.niter_outer = 2;
            flow_params.alpha = 1.0f;
            flow_params.gamma = 0.77f;
            flow_params.delta = 0.0f;
            flow_params.sigma = 1.7f; 
        }
        else if( isarg("-middlebury") ){ 
            epic_params.pref_nn= 15; 
            epic_params.nn= 65; 
            epic_params.coef_kernel = 0.2f;       
            flow_params.niter_outer = 25;
            flow_params.alpha = 1.0f;
            flow_params.gamma = 0.72f;
            flow_params.delta = 0.0f;
            flow_params.sigma = 1.1f;  
        }
        else{
            fprintf(stderr, "unknown argument %s", a);
            usage();
            exit(1);
        }   
    }
    
    // compute interpolation and energy minimization
    color_image_t *imlab = rgb_to_lab(im1);
    epic(wx, wy, imlab, &matches, &edges, &epic_params, 1);
    // energy minimization
    variational(wx, wy, im1, im2, &flow_params);
    // write output file and free memory
    writeFlowFile(outputfile, wx, wy);
    
    color_image_delete(im1);
    color_image_delete(imlab);
    color_image_delete(im2);
    free(matches.pixels);
    free(edges.pixels);
    image_delete(wx);
    image_delete(wy);

    return 0;
}
Beispiel #2
0
int main(int argc, char *argv[]){
  int     n_search;
  int     i_halo;
  char    filename_SSimPL_root[MAX_FILENAME_LENGTH];
  char    filename_in[MAX_FILENAME_LENGTH];
  char    group_text_prefix[4];
  int     n_files;
  int     k_read;
  int     max_n_groups;
  int     l_read;
  int     n_groups;
  int     j_read;
  int     mode;
  int     n_groups_i;
  int     n_groups_j;
  int     j_halo;
  int     match;
  int     i_read;
  int     i_read_start;
  int     i_read_stop;
  SID_fp  fp_in;

  SID_init(&argc,&argv,NULL,NULL);

  // Fetch user inputs
  strcpy(filename_SSimPL_root,argv[1]);
  if(!strcmp(argv[2],"groups") || !strcmp(argv[2],"group"))
     mode=MATCH_GROUPS;
  else if(!strcmp(argv[2],"subgroups") || !strcmp(argv[2],"subgroup"))
     mode=MATCH_SUBGROUPS;
  else{
     SID_log("Invalid mode selection {%s}.  Should be 'group' or 'subgroup'.",SID_LOG_COMMENT,argv[2]);
     SID_exit(ERROR_SYNTAX);
  }
  i_read=atoi(argv[3]);
  j_read=atoi(argv[4]);
  SID_log("Searching match information for halo #%d in file #%d of {%s}...",SID_LOG_OPEN|SID_LOG_TIMER,i_halo,i_read,filename_SSimPL_root);

  // Convert filename_root to filename
  switch(mode){
     case MATCH_SUBGROUPS:
     sprintf(group_text_prefix,"sub");
     break;
     case MATCH_GROUPS:
     sprintf(group_text_prefix,"");
     break;
  }

  // Set the standard SSiMPL match file path
  char filename_root_in[MAX_FILENAME_LENGTH];
  sprintf(filename_root_in,"%s/trees/matches/",filename_SSimPL_root);

  // Set the output file
  char filename_base[MAX_FILENAME_LENGTH];
  char filename_out[MAX_FILENAME_LENGTH];
  sprintf(filename_base,filename_SSimPL_root);
  if(!strcmp(&(filename_base[strlen(filename_base)-1]),"/"))
     strcpy(&(filename_base[strlen(filename_base)-1]),"\0");
  strip_path(filename_base);
  sprintf(filename_out,"%s_%d_%d_2way_matches.txt",filename_base,i_read,j_read);

  // Read header information
  SID_log("Reading header information...",SID_LOG_OPEN);
  sprintf(filename_in,"%s/%sgroup_matches_header.dat",filename_root_in,group_text_prefix);
  SID_fopen(filename_in,"r",&fp_in);
  SID_fread(&i_read_start,sizeof(int),1,&fp_in);SID_log("snap start  =%d",SID_LOG_COMMENT,i_read_start);
  SID_fread(&i_read_stop, sizeof(int),1,&fp_in);SID_log("snap stop   =%d",SID_LOG_COMMENT,i_read_stop);
  SID_fread(&n_search,    sizeof(int),1,&fp_in);SID_log("search range=%d",SID_LOG_COMMENT,n_search);
  SID_fread(&n_files,     sizeof(int),1,&fp_in);SID_log("# of files  =%d",SID_LOG_COMMENT,n_files);
  for(k_read=0,max_n_groups=0;k_read<n_files;k_read++){
     SID_fread(&l_read,  sizeof(int),1,&fp_in);
     SID_fread(&n_groups,sizeof(int),1,&fp_in);
     SID_fseek(&fp_in,   sizeof(int),n_groups,SID_SEEK_CUR);
     if(mode==MATCH_GROUPS)
        SID_fseek(&fp_in,   sizeof(int),n_groups,SID_SEEK_CUR);
     max_n_groups=MAX(max_n_groups,n_groups);
  }
  SID_log("Max # groups=%d",SID_LOG_COMMENT,max_n_groups);
  SID_fclose(&fp_in);
  SID_log("Done.",SID_LOG_CLOSE);

  // Initialize some arrays
  int    *n_particles_i       =(int    *)SID_malloc(sizeof(int)   *max_n_groups);
  int    *n_particles_j       =(int    *)SID_malloc(sizeof(int)   *max_n_groups);
  int    *match_forward_ids   =(int    *)SID_malloc(sizeof(int)   *max_n_groups);
  size_t *match_forward_index =(size_t *)SID_malloc(sizeof(size_t)*max_n_groups);
  float  *match_forward_score =(float  *)SID_malloc(sizeof(float) *max_n_groups);
  char   *match_forward_2way  =(char   *)SID_malloc(sizeof(char)  *max_n_groups);
  int    *match_backward_ids  =(int    *)SID_malloc(sizeof(int)   *max_n_groups);
  size_t *match_backward_index=(size_t *)SID_malloc(sizeof(size_t)*max_n_groups);
  float  *match_backward_score=(float  *)SID_malloc(sizeof(float) *max_n_groups);
  char   *match_backward_2way =(char   *)SID_malloc(sizeof(char)  *max_n_groups);

  // Loop over all matching combinations
  SID_log("Reading forward matches...",SID_LOG_OPEN|SID_LOG_TIMER);
  SID_set_verbosity(SID_SET_VERBOSITY_DEFAULT);
  read_matches(filename_root_in,
               i_read,
               j_read,
               max_n_groups,
               mode,
               &n_groups_i,
               &n_groups_j,
               n_particles_i,
               n_particles_j,
               NULL,
               NULL,
               match_forward_ids,
               match_forward_score,
               match_forward_index,
               match_forward_2way,
               FALSE);
  SID_log("Done.",SID_LOG_CLOSE);
  SID_log("Processing backwards matches...",SID_LOG_OPEN|SID_LOG_TIMER);
  read_matches(filename_root_in,
               j_read,
               i_read,
               max_n_groups,
               mode,
               &n_groups_j,
               &n_groups_i,
               n_particles_j,
               n_particles_i,
               NULL,
               NULL,
               match_backward_ids,
               match_backward_score,
               match_backward_index,
               match_backward_2way,
               FALSE);
  SID_log("Done.",SID_LOG_CLOSE);

  // Open output file
  FILE *fp_out;
  fp_out=fopen(filename_out,"w");
  int i_column=1;
  fprintf(fp_out,"# Column (%02d): Halo index for snapshot %d\n",          i_column++,i_read);
  fprintf(fp_out,"#        (%02d): Halo index for snapshot %d\n",          i_column++,j_read);
  fprintf(fp_out,"#        (%02d): No. particles in snapshot %d\n",        i_column++,i_read);
  fprintf(fp_out,"#        (%02d): No. particles in snapshot %d\n",        i_column++,j_read);
  fprintf(fp_out,"#        (%02d): Forward  match score\n",                i_column++);
  fprintf(fp_out,"#        (%02d): Forward  match score/min match score\n",i_column++);
  fprintf(fp_out,"#        (%02d): Backward match score\n",                i_column++);
  fprintf(fp_out,"#        (%02d): Backward match score/min match score\n",i_column++);
  for(int i_halo=0;i_halo<n_groups_i;i_halo++){
     int j_halo=match_forward_ids[i_halo];
     if(match_forward_2way[i_halo]){
        if(j_halo<0 || j_halo>n_groups_j)
           SID_trap_error("There's an invalid match id (ie. %d<0 || %d>%d)  attached to a 2-way match!",ERROR_LOGIC,j_halo,j_halo,n_groups_j);
        fprintf(fp_out,"%7d %7d %6d %6d %10.3le %10.3le %10.3le %10.3le\n",
                i_halo,
                j_halo,
                n_particles_i[i_halo],
                n_particles_j[j_halo],
                match_forward_score[i_halo],
                match_forward_score[i_halo]/minimum_match_score((double)n_particles_i[i_halo]),
                match_backward_score[j_halo],
                match_backward_score[j_halo]/minimum_match_score((double)n_particles_j[j_halo]));
     }                
  }
  fclose(fp_out);

  // Clean-up
  SID_free(SID_FARG n_particles_i);
  SID_free(SID_FARG n_particles_j);
  SID_free(SID_FARG match_forward_ids);
  SID_free(SID_FARG match_forward_index);
  SID_free(SID_FARG match_forward_score);
  SID_free(SID_FARG match_forward_2way);
  SID_free(SID_FARG match_backward_ids);
  SID_free(SID_FARG match_backward_index);
  SID_free(SID_FARG match_backward_score);
  SID_free(SID_FARG match_backward_2way);
  
  SID_log("Done.",SID_LOG_CLOSE);
  SID_exit(ERROR_NONE);
}
Beispiel #3
0
int main(int argc, char *argv[]){

  SID_init(&argc,&argv,NULL,NULL);

  SID_log("Constructing match catalog...",SID_LOG_OPEN|SID_LOG_TIMER);

  // Parse arguments
  char filename_catalog_root[MAX_FILENAME_LENGTH];
  char filename_matches_root[MAX_FILENAME_LENGTH];
  char filename_out[MAX_FILENAME_LENGTH];
  char prefix_text[32];
  int  flag_matches_type;
  int  i_read;
  int  j_read;
  int  catalog_read_mode;
  int  matches_read_mode;
  strcpy(filename_catalog_root,argv[1]);
  strcpy(filename_matches_root,argv[2]);
  flag_matches_type      =atoi(argv[3]);
  strcpy(prefix_text,          argv[4]);
  i_read                 =atoi(argv[5]);
  j_read                 =atoi(argv[6]);
  strcpy(filename_out,         argv[7]);
  if(!strcpy(prefix_text,"subgroup") ||
     !strcpy(prefix_text,"subgroups") ||
     !strcpy(prefix_text,"sub")){
     sprintf(prefix_text,"sub");
     catalog_read_mode=READ_CATALOG_SUBGROUPS|READ_CATALOG_PROPERTIES;
     matches_read_mode=MATCH_SUBGROUPS;
  }
  else if(!strcpy(prefix_text,"group") ||
          !strcpy(prefix_text,"groups")){
     sprintf(prefix_text,"");
     catalog_read_mode=READ_CATALOG_GROUPS|READ_CATALOG_PROPERTIES;
     matches_read_mode=MATCH_GROUPS;
  }
  else
     SID_trap_error("Invalid catalog type (%s).",ERROR_SYNTAX,prefix_text);

  // Set filenames 
  char filename_cat1[MAX_FILENAME_LENGTH];
  char filename_cat2[MAX_FILENAME_LENGTH];
  sprintf(filename_cat1,"%s_%03d.catalog_%sgroups_properties",filename_catalog_root,prefix_text,i_read);
  sprintf(filename_cat2,"%s_%03d.catalog_%sgroups_properties",filename_catalog_root,prefix_text,j_read);

  // Contents of the halo properties structure
  //struct halo_properties_info{
  //  long long id_MBP;                    // ID of most bound particle in structure
  //  int       n_particles;               // Number of particles in the structure
  //  float     position_COM[3];           // Centre-of-mass position      [Mpc/h]
  //  float     position_MBP[3];           // Most bound particle position [Mpc/h]
  //  float     velocity_COM[3];           // Centre-of-mass velocity      [km/s]
  //  float     velocity_MBP[3];           // Most bound particle velocity [km/s]
  //  double    M_vir;                     // Bryan & Norman (ApJ 495, 80, 1998) virial mass [M_sol/h]
  //  float     R_vir;                     // Virial radius [Mpc/h]
  //  float     R_halo;                    // Distance of last halo particle from MBP [Mpc/h]
  //  float     R_max;                     // Radius of maximum circular velocity     [Mpc/h]
  //  float     V_max;                     // Maximum circular velocity               [km/s]
  //  float     sigma_v;                   // Total 3D velocity dispersion            [km/s]
  //  float     spin[3];                   // Specific angular momentum vector        [Mpc/h*km/s]
  //  float     q_triaxial;                // Triaxial shape parameter q=b/a
  //  float     s_triaxial;                // Triaxial shape parameter s=c/a
  //  float     shape_eigen_vectors[3][3]; // Normalized triaxial shape eigenvectors
  //};

  // Read matches
  int    *n_subgroups  =NULL;
  int    *n_groups     =NULL;
  int    *n_particles_i=NULL;
  int    *n_particles_j=NULL;
  int    *match_ids    =NULL;
  float  *match_score  =NULL;
  size_t *match_index  =NULL;
  int     n_halos_i;
  int     n_halos_j;
  int     n_files;
  int     n_subgroups_max;
  int     n_groups_max;
  int     n_halos_max;
  read_matches_header(filename_matches_root,
                      0,
                      MAX(i_read,j_read),
                      1,
                      &n_files,
                      &n_subgroups,
                      &n_groups,
                      &n_subgroups_max,
                      &n_groups_max,
                      &n_halos_max);
  read_matches(filename_matches_root,
               i_read,
               j_read,
               n_halos_max,
               matches_read_mode,
               &n_halos_i,
               &n_halos_j,
               n_particles_i,
               n_particles_j,
               NULL,
               NULL,
               match_ids,
               match_score,
               match_index,
               NULL,
               FALSE);

  // Create a storage array mapping the indices of the second catalog
  //    to those of the halos they are matched to in the first catalog
  int  i_halo;
  int  j_halo;
  int *storage_index;
  storage_index=(int *)SID_malloc(sizeof(int)*n_halos_j);
  for(j_halo=0;j_halo<n_halos_j;j_halo++)
     storage_index[j_halo]=-1;
  for(i_halo=0,j_halo=0;j_halo<n_halos_j && i_halo<n_halos_i;j_halo++){
     while(match_ids[match_index[i_halo]]<j_halo && i_halo<(n_halos_i-1)) i_halo++;
     if(match_ids[match_index[i_halo]]<j_halo)                            i_halo++;
     if(match_ids[match_index[i_halo]]==j_halo)
        storage_index[j_halo]=match_index[i_halo];
  }

  // Open catalog files
  fp_catalog_info fp_properties_i;
  fp_catalog_info fp_properties_j;
  fopen_catalog(filename_catalog_root,
                i_read,
                catalog_read_mode,
                &fp_properties_i);
  fopen_catalog(filename_catalog_root,
                j_read,
                catalog_read_mode,
                &fp_properties_j);

  // Read catalogs
  halo_properties_info *properties_i;
  halo_properties_info *properties_j;
  properties_i    =(halo_properties_info *)SID_malloc(sizeof(halo_properties_info)*n_halos_i);
  properties_j    =(halo_properties_info *)SID_malloc(sizeof(halo_properties_info)*n_halos_i);
  for(i_halo=0;i_halo<n_halos_i;i_halo++)
     fread_catalog_file(&fp_properties_i,NULL,NULL,&(properties_i[i_halo]),NULL,i_halo);
  for(j_halo=0;j_halo<n_halos_j;j_halo++){
     if(storage_index[j_halo]>=0)
        fread_catalog_file(&fp_properties_j,NULL,NULL,&(properties_j[storage_index[j_halo]]),NULL,j_halo);
  }
  fclose_catalog(&fp_properties_i);
  fclose_catalog(&fp_properties_j);

  // Write results
  int   i_column=0;
  FILE *fp_out;
  fp_out=fopen(filename_out,"w");
  fprintf(fp_out,"# Catalog for matches {root %s} and catalog {root %s}; snap No. %d to %d.\n",
                 filename_matches_root,
                 filename_catalog_root,
                 i_read,j_read);
  fprintf(fp_out,"# Columns:(%02d) id (catalog No. 1)\n",          i_column++);
  fprintf(fp_out,"#         (%02d) id (catalog No. 2)\n",          i_column++);
  fprintf(fp_out,"#         (%02d)  M (catalog No. 1) [M_sol/h]\n",i_column++);
  fprintf(fp_out,"#         (%02d)  M (catalog No. 2) [M_sol/h]\n",i_column++);
  fprintf(fp_out,"#         (%02d)  x (catalog No. 1) [Mpc/h]\n",  i_column++);
  fprintf(fp_out,"#         (%02d)  y (catalog No. 1) [Mpc/h]\n",  i_column++);
  fprintf(fp_out,"#         (%02d)  z (catalog No. 1) [Mpc/h]\n",  i_column++);
  fprintf(fp_out,"#         (%02d)  x (catalog No. 2) [Mpc/h]\n",  i_column++);
  fprintf(fp_out,"#         (%02d)  y (catalog No. 2) [Mpc/h]\n",  i_column++);
  fprintf(fp_out,"#         (%02d)  z (catalog No. 2) [Mpc/h]\n",  i_column++);
  for(i_halo=0;i_halo<n_halos_i;i_halo++){
     fprintf(fp_out,"%10d %10d %10.4le %10.4le %10.4f %10.4f %10.4f %10.4f %10.4f %10.4f\n",
                    i_halo,
                    match_ids[i_halo],
                    properties_i[i_halo].M_vir,
                    properties_j[i_halo].M_vir,
                    properties_i[i_halo].position_COM[0],
                    properties_i[i_halo].position_COM[1],
                    properties_i[i_halo].position_COM[2],
                    properties_j[i_halo].position_COM[0],
                    properties_j[i_halo].position_COM[1],
                    properties_j[i_halo].position_COM[2]);
  }
  fclose(fp_out);

  // Clean-up
  SID_free(SID_FARG n_subgroups);
  SID_free(SID_FARG n_groups);
  SID_free(SID_FARG n_particles_i);
  SID_free(SID_FARG n_particles_j);
  SID_free(SID_FARG properties_i);
  SID_free(SID_FARG properties_j);
  SID_free(SID_FARG match_ids);
  SID_free(SID_FARG match_score);
  SID_free(SID_FARG match_index);
  SID_free(SID_FARG storage_index);

  SID_log("Done.",SID_LOG_CLOSE);
  SID_exit(ERROR_NONE);
}