示例#1
0
static void load_overlaps(storm_file_handle_t *s_handle,
			  storm_status_t *storms1,
			  storm_status_t *storms2,
			  int istorm, int jstorm,
			  bounding_box_t *box1,
			  bounding_box_t *box2)

{

  ui08 *overlap_grid;
  ui08 *tmp_grid;

  ui32 nx, ny, npoints_grid;
  ui32 npoints_1, npoints_2, npoints_overlap;

  double area_grid;
  double area_1, area_2, area_overlap;
  double fraction_1, fraction_2, sum_fraction;
  
  bounding_box_t both;
  
  storm_status_t *storm1 = storms1 + istorm;
  storm_status_t *storm2 = storms2 + jstorm;
  
  titan_grid_t *grid = &s_handle->scan->grid;

  area_grid = grid->dx * grid->dy;

  /*
   * compute dimensions for bounding box for both
   * storms
   */
  
  both.min_ix = MIN(box1->min_ix, box2->min_ix);
  both.min_iy = MIN(box1->min_iy, box2->min_iy);
  both.max_ix = MAX(box1->max_ix, box2->max_ix);
  both.max_iy = MAX(box1->max_iy, box2->max_iy);
  
  /*
   * enlarge grid to make sure it will cover the
   * current storm1 position
   */
  
  both.min_ix = MIN(both.min_ix, storm1->current.bound.min_ix);
  both.min_iy = MIN(both.min_iy, storm1->current.bound.min_iy);
  both.max_ix = MAX(both.max_ix, storm1->current.bound.max_ix);
  both.max_iy = MAX(both.max_iy, storm1->current.bound.max_iy);
  
  /*
   * add 1 pixel margin
   */
  
  both.min_ix -= 1;
  both.min_iy -= 1;
  both.max_ix += 1;
  both.max_iy += 1;
  
  nx = both.max_ix - both.min_ix + 1;
  ny = both.max_iy - both.min_iy + 1;
  npoints_grid = nx * ny;
  
  if (Glob->params.debug >= DEBUG_VERBOSE) {

    fprintf(stderr, "BOTH:\n");
    fprintf(stderr, "min_ix, min_iy: %d, %d\n",
	    both.min_ix, both.min_iy);
    fprintf(stderr, "max_ix, max_iy: %d, %d\n",
	    both.max_ix, both.max_iy);
    fprintf(stderr, "nx, ny: %ld, %ld\n", (long) nx, (long) ny);
	
  }
  
  if (Glob->params.use_runs_for_overlaps) {

    /*
     * load tmp grid with storm1 runs
     */
    
    tmp_grid = init_tmp_grid(npoints_grid);
    overlap_grid = init_overlap_grid(npoints_grid);
    
    load_current_runs(storm1, &both, nx, tmp_grid, 1);
    
    /*
     * copy this storm onto the overlap grid, taking account of
     * movement and growth
     */
    
    npoints_1 = load_forecast_runs(storm1, &both, nx, ny, grid,
				   overlap_grid, tmp_grid);
    
    /*
     * add points for storm2 runs
     */
    
    npoints_2 = load_current_runs(storm2, &both, nx, overlap_grid, 2);

  } else {

    overlap_grid = init_overlap_grid(npoints_grid);
    
    npoints_1 = load_forecast_poly(s_handle, storm1, &both,
				   nx, ny, overlap_grid, 1);

    npoints_2 = load_current_poly(s_handle, storm2, &both,
				  nx, ny, overlap_grid, 2);

  }
  
  /*
   * compute overlap
   */
  
  npoints_overlap = compute_overlap(overlap_grid, npoints_grid);
  
  /*
   * compute areas
   */
  
  area_1 = (double) npoints_1 * area_grid;
  area_2 = (double) npoints_2 * area_grid;
  area_overlap = (double) npoints_overlap * area_grid;
  
  fraction_1 = area_overlap / area_1;
  fraction_2 = area_overlap / area_2;
  
  sum_fraction = fraction_1 + fraction_2;
  
  if (sum_fraction > Glob->params.min_sum_fraction_overlap) {

    if (Glob->params.debug >= DEBUG_VERBOSE) {
	    
      fprintf(stderr, "-------------------------\n");
      fprintf(stderr, "area_1, area_2, area_overlap: "
	      "%g, %g, %g\n",
	      area_1, area_2, area_overlap);
      fprintf(stderr, "fraction_1, fraction_2, sum_fraction: "
	      "%g, %g, %g\n",
	      fraction_1, fraction_2, sum_fraction);
      print_overlap(overlap_grid, nx, ny);
      fprintf(stderr, "-------------------------\n");
	    
    }

    add_overlap(storms1, storms2,
		istorm, jstorm,
		area_overlap);
							
  } /* if (sum_fraction > Glob->params.min_sum_fraction_overlap) */

}
示例#2
0
int
main(int argc, char *argv[]) {
  char         **av, *xform_name, *out_fname, fname[STRLEN], *seg_name, *s1, *s2 ;
  int          ac, nargs, i, nsubjects, j, nvoxels ;
  MRI          *mri_seg[MAX_SUBJECTS] ;
  float        overlap, total_overlap ;
  TRANSFORM    *transform1, *transform2 ;
  FILE         *fp ;

  /* rkt: check for and handle version tag */
  nargs = handle_version_option (argc, argv, "$Id: mri_evaluate_morph.c,v 1.5 2011/03/02 00:04:15 nicks Exp $", "$Name:  $");
  if (nargs && argc - nargs == 1)
    exit (0);
  argc -= nargs;

  Progname = argv[0] ;
  ErrorInit(NULL, NULL, NULL) ;
  DiagInit(NULL, NULL, NULL) ;

  if (strlen(sdir) == 0) {
    char *cp ;
    cp = getenv("SUBJECTS_DIR") ;
    if (!cp)
      ErrorExit(ERROR_BADPARM, "%s: no SUBJECTS_DIR in envoronment.\n",Progname);
    strcpy(sdir, cp) ;
  }
  ac = argc ;
  av = argv ;
  for ( ; argc > 1 && ISOPTION(*argv[1]) ; argc--, argv++) {
    nargs = get_option(argc, argv) ;
    argc -= nargs ;
    argv += nargs ;
  }

  if (argc < 3)
    usage_exit() ;

  xform_name = argv[1] ;
  seg_name = argv[2] ;
  out_fname = argv[argc-1] ;

#define FIRST_SUBJECT 3
  nsubjects = argc-(FIRST_SUBJECT+1) ;
  printf("processing %d subjects...\n", nsubjects) ;

  for (i = FIRST_SUBJECT ; i < argc-1 ; i++) {
    fprintf(stderr, "processing subject %s...\n", argv[i]) ;
    sprintf(fname, "%s/%s/mri/%s", sdir, argv[i], seg_name) ;
    mri_seg[i-FIRST_SUBJECT] = MRIread(fname) ;
    if (!mri_seg[i-FIRST_SUBJECT])
      ErrorExit(ERROR_NOFILE, "%s: could not read segmentation %s",
                Progname, fname) ;
  }

  fp = fopen(out_fname, "w") ;
  if (!fp)
    ErrorExit(ERROR_NOFILE, "%s: could not open output file %s...\n", out_fname) ;

  nvoxels = mri_seg[0]->width * mri_seg[0]->height * mri_seg[0]->depth ;
  for (total_overlap = 0.0f, i = 0 ; i < nsubjects ; i++) {
    for (j = i+1 ; j < nsubjects ; j++) {
      s1 = argv[i+FIRST_SUBJECT] ;
      s2 = argv[j+FIRST_SUBJECT] ;
      printf("reading transforms for subjects %s and %s...\n", s1, s2) ;
      sprintf(fname, "%s/%s/mri/transforms/%s", sdir, s1, xform_name) ;
      transform1 = TransformRead(fname) ;
      if (transform1 == NULL)
        ErrorExit(ERROR_NOFILE, "%s: could not read transform %s",
                  Progname, fname) ;
      sprintf(fname, "%s/%s/mri/transforms/%s", sdir, s1, xform_name) ;
      transform2 = TransformRead(fname) ;
      if (transform2 == NULL)
        ErrorExit(ERROR_NOFILE, "%s: could not read transform %s",
                  Progname, fname) ;
      printf("computing overlap for subjects %s and %s...\n", s1, s2) ;
      overlap = compute_overlap(mri_seg[i], mri_seg[j], transform1, transform2) ;
      total_overlap += overlap ;
      printf("overlap = %2.0f, total = %2.0f\n", overlap, total_overlap) ;
      fprintf(fp, "%s %s %2.0f %2.1f\n", s1, s2, overlap, 100.0f*overlap/(float)nvoxels) ;
      fflush(fp) ;
      TransformFree(&transform1) ;
      TransformFree(&transform2) ;
    }
  }

  total_overlap /= (float)((nsubjects*(nsubjects-1))/2.0f) ;
  printf("overlap/subject pair = %2.0f (%2.1f %%)\n", total_overlap,
         100.0f*total_overlap/(float)nvoxels) ;

  fclose(fp) ;
  exit(0) ;
  return(0) ;  /* for ansi */
}