Esempio n. 1
0
/***-------------------------------------------------------****/
int main(int argc, char *argv[])
{
  int  nargs, index, ac, nvolumes;
  char **av ;
  MRI  *mri_or = NULL, *mri ;

  /* rkt: check for and handle version tag */
  nargs = handle_version_option (argc, argv, vcid, "$Name:  $");
  if (nargs && argc - nargs == 1)
    exit (0);
  Progname = argv[0] ;
  argc -= nargs;
  ac = argc ;
  av = argv ;
  for ( ; argc > 1 && ISOPTION(*argv[1]) ; argc--, argv++)
  {
    nargs = get_option(argc, argv) ;
    argc -= nargs ;
    argv += nargs ;
  }

  nvolumes = argc-2 ;
  if (nvolumes <= 0)
    usage_exit() ;
  printf("processing %d input files\n", nvolumes) ;

  ErrorInit(NULL, NULL, NULL) ;
  DiagInit(NULL, NULL, NULL) ;

  for (index = 0 ; index < nvolumes ; index++)
  {
    char *fname = argv[index+1] ;
    printf("processing input volume %d of %d: %s\n",
           index+1, nvolumes, fname) ;
    mri = MRIread(fname) ;
    if (index == 0){
      mri_or = MRIcopy(mri, NULL) ;
    // if nvolumes == 1 binarize the volume! LZ: MRIbinarize(MRI *mri_src, MRI *mri_dst, float threshold, float low_val,float hi_val)
      if (nvolumes == 1) {
	if(use_orig_value)
	  MRIorVal(mri, mri_or, mri_or, 0) ;
	else
	  MRIor(mri, mri_or, mri_or, 0) ;
      }
    } 
    else {
      if(use_orig_value)
	MRIorVal(mri, mri_or, mri_or, 0) ;
      else
	MRIor(mri, mri_or, mri_or, 0) ;
    }


    MRIfree(&mri) ;
  }

  printf("writing output to %s\n", argv[argc-1]) ;
  MRIwrite(mri_or, argv[argc-1]) ;
  exit(0);

} /* end main() */
Esempio n. 2
0
FCD_DATA   *
FCDloadData(char *sdir, char *subject)
{
  FCD_DATA    *fcd ;
  char        fname[STRLEN] ;
  MRI         *mri_interior, *mri_dist, *mri_int_lh, *mri_int_rh, *mri_pvals ;

  fcd = (FCD_DATA *)calloc(1, sizeof(FCD_DATA)) ;

  sprintf(fname, "%s/%s/surf/lh.white", sdir, subject) ;
  fcd->mris_lh = MRISread(fname) ;
  if (fcd->mris_lh == NULL)
  {
    ErrorExit(ERROR_NOFILE, "FCDloadData: couldn't load %s", fname) ;
  }
  MRISsaveVertexPositions(fcd->mris_lh, WHITE_VERTICES) ;
  if (MRISreadPialCoordinates(fcd->mris_lh, "pial") != NO_ERROR)
  {
    ErrorExit(ERROR_NOFILE, "FCDloadData: couldn't load lh pial vertices") ;
  }

  sprintf(fname, "%s/%s/surf/lh.pial", sdir, subject) ;
  fcd->mris_lh_pial = MRISread(fname) ;
  if (fcd->mris_lh_pial == NULL)
  {
    ErrorExit(ERROR_NOFILE, "FCDloadData: couldn't load %s", fname) ;
  }

  sprintf(fname, "%s/%s/surf/lh.sphere.d1.left_right", sdir, subject) ;
  fcd->mris_lh_sphere_d1 = MRISread(fname) ;
  if (fcd->mris_lh_sphere_d1 == NULL)
  {
    ErrorExit(ERROR_NOFILE, "FCDloadData: couldn't load %s", fname) ;
  }

  exec_progress_callback(1, 12, 0, 1) ;
  sprintf(fname, "%s/%s/surf/rh.white", sdir, subject) ;
  fcd->mris_rh = MRISread(fname) ;
  if (fcd->mris_rh == NULL)
  {
    ErrorExit(ERROR_NOFILE, "FCDloadData: couldn't load %s", fname) ;
  }
  MRISsaveVertexPositions(fcd->mris_rh, WHITE_VERTICES) ;
  if (MRISreadPialCoordinates(fcd->mris_rh, "pial") != NO_ERROR)
  {
    ErrorExit(ERROR_NOFILE, "FCDloadData: couldn't load rh pial vertices") ;
  }

  sprintf(fname, "%s/%s/surf/rh.pial", sdir, subject) ;
  fcd->mris_rh_pial = MRISread(fname) ;
  if (fcd->mris_rh_pial == NULL)
  {
    ErrorExit(ERROR_NOFILE, "FCDloadData: couldn't load %s", fname) ;
  }

  sprintf(fname, "%s/%s/surf/rh.sphere.d1.left_right", sdir, subject) ;
  fcd->mris_rh_sphere_d1 = MRISread(fname) ;
  if (fcd->mris_rh_sphere_d1 == NULL)
  {
    ErrorExit(ERROR_NOFILE, "FCDloadData: couldn't load %s", fname) ;
  }

  exec_progress_callback(2, 12, 0, 1) ;
  sprintf(fname, "%s/%s/mri/aseg.mgz", sdir, subject) ;
  fcd->mri_aseg = MRIread(fname) ;
  if (fcd->mri_aseg == NULL)
  {
    ErrorExit(ERROR_NOFILE, "FCDloadData: couldn't load %s", fname) ;
  }

  exec_progress_callback(3, 12, 0, 1) ;
  sprintf(fname, "%s/%s/mri/aparc+aseg.mgz", sdir, subject) ;
  fcd->mri_aparc = MRIread(fname) ;
  if (fcd->mri_aparc == NULL)
  {
    ErrorExit(ERROR_NOFILE, "FCDloadData: couldn't load %s", fname) ;
  }

  exec_progress_callback(4, 12, 0, 1) ;
  fcd->mri_flair = NULL;
  sprintf(fname, "%s/%s/mri/flair.reg.norm.mgz", sdir, subject) ; 
  if ( ! FileExists(fname))
  {
    sprintf(fname, "%s/%s/mri/FLAIR.mgz", sdir, subject) ; 
    if ( ! FileExists(fname))
    {
      sprintf(fname, "%s/%s/mri/FLAIRax.mgz", sdir, subject) ; 
      if ( ! FileExists(fname))
      {
        sprintf(fname, "%s/%s/mri/FLAIRcor.mgz", sdir, subject) ; 
        if ( ! FileExists(fname))
        {
          sprintf(fname, " ");
        }
      }
    }
  }
  if (strlen(fname) > 1)
  {
    fcd->mri_flair = MRIread(fname) ;
    if (fcd->mri_flair == NULL)
    {
      ErrorExit(ERROR_NOFILE, "FCDloadData: couldn't load $s", fname) ;
    }
  }

  fcd->mri_t2 = NULL;
  sprintf(fname, "%s/%s/mri/T2.mgz", sdir, subject) ; 
  if ( ! FileExists(fname))
  {
    sprintf(fname, "%s/%s/mri/T2ax.mgz", sdir, subject) ; 
    if ( ! FileExists(fname))
    {
      sprintf(fname, "%s/%s/mri/T2cor.mgz", sdir, subject) ; 
      if ( ! FileExists(fname))
      {
        sprintf(fname, " ");
      }
    }
  }
  if (strlen(fname) > 1)
  {
    fcd->mri_t2 = MRIread(fname) ;
    if (fcd->mri_t2 == NULL)
    {
      ErrorExit(ERROR_NOFILE, "FCDloadData: couldn't load $s", fname) ;
    }
  }

  exec_progress_callback(5, 12, 0, 1) ;
  sprintf(fname, "%s/%s/mri/norm.mgz", sdir, subject) ;
  fcd->mri_norm = MRIread(fname) ;
  if (fcd->mri_norm == NULL)
  {
    ErrorExit(ERROR_NOFILE, "FCDloadData: couldn't load %s", fname) ;
  }

  fcd->mri_thickness_increase = 
    MRIcloneDifferentType(fcd->mri_aseg, MRI_FLOAT) ;
  fcd->mri_thickness_decrease = 
    MRIcloneDifferentType(fcd->mri_aseg, MRI_FLOAT) ;
  fcd->mri_thickness_difference = MRIadd(fcd->mri_thickness_increase, fcd->mri_thickness_decrease, NULL);

  exec_progress_callback(6, 12, 0, 1) ;
  sprintf(fname, "%s/%s/surf/lh.rh.thickness.smooth0.mgz", sdir, subject) ;
  fcd->rh_thickness_on_lh = MRIread(fname) ;
  if (fcd->mri_aseg == NULL)
  {
    ErrorExit(ERROR_NOFILE, "FCDloadData: couldn't load %s", fname) ;
  }

  exec_progress_callback(7, 12, 0, 1) ;
  sprintf(fname, "%s/%s/surf/rh.thickness.mgz", sdir, subject) ;
  fcd->rh_thickness_on_rh = MRIread(fname) ;
  if (fcd->rh_thickness_on_rh == NULL)
  {
    ErrorExit(ERROR_NOFILE, "FCDloadData: couldn't load %s", fname) ;
  }

  exec_progress_callback(8, 12, 0, 1) ;
  sprintf(fname, "%s/%s/surf/lh.thickness.mgz", sdir, subject) ;
  fcd->lh_thickness_on_lh = MRIread(fname) ;
  if (fcd->lh_thickness_on_lh == NULL)
  {
    ErrorExit(ERROR_NOFILE, "FCDloadData: couldn't load %s", fname) ;
  }

  exec_progress_callback(9, 12, 0, 1) ;
  sprintf(fname, "%s/%s/surf/rh.lh.thickness.smooth0.mgz", sdir, subject) ;
  if ( ! FileExists(fname))
  {
    sprintf(fname, "%s/%s/surf/rh.lh.thickness.mgz", sdir, subject) ;
    if (fcd->lh_thickness_on_rh == NULL)
    {
      ErrorExit(ERROR_NOFILE, "FCDloadData: couldn't load %s", fname) ;
    }
  }
  fcd->lh_thickness_on_rh = MRIread(fname) ;

  exec_progress_callback(10, 12, 0, 1) ;
  mri_int_lh = MRIclone(fcd->mri_norm, NULL) ;
  mri_int_rh = MRIclone(fcd->mri_norm, NULL) ;
  mri_interior = MRIclone(fcd->mri_norm, NULL) ;
  mri_dist = MRIcloneDifferentType(mri_interior, MRI_FLOAT) ;
  MRISrestoreVertexPositions(fcd->mris_lh, PIAL_VERTICES) ;
  MRISrestoreVertexPositions(fcd->mris_rh, PIAL_VERTICES) ;
  MRISfillInterior(fcd->mris_lh, mri_interior->xsize, mri_int_lh) ;
  MRISfillInterior(fcd->mris_rh, mri_interior->xsize, mri_int_rh) ;

  exec_progress_callback(11, 12, 0, 1) ;
  MRIor(mri_int_lh, mri_int_rh, mri_interior, 0) ;
  MRIfree(&mri_int_lh) ;
  MRIfree(&mri_int_rh) ;
  MRIbinarize(mri_interior, mri_interior, 1, 0, 1) ;
  if (Gdiag & DIAG_WRITE)
  {
    MRIwrite(mri_interior, "int.mgz") ;
  }
  MRIdistanceTransform(mri_interior,
                       mri_dist,
                       1,
                       2*MAX_DIST,
                       DTRANS_MODE_SIGNED,
                       NULL);
  if (Gdiag & DIAG_WRITE)
  {
    MRIwrite(mri_dist, "dist.mgz") ;
  }
  mri_pvals = build_distance_by_intensity_histo(fcd->mri_norm, 
                                                mri_dist,
                                                fcd->mri_aseg,
                                                DIST_SPACING,
                                                MAX_DIST) ;
  exec_progress_callback(12, 12, 0, 1) ;
  augment_thicknesses(fcd, mri_pvals, 1.5, 5, 1) ;

  MRISrestoreVertexPositions(fcd->mris_lh, WHITE_VERTICES) ;
  MRISrestoreVertexPositions(fcd->mris_rh, WHITE_VERTICES) ;
  MRIfree(&mri_dist) ;
  MRIfree(&mri_interior) ;
  MRIfree(&mri_pvals) ;

  return(fcd) ;
}