Ejemplo n.º 1
0
int main (int argc, char **argv)
{
    FILE *in_file, *out_file;
    VImage image;
    VAttrList list = VCreateAttrList ();
    char prg[50];	
    sprintf(prg,"plaintov V%s", getVersion());
    fprintf (stderr, "%s\n", prg);


    VParseFilterCmd (VNumber (options), options, argc, argv,
		     & in_file, & out_file);
    
    if (! (image = VReadPlain (in_file)))
	exit (EXIT_FAILURE);

    VHistory(VNumber(options),options,prg,&list,&list);
    VAppendAttr (list, object_name, NULL, VImageRepn, image);
    if (! VWriteFile (out_file, list))
	exit (EXIT_FAILURE);

    fprintf (stderr, "%s: Converted 1 file from Vista plain format"
	     " to Vista format.\n", argv[0]);

    return EXIT_SUCCESS;
}
Ejemplo n.º 2
0
int 
main (int argc,char *argv[])
{  
  static VFloat sigma = 1.5;
  static VOptionDescRec  options[] = {
    {"sigma",VFloatRepn,1,(VPointer) &sigma,VOptionalOpt,NULL,"std dev"}
  };
  FILE *in_file,*out_file;
  VAttrList list=NULL;
  VAttrListPosn posn;
  VImage src=NULL,dest=NULL;
  char prg[50];	
  sprintf(prg,"vgauss2d V%s", getVersion());
  fprintf (stderr, "%s\n", prg);
  
  VParseFilterCmd (VNumber (options),options,argc,argv,&in_file,&out_file);

  if (! (list = VReadFile (in_file, NULL))) exit (1);
  fclose(in_file);

  for (VFirstAttr (list, & posn); VAttrExists (& posn); VNextAttr (& posn)) {
    if (VGetAttrRepn (& posn) != VImageRepn) continue;
    VGetAttrValue (& posn, NULL,VImageRepn, & src);

    dest = VFilterGauss2d (src,NULL,(double)sigma);

    VSetAttrValue (& posn, NULL,VImageRepn,dest);
  }
  if (src == NULL) VError(" no input image found");

  VHistory(VNumber(options),options,prg,&list,&list);
  if (! VWriteFile (out_file, list)) exit (1);
  fprintf (stderr, "%s: done.\n", argv[0]);
  return 0;
}
Ejemplo n.º 3
0
int
main(int argc, char *argv[]) {
    static VShort type = 0;
    static VArgVector contrast;
    static VOptionDescRec  options[] = {
        {"type", VShortRepn, 1, (VPointer) &type, VOptionalOpt, TYPDict, "type of output"},
        {"contrast", VFloatRepn, 0, (VPointer) &contrast, VRequiredOpt, NULL, "contrast vector"}
    };
    FILE *in_file, *out_file;
    VAttrList list = NULL, out_list = NULL;
    gsl_vector_float *cont;
    float u;
    int i;
    char prg_name[100];
	char ver[100];
	getLipsiaVersion(ver, sizeof(ver));
	sprintf(prg_name, "vgetcontrast V%s", ver);
    fprintf(stderr, "%s\n", prg_name);
    VParseFilterCmd(VNumber(options), options, argc, argv, &in_file, &out_file);
    cont = gsl_vector_float_alloc(contrast.number);
    for(i = 0; i < contrast.number; i++) {
        u = ((VFloat *)contrast.vector)[i];
        fvset(cont, i, u);
    }
    if(!(list = VReadFile(in_file, NULL)))
        exit(1);
    fclose(in_file);
    out_list = VGetContrast(list, cont, type);
    /* Output: */
    VHistory(VNumber(options), options, prg_name, &list, &out_list);
    if(! VWriteFile(out_file, out_list))
        exit(1);
    fprintf(stderr, "%s: done.\n", argv[0]);
    return 0;
}
Ejemplo n.º 4
0
VBoolean VWriteObjects (FILE *file, VRepnKind repn, VAttrList attributes,
			int nobjects, VPointer objects[])
{
    VAttrList list;
    VAttrListPosn posn;
    int i;
    VBoolean result;

    /* Create an attribute list if none was supplied: */
    list = attributes ? attributes : VCreateAttrList ();

    /* Prepend to the attribute list an attribute for each object: */
    for (i = nobjects - 1; i >= 0; i--)
	VPrependAttr (list, VRepnName (repn), NULL, repn, objects[i]);

    /* Write the attribute list: */
    result = VWriteFile (file, list);

    /* Remove the attributes just prepended: */
    VFirstAttr (list, & posn);
    for (i = 0; i < nobjects; i++)
	VDeleteAttr (& posn);
    if (list != attributes)
	VDestroyAttrList (list);

    return result;
}
Ejemplo n.º 5
0
int
main(int argc, char *argv[]) {
    static VString cfile = "";
    static VFloat tr = 2;
    static VBoolean normalize = FALSE;
    static VOptionDescRec  options[] = {
        {"in", VStringRepn, 1, (VPointer) &cfile, VRequiredOpt, NULL, "file"},
        {"tr", VFloatRepn, 1, (VPointer) &tr, VRequiredOpt, NULL, "TR in seconds"},
        {"normalize", VBooleanRepn, 1, (VPointer) &normalize, VOptionalOpt, NULL, "Whether to normalize"}
    };
    FILE *out_file = NULL;
    VAttrList list = NULL;
    VImage dest = NULL;
	char prg_name[100];
	char ver[100];
	getLipsiaVersion(ver, sizeof(ver));
	sprintf(prg_name, "vcovariates V%s", ver);
	fprintf(stderr, "%s\n", prg_name);
    VParseFilterCmd(VNumber(options), options, argc, argv, NULL, &out_file);
    if(tr > 500)
        VError(" tr must be given in seconds, not milliseconds");
    dest = VCovariates(cfile, tr, normalize);
    list = VCreateAttrList();
    VAppendAttr(list, "image", NULL, VImageRepn, dest);
    /* Output: */
    if(! VWriteFile(out_file, list))
        exit(1);
    fprintf(stderr, " %s: done.\n", argv[0]);
    return 0;
}
Ejemplo n.º 6
0
int main(int argc, char **argv) {
    static VString filename = "";
    static VLong neighb = 2;
    static VLong iter = 1;
    static VOptionDescRec options[] = {
        {
            "n", VLongRepn, 1, &neighb, VOptionalOpt, TYPDict,
            "type of neighbourhood used for smoothing"
        },
        {
            "iter", VLongRepn, 1, &iter, VOptionalOpt, NULL,
            "number of iterations"
        },
        {
            "image", VStringRepn, 1, &filename, VOptionalOpt, NULL,
            "grey value image"
        },
    };
    FILE *in_file, *out_file, *fp;
    VAttrList list, list1;
    VImage src = NULL, dest, image = NULL;
    VAttrListPosn posn;
    /* Parse command line arguments: */
    VParseFilterCmd(VNumber(options), options, argc, argv, &in_file, &out_file);
    /* Read transformation image: */
    fp = VOpenInputFile(filename, TRUE);
    list1 = VReadFile(fp, NULL);
    if(! list1)
        VError("Error reading image");
    fclose(fp);
    for(VFirstAttr(list1, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
        if(VGetAttrRepn(& posn) != VImageRepn)
            continue;
        VGetAttrValue(& posn, NULL, VImageRepn, & image);
        if(VPixelRepn(image) != VUByteRepn)
            continue;
        VGetAttrValue(& posn, NULL, VImageRepn, & image);
        break;
    }
    if(image == NULL)
        VError(" image not found");
    /* Read source image(s): */
    if(!(list = VReadFile(in_file, NULL)))
        exit(1);
    for(VFirstAttr(list, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
        if(VGetAttrRepn(& posn) != VImageRepn)
            continue;
        VGetAttrValue(& posn, NULL, VImageRepn, & src);
        dest = VTopSmoothImage3d(src, image, NULL, neighb, iter);
        if(dest == NULL)
            exit(1);
        VSetAttrValue(& posn, NULL, VImageRepn, dest);
        VDestroyImage(src);
    }
    /* Write the results to the output file: */
    if(VWriteFile(out_file, list))
        fprintf(stderr, "%s: done.\n", argv[0]);
    return 0;
}
Ejemplo n.º 7
0
int
main(int argc, char *argv[]) {
    static VString filename = "";
    static VBoolean fisher = FALSE;
    static VShort  minval = 0;
    static VOptionDescRec  options[] = {
        {"mask", VStringRepn, 1, (VPointer) &filename, VRequiredOpt, NULL, "mask"},
        {"fisher", VBooleanRepn, 1, (VPointer) &fisher, VOptionalOpt, NULL, "Whether to do fisher transform"},
        {"minval", VShortRepn, 1, (VPointer) &minval, VOptionalOpt, NULL, "signal threshold"}
    };
    FILE *in_file, *out_file, *fp;
    VAttrList list = NULL, list1 = NULL, list2 = NULL;
    VAttrListPosn posn;
    VImage dest = NULL, mask = NULL;
	char prg_name[100];
	char ver[100];
	getLipsiaVersion(ver, sizeof(ver));
	sprintf(prg_name, "vsimmat V%s", ver);
	fprintf(stderr, "%s\n", prg_name);
    VParseFilterCmd(VNumber(options), options, argc, argv, &in_file, &out_file);
    /*
    ** read mask
    */
    fp = VOpenInputFile(filename, TRUE);
    list1 = VReadFile(fp, NULL);
    if(! list1)
        VError("Error reading mask file");
    fclose(fp);
    for(VFirstAttr(list1, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
        if(VGetAttrRepn(& posn) != VImageRepn)
            continue;
        VGetAttrValue(& posn, NULL, VImageRepn, & mask);
        if(VPixelRepn(mask) != VBitRepn) {
            mask = NULL;
            continue;
        }
    }
    if(mask == NULL)
        VError(" no mask found");
    /*
    ** read functional data
    */
    if(!(list = VReadFile(in_file, NULL)))
        exit(1);
    fclose(in_file);
    /*
    ** process
    */
    dest = SimilarityMatrix(list, mask, minval, fisher);
    list2 = VCreateAttrList();
    VAppendAttr(list2, "matrix", NULL, VImageRepn, dest);
    VHistory(VNumber(options), options, prg_name, &list, &list2);
    if(! VWriteFile(out_file, list2))
        exit(1);
    fprintf(stderr, "%s: done.\n", argv[0]);
    return 0;
}
Ejemplo n.º 8
0
int
main(int argc, char *argv[]) {
    static VShort minval = 0;
    static VFloat tdel = 5;
    static VBoolean slicetime_correction = TRUE;
    static VString slicetime = "";
    static VString filename = "";
    static VOptionDescRec  options[] = {
        {"minval", VShortRepn, 1, (VPointer) &minval, VOptionalOpt, NULL, "Signal threshold"},
        {
            "correction", VBooleanRepn, 1, (VPointer) &slicetime_correction, VOptionalOpt, NULL,
            "Whether to perform slicetime correction"
        },
        {
            "slicetime", VStringRepn, 1, (VPointer) &slicetime, VOptionalOpt, NULL,
            "ASCII file containing slice times in milliseconds"
        },
        {
            "scanfile", VStringRepn, 1, (VPointer) &filename, VOptionalOpt, NULL,
            "ASCII file containing scan times in seconds"
        },
        {"del", VFloatRepn, 1, (VPointer) &tdel, VOptionalOpt, NULL, "First few seconds to be ignored"}
    };
    FILE *in_file = NULL, *out_file = NULL;
    VAttrList list = NULL;
    float *onset_array = NULL;
    char prg_name[100];
    char ver[100];
    getLipsiaVersion(ver, sizeof(ver));
    sprintf(prg_name, "vslicetime V%s", ver);
    fprintf(stderr, "%s\n", prg_name);
    VParseFilterCmd(VNumber(options), options, argc, argv, &in_file, &out_file);
    if(!(list = VReadFile(in_file, NULL)))
        exit(1);
    fclose(in_file);
    if(strlen(slicetime) > 2)
        onset_array = ReadSlicetimes(slicetime);
    if(strlen(filename) < 2) {
        VSlicetime(list, minval, tdel, slicetime_correction, onset_array);
    } else {
        VSlicetime_NC(list, minval, tdel, slicetime_correction, onset_array, filename);
    }
    VHistory(VNumber(options), options, prg_name, &list, &list);
    if(! VWriteFile(out_file, list))
        exit(1);
    fprintf(stderr, "%s: done.\n", argv[0]);
    exit(0);
}
Ejemplo n.º 9
0
int 
main (int argc,char *argv[])
{ 
  static VShort aneighb = 1;
  static VShort arepn = 1;
  static VOptionDescRec  options[] = {
    {"n",VShortRepn,1,(VPointer) &aneighb,
       VOptionalOpt,ADJDict,"neighbourhood type"},
    {"repn",VShortRepn,1,(VPointer) &arepn,
       VOptionalOpt,TYPEDict,"output representation type (ubyte or short)"}
  };
  FILE *in_file,*out_file;
  VAttrList list=NULL;
  VAttrListPosn posn;
  VImage src=NULL,dest=NULL;
  int nl=0,neighb;
  VRepnKind repn;
  char prg[50];	
  sprintf(prg,"vlabel2d V%s", getVersion());
  fprintf (stderr, "%s\n", prg);

  VParseFilterCmd (VNumber (options),options,argc,argv,&in_file,&out_file);

  if (arepn == 0) repn = VUByteRepn;
  else repn = VShortRepn;

  if (aneighb == 0) neighb = 4;
  else neighb = 8;

  if (! (list = VReadFile (in_file, NULL))) exit (1);
  fclose(in_file);

  for (VFirstAttr (list, & posn); VAttrExists (& posn); VNextAttr (& posn)) {
    if (VGetAttrRepn (& posn) != VImageRepn) continue;
    VGetAttrValue (& posn, NULL,VImageRepn, & src);

    dest = VLabelImage2d(src,NULL, (int) neighb,repn,&nl);
    fprintf(stderr," numlabels= %d\n",nl);
    VSetAttrValue (& posn, NULL,VImageRepn,dest);
  }
  if (src == NULL) VError(" no input image found");


  VHistory(VNumber(options),options,prg,&list,&list);
  if (! VWriteFile (out_file, list)) exit (1);
  fprintf (stderr, "%s: done.\n", argv[0]);
  return 0;
}
Ejemplo n.º 10
0
int 
main (int argc,char *argv[])
{
  static VShort first = 0;
  static VShort last = -1;
  static VOptionDescRec options[] = {
    { "first", VShortRepn, 1, (VPointer) & first,
      VOptionalOpt, NULL, "First slice" },
    { "last", VShortRepn, 1, (VPointer) & last,
      VOptionalOpt, NULL, "Last slice " }
  };

  FILE *in_file, *out_file;
  VAttrList list;
  VAttrListPosn posn;
  VImage src=NULL, result=NULL;
  char prg[50];	
  sprintf(prg,"vselbands V%s", getVersion());
  fprintf (stderr, "%s\n", prg);

  /* Parse command line arguments and identify files: */
  VParseFilterCmd (VNumber (options), options, argc, argv,& in_file, & out_file);


  /* Read the input file: */
  list = VReadFile (in_file, NULL);
  if (! list) exit (1);


  /* process */
  for (VFirstAttr (list, & posn); VAttrExists (& posn); VNextAttr (& posn)) {

    if (VGetAttrRepn (& posn) != VImageRepn) continue;
    VGetAttrValue (& posn, NULL, VImageRepn, & src);
    result = VSelSlices (src, NULL,first,last);
    if (! result) exit (1);
    VSetAttrValue (& posn, NULL, VImageRepn, result);
    VDestroyImage (src);
  }


  /* Write out the results: */
  VHistory(VNumber(options),options,prg,&list,&list);
  if (! VWriteFile (out_file, list)) exit (1);
  fprintf (stderr, "%s: done.\n", argv[0]);
  return 0;
}
Ejemplo n.º 11
0
VBoolean WriteImages (VString Name, VAttrList Images, VAttrList& history_list)
{
   FILE*         file;      /* output file      */
   VAttrList     list;      /* attribute list   */
   VAttrListPosn pos;       /* position in list */
   VImage        image;     /* image in list    */
   VBoolean      success;   /* success flag     */
   char history[]="history";

   /* open file */
   file = fopen (Name, "w");
   if (!file)
   {
      VError ("Failed to open output file '%s'", Name);
      return FALSE;
   }

   /* create list */
   list = VCreateAttrList();
 
   /* insert images */
   for (VFirstAttr (Images, &pos); VAttrExists (&pos); VNextAttr (&pos))
   {
      VGetAttrValue (&pos, NULL, VImageRepn, &image);
      VAppendAttr (list, VGetAttrName (&pos), NULL, VImageRepn, image);
   }

   /* Prepend history */
   VPrependAttr(list, history ,NULL,VAttrListRepn,history_list);
   
   /* write file */
   success = VWriteFile (file, list);
   if (!success) VError ("Failed to write output file '%s'", Name);

   /* remove images */
   for (VFirstAttr (list, &pos); VAttrExists (&pos); VNextAttr (&pos))
      if (VGetAttrRepn (&pos) == VImageRepn)
         VSetAttrValue (&pos, NULL, VImageRepn, NULL);

   /* clean-up*/
   VDestroyAttrList (list);
   fclose (file);

   return success;

} /* WriteImages */
Ejemplo n.º 12
0
Archivo: vhemi.c Proyecto: Rollmops/via
int main (int argc,char *argv[])
{
  static VLong hemi = 0;
  static VOptionDescRec options[] = {
    { "hemi", VLongRepn, 1, & hemi, VOptionalOpt, HEMIDict,
      "Hemisphere to retain" }
  };
  FILE *in_file, *out_file;
  VAttrList list;
  VAttrListPosn posn;
  VImage isrc=NULL;
  VGraph gsrc=NULL,dest=NULL;
  char prg[50];	
  sprintf(prg,"vhemi V%s", getVersion());
  fprintf (stderr, "%s\n", prg);
  
  /* Parse command line arguments and identify files: */
  VParseFilterCmd (VNumber (options), options, argc, argv,
		   & in_file, & out_file);
  
  /* Read the grey input file: */
  list = VReadFile (in_file, NULL);
  if (! list) VError("Error reading input image");
  fclose(in_file);


  for (VFirstAttr (list, & posn); VAttrExists (& posn); VNextAttr (& posn)) {
    if (VGetAttrRepn (& posn) == VImageRepn) {
      VGetAttrValue (& posn, NULL, VImageRepn, & isrc);
      VImageHemi(&isrc,hemi);
      VSetAttrValue (& posn, NULL,VImageRepn,isrc);
    }
    else if (VGetAttrRepn (& posn) == VGraphRepn) {
      VGetAttrValue (& posn, NULL, VGraphRepn, & gsrc);
      dest = VGraphHemi(gsrc,hemi);
      VSetAttrValue (& posn, NULL,VGraphRepn,dest);
    }
  }

  /* Write out the results: */
  VHistory(VNumber(options),options,prg,&list,&list);
  if (! VWriteFile (out_file,list)) exit (1);
  fprintf (stderr, "%s: done.\n", argv[0]);
  return 0;
}
Ejemplo n.º 13
0
int main(int argc, char *argv[]) {
    static VDouble d1   = 0;
    static VDouble d2   = 3.0;
    static VShort threshold = 155;
    static VShort background = 30;
    static VFloat edge  = 20;
    static VOptionDescRec options[] = {
        { "d1", VDoubleRepn, 1, &d1, VOptionalOpt, 0, "erosion" },
        { "d2", VDoubleRepn, 1, &d2, VOptionalOpt, 0, "dilation" },
        { "t", VShortRepn, 1, &threshold, VOptionalOpt, 0, "threshold" },
        { "background", VShortRepn, 1, &background, VOptionalOpt, 0, " image background" },
        { "edge", VFloatRepn, 1, &edge, VOptionalOpt, 0, "edge strength" }
    };
    VAttrList list;
    VAttrListPosn posn;
    VImage src = NULL, dst = NULL;
    FILE *in_file, *out_file;
    char prg_name[100];
	char ver[100];
	getLipsiaVersion(ver, sizeof(ver));
	sprintf(prg_name, "vbrainpeel V%s", ver);
    fprintf(stderr, "%s\n", prg_name);
    VParseFilterCmd(VNumber(options), options, argc, argv, &in_file, &out_file);
    /* Read source image(s): */
    if(!(list = VReadFile(in_file, NULL)))
        return 1;
    fclose(in_file);
    /* Operate on each source image: */
    for(VFirstAttr(list, &posn); VAttrExists(&posn); VNextAttr(&posn)) {
        if(VGetAttrRepn(&posn) == VImageRepn) {
            VGetAttrValue(&posn, NULL, VImageRepn, &src);
            dst = VPeel(src, NULL, d1, d2, edge, threshold, background);
            if(dst)
                VSetAttrValue(&posn, NULL, VImageRepn, dst);
            else
                VError(" error in vbrainpeel");
        }
    }
    /* Write the results to the output file: */
    VHistory(VNumber(options), options, prg_name, &list, &list);
    if(!VWriteFile(out_file, list))
        return 1;
    fprintf(stderr, " %s: done.\n", argv[0]);
    return 0;
}
Ejemplo n.º 14
0
int main(int argc, char *argv[]) {
    static VBoolean x_axis = FALSE;
    static VBoolean y_axis = FALSE;
    static VBoolean z_axis = FALSE;
    static VOptionDescRec options[] = {
        { "x", VBooleanRepn, 1, (VPointer) &x_axis, VOptionalOpt, NULL, "Flip x-axis" },
        { "y", VBooleanRepn, 1, (VPointer) &y_axis, VOptionalOpt, NULL, "Flip y-axis" },
        { "z", VBooleanRepn, 1, (VPointer) &z_axis, VOptionalOpt, NULL, "Flip z-axis" },
    };
    FILE *in_file, *out_file;
    VAttrList list;
    VAttrListPosn posn;
    VImage src = NULL, result = NULL;
	char prg_name[100];
	char ver[100];
	getLipsiaVersion(ver, sizeof(ver));
	sprintf(prg_name, "vflip3d V%s", ver);
	fprintf(stderr, "%s\n", prg_name);
	VWarning("It is recommended to use the program vswapdim since vflip3d does not support extended header informations");
    /* Parse command line arguments and identify files: */
    VParseFilterCmd(VNumber(options), options, argc, argv, &in_file, &out_file);
    /* Read the input file: */
    list = VReadFile(in_file, NULL);
    if(! list)
        exit(1);
    /* For each attribute read... */
    for(VFirstAttr(list, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
        if(VGetAttrRepn(& posn) != VImageRepn)
            continue;
        VGetAttrValue(& posn, NULL, VImageRepn, & src);
        result = Flip3dImage(src, NULL, VAllBands, x_axis, y_axis, z_axis);
        if(! result)
            exit(1);
        VSetAttrValue(& posn, NULL, VImageRepn, result);
        VDestroyImage(src);
    }
    /* Write out the results: */
    if(! VWriteFile(out_file, list))
        exit(1);
    fprintf(stderr, "%s: done.\n", argv[0]);
    return 0;
}
Ejemplo n.º 15
0
int main (int argc,char *argv[])
{
  FILE *in_file, *out_file;
  VAttrList list;
  VAttrListPosn posn;
  VImage src=NULL, dest=NULL;
  char prg[50];	
  sprintf(prg,"vthin3d V%s", getVersion());
  fprintf (stderr, "%s\n", prg);
  
  /* Parse command line arguments and identify files: */
  VParseFilterCmd (0,NULL, argc, argv, & in_file, & out_file);
  
  /* Read the input file: */
  list = VReadFile (in_file, NULL);
  if (! list) exit (1);
  fclose(in_file);
  

  /* For each attribute read... */
  for (VFirstAttr (list, & posn); VAttrExists (& posn); VNextAttr (& posn)) {

    if (VGetAttrRepn (& posn) != VImageRepn) continue;
    VGetAttrValue (& posn, NULL, VImageRepn, & src);
    if (VPixelRepn(src) != VBitRepn) continue;

    dest = VThin3d(src, NULL,(int)26);
    if (! dest) exit (1);

    VSetAttrValue (& posn, NULL, VImageRepn, dest);
    VDestroyImage (src);
  }
  

  /* output */
  VHistory(0,NULL,prg,&list,&list);
  if (! VWriteFile (out_file, list)) exit (1);  
  fprintf (stderr, "%s: done.\n", argv[0]);
  return 0;
}
Ejemplo n.º 16
0
int 
main (int argc,char *argv[])
{  
  static VDouble xmin = 0;
  static VDouble xmax = 255;
  static VOptionDescRec  options[] = {
    {"min",VDoubleRepn,1,(VPointer) &xmin,VOptionalOpt,NULL,"lower threshold"},
    {"max",VDoubleRepn,1,(VPointer) &xmax,VOptionalOpt,NULL,"upper threshold"},
  };
  FILE *in_file,*out_file;
  VAttrList list=NULL;
  VAttrListPosn posn;
  VImage src=NULL,dest=NULL;
  char prg[50];	
  sprintf(prg,"vbinarize V%s", getVersion());
  fprintf (stderr, "%s\n", prg);
 
  VParseFilterCmd (VNumber (options),options,argc,argv,&in_file,&out_file);

  if (! (list = VReadFile (in_file, NULL))) exit (1);
  fclose(in_file);

  for (VFirstAttr (list, & posn); VAttrExists (& posn); VNextAttr (& posn)) {
    if (VGetAttrRepn (& posn) != VImageRepn) continue;
    VGetAttrValue (& posn, NULL,VImageRepn, & src);

    dest = VBinarizeImage (src,NULL,xmin,xmax);
    VSetAttrValue (& posn, NULL,VImageRepn,dest);
  }
  if (src == NULL) VError(" no input image found");


  VHistory(VNumber(options),options,prg,&list,&list);

  if (! VWriteFile (out_file, list)) exit (1);
  fprintf (stderr, "%s: done.\n", argv[0]);
  return 0;
}
Ejemplo n.º 17
0
int
main(int argc, char *argv[]) {
    static VString cfile = "";
    static VOptionDescRec  options[] = {
        {"file", VStringRepn, 1, (VPointer) &cfile, VOptionalOpt, NULL, "file"}
    };
    FILE *in_file, *out_file;
    VAttrList list = NULL;
    VAttrListPosn posn;
    VImage design = NULL, dest = NULL;
    char prg_name[100];
	char ver[100];
	getLipsiaVersion(ver, sizeof(ver));
	sprintf(prg_name, "vaddcovariates V%s", ver);
    fprintf(stderr, "%s\n", prg_name);
    VParseFilterCmd(VNumber(options), options, argc, argv, &in_file, &out_file);
    if(!(list = VReadFile(in_file, NULL)))
        exit(1);
    fclose(in_file);
    for(VFirstAttr(list, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
        if(VGetAttrRepn(& posn) != VImageRepn)
            continue;
        VGetAttrValue(& posn, NULL, VImageRepn, & design);
        if(VPixelRepn(design) != VFloatRepn && VPixelRepn(design) != VDoubleRepn)
            continue;
        dest = VAddCovariates(design, cfile);
        VSetAttrValue(& posn, NULL, VImageRepn, dest);
        break;
    }
    if(design == NULL)
        VError(" design matrix not found ");
    /* Output: */
    if(! VWriteFile(out_file, list))
        exit(1);
    fprintf(stderr, " %s: done.\n", argv[0]);
    return 0;
}
Ejemplo n.º 18
0
int
main (int argc,char *argv[])
{
  static VString  filename = "";
  static VString  filename1 = "";
  static VString  filename2 = "";
  static VShort   first  = 2;
  static VShort   length = 0;
  static VShort   type = 0;
  static VShort   minval = 0;
  static VShort   nproc = 4;
  static VOptionDescRec  options[] = {
    {"in1",VStringRepn,1,(VPointer) &filename1,VRequiredOpt,NULL,"first input file"},
    {"in2",VStringRepn,1,(VPointer) &filename2,VRequiredOpt,NULL,"second input file"},
    {"mask",VStringRepn,1,(VPointer) &filename,VRequiredOpt,NULL,"mask"},
    {"type",VShortRepn,1,(VPointer) &type,VOptionalOpt,TYPDict,"type of concordance measure"},
    {"minval",VShortRepn,1,(VPointer) &minval,VOptionalOpt,NULL,"signal threshold"},
    {"first",VShortRepn,1,(VPointer) &first,VOptionalOpt,NULL,"first timestep to use"},
    {"length",VShortRepn,1,(VPointer) &length,VOptionalOpt,NULL,
     "length of time series to use, '0' to use full length"},
    {"j",VShortRepn,1,(VPointer) &nproc,VOptionalOpt,NULL,"number of processors to use, '0' to use all"}
  };
  FILE *out_file,*fp;
  VAttrList list=NULL,list1=NULL,list2=NULL,out_list=NULL;
  VAttrListPosn posn;
  VImage mask=NULL,map=NULL,dest=NULL,disc=NULL;
  float *A1=NULL,*A2=NULL,u=0,tiny=1.0e-6;
  int b,r,c;
  char *prg = "vccm2";

  VParseFilterCmd (VNumber (options),options,argc,argv,NULL,&out_file);
  if (type > 3) VError("illegal type");


  /*
  ** read mask
  */
  fp = VOpenInputFile (filename, TRUE);
  list = VReadFile (fp, NULL);
  if (! list) VError("Error reading mask file");
  fclose(fp);

  for (VFirstAttr (list, & posn); VAttrExists (& posn); VNextAttr (& posn)) {
    if (VGetAttrRepn (& posn) != VImageRepn) continue;
    VGetAttrValue (& posn, NULL,VImageRepn, & mask);
    if (VPixelRepn(mask) == VFloatRepn || VPixelRepn(mask) == VDoubleRepn) {
      mask = NULL;
      continue;
    }
  }
  if (mask == NULL) VError(" no mask found");


  /* read files */
  fp = VOpenInputFile (filename1, TRUE);
  list1 = VReadFile (fp, NULL);
  if (! list1) VError("Error reading 1st input file");
  fclose(fp);

  fp = VOpenInputFile (filename2, TRUE);
  list2 = VReadFile (fp, NULL);
  if (! list2) VError("Error reading 2nd input file");
  fclose(fp);


  /* get voxel map */
  map = GetMap(list1,list2,mask,minval);


 /* omp-stuff */
#ifdef _OPENMP
  int num_procs=omp_get_num_procs();
  if (nproc > 0 && nproc < num_procs) num_procs = nproc;
  printf("using %d cores\n",(int)num_procs);
  omp_set_num_threads(num_procs);
#endif /* _OPENMP */


  /* compute corr matrices */
  A1 = VCorrMatrix(list1,map,first,length);
  A2 = VCorrMatrix(list2,map,first,length);


  /* get concordance between two corr matrices */
  dest = VCCM2(A1,A2,map,(int)type);


  /* invert to get discordant map */
  disc = VCreateImageLike(dest);
  VFillImage(disc,VAllBands,0);

  if (type < 2) {
    for (b=0; b<VImageNBands(dest); b++) {
      for (r=0; r<VImageNRows(dest); r++) {
	for (c=0; c<VImageNColumns(dest); c++) {
	  if (VGetPixel(mask,b,r,c) < 1) continue;
	  u = VPixel(dest,b,r,c,VFloat);
	  if (u < tiny) continue;
	  VPixel(disc,b,r,c,VFloat) = 1-u;
	} 
      }
    }
  }


  /* output */
  out_list = VCreateAttrList();
  VHistory(VNumber(options),options,prg,&list,&out_list);
  VAppendAttr(out_list,"concordant",NULL,VImageRepn,dest);
  if (type < 2) VAppendAttr(out_list,"discordant",NULL,VImageRepn,disc);
  if (! VWriteFile (out_file, out_list)) exit (1);
  fprintf (stderr, "%s: done.\n", argv[0]);
  return 0;
}
Ejemplo n.º 19
0
int
main(int argc, char *argv[]) {
    static VArgVector in_files;
    static VString out_filename;
    static VBoolean in_found, out_found;
    static VOptionDescRec  options[] = {
        {"in", VStringRepn, 0, & in_files, & in_found, NULL, "Input files" },
        {"out", VStringRepn, 1, & out_filename, & out_found, NULL, "Output file" }
    };
    FILE *fp = NULL;
    VStringConst in_filename;
    VAttrList list = NULL, out_list = NULL;
    VImage *design = NULL, tmp = NULL, dest = NULL;
    VAttrListPosn posn;
    int  i, nimages;
    char prg_name[100];
	char ver[100];
	getLipsiaVersion(ver, sizeof(ver));
	sprintf(prg_name, "vcatdesign V%s", ver);
    fprintf(stderr, "%s\n", prg_name);
    /* Parse command line arguments: */
    if(! VParseCommand(VNumber(options), options, & argc, argv) ||
            ! VIdentifyFiles(VNumber(options), options, "in", & argc, argv, 0) ||
            ! VIdentifyFiles(VNumber(options), options, "out", & argc, argv, -1))
        goto Usage;
    if(argc > 1) {
        VReportBadArgs(argc, argv);
Usage:
        VReportUsage(argv[0], VNumber(options), options, NULL);
        exit(EXIT_FAILURE);
    }
    /* Read each input file */
    nimages = in_files.number;
    design = (VImage *) VMalloc(sizeof(VImage) * nimages);
    for(i = 0; i < nimages; i++) {
        in_filename = ((VStringConst *) in_files.vector)[i];
        fprintf(stderr, " reading:  %s\n", in_filename);
        fp = VOpenInputFile(in_filename, TRUE);
        list = VReadFile(fp, NULL);
        if(! list)
            VError("Error reading file %s", in_filename);
        fclose(fp);
        for(VFirstAttr(list, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
            if(VGetAttrRepn(& posn) != VImageRepn)
                continue;
            VGetAttrValue(& posn, NULL, VImageRepn, & tmp);
            if(VPixelRepn(tmp) == VFloatRepn || VPixelRepn(tmp) == VDoubleRepn) {
                design[i] = tmp;
                break;
            }
        }
    }
    /* process */
    dest = ConcatDesigns(design, nimages);
    out_list = VCreateAttrList();
    VAppendAttr(out_list, "image", NULL, VImageRepn, dest);
    /* Output: */
    VHistory(VNumber(options), options, prg_name, &list, &out_list);
    fp = VOpenOutputFile(out_filename, TRUE);
    if(!fp)
        VError(" error opening outout file %s", out_filename);
    if(! VWriteFile(fp, out_list))
        exit(1);
    fprintf(stderr, "%s: done.\n", argv[0]);
    return 0;
}
Ejemplo n.º 20
0
int main(int argc, char *argv[]) {
    /* command line arguments */
    static VString out_filename;
    static VArgVector in_files;
    static VString trans_filename = "";
    static VBoolean in_found, out_found;
    static VShort minval = 0;
    static VBoolean compress = TRUE;
    static VFloat resolution = 3;
    static VOptionDescRec options[] = {
        { "in", VStringRepn, 0, & in_files, & in_found, NULL, "Input file" },
        { "out", VStringRepn, 1, & out_filename, & out_found, NULL, "Output file" },
        {
            "trans", VStringRepn, 1, &trans_filename, VRequiredOpt, NULL,
            "File containing transformation matrix"
        },
        {
            "resolution", VFloatRepn, 1, &resolution, VOptionalOpt, NULL,
            "Output voxel resolution in mm"
        },
        {
            "minval", VShortRepn, 1, &minval, VOptionalOpt, NULL,
            "Signal threshold"
        },
        {
            "compress", VBooleanRepn, 1, &compress, VOptionalOpt, NULL,
            "Whether to compress empty slices"
        }
    };
    VStringConst in_filename;
    FILE *in_file, *out_file, *fp;
    VAttrList list, list1, out_list;
    VAttrListPosn posn;
    VImage trans = NULL;
    VImage *dst_image;
    VImageInfo *imageInfo;
    int nobject = 0, ntimesteps = 0, nbands = 0, nrows = 0, ncols = 0;
    VString ca, cp, extent, str;
    int found = 0;
    int j, dest_nbands;
    char prg_name[100];
	char ver[100];
	getLipsiaVersion(ver, sizeof(ver));
	sprintf(prg_name, "vfunctrans V%s", ver);
    fprintf(stderr, "%s\n", prg_name);
    /* Parse command line arguments: */
    if(! VParseCommand(VNumber(options), options, & argc, argv) ||
            ! VIdentifyFiles(VNumber(options), options, "in", & argc, argv, 0) ||
            ! VIdentifyFiles(VNumber(options), options, "out", & argc, argv, -1))
        goto Usage;
    if(argc > 1) {
        VReportBadArgs(argc, argv);
Usage:
        VReportUsage(argv[0], VNumber(options), options, NULL);
        exit(EXIT_FAILURE);
    }
    if(resolution <= 0)
        VError(" 'resolution' must be an integer > 0");
    /*
    ** Read the transformation matrix:
    */
    fp = VOpenInputFile(trans_filename, TRUE);
    list1 = VReadFile(fp, NULL);
    if(! list1)
        VError("Error reading image");
    fclose(fp);
    for(VFirstAttr(list1, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
        if(VGetAttrRepn(& posn) != VImageRepn)
            continue;
        if(strncmp(VGetAttrName(&posn), "transform", 9) != 0)
            continue;
        VGetAttrValue(& posn, NULL, VImageRepn, & trans);
        break;
    }
    if(trans == NULL)
        VError("transformation matrix not found");
    /*
    ** check attributes
    */
    if(VGetAttr(VImageAttrList(trans), "ca", NULL,
                VStringRepn, (VPointer) & ca) != VAttrFound)
        VError(" attribute 'ca' missing in transformation matrix ");
    if(VGetAttr(VImageAttrList(trans), "cp", NULL,
                VStringRepn, (VPointer) & cp) != VAttrFound)
        VError(" attribute 'cp' missing in transformation matrix ");
    if(VGetAttr(VImageAttrList(trans), "extent", NULL,
                VStringRepn, (VPointer) & extent) != VAttrFound)
        VError(" attribute 'extent' missing in transformation matrix ");
    /*
    ** open in-file
    */
    if(in_files.number < 1 || in_files.number > 1)
        VError(" incorrect number of input files: %d", in_files.number);
    in_filename = ((VStringConst *) in_files.vector)[0];
    if(strcmp(in_filename, "-") == 0)
        in_file = stdin;
    else {
        in_file = fopen((char *)in_filename, "r");
        if(! in_file)
            VError("Failed to open input file %s", in_filename);
    }
    /*
    ** read file info
    */
    if(! ReadHeader(in_file))
        VError("error reading header");
    if(!(list = ReadAttrList(in_file)))
        VError("error reading attr list");
    j = 0;
    for(VFirstAttr(list, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
        j++;
    }
    imageInfo = (VImageInfo *) VMalloc(sizeof(VImageInfo) * (j + 1));
    nobject = nbands = found = 0;
    for(VFirstAttr(list, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
        str = VGetAttrName(&posn);
        if(strncmp(str, "history", 7) == 0) {
            nobject++;
            continue;
        }
        VImageInfoIni(&imageInfo[nbands]);
        if(! VGetImageInfo(in_file, list, nobject, &imageInfo[nbands]))
            VError(" error reading image info");
        if(imageInfo[nbands].repn == VShortRepn) {
            found = 1;
            nrows = imageInfo[nbands].nrows;
            ncols = imageInfo[nbands].ncolumns;
            ntimesteps = imageInfo[nbands].nbands;
            nbands++;
        }
        nobject++;
    }
    fclose(in_file);
    if(!found)
        VError(" couldn't find functional data");
    /*
    ** process each time step
    */
    dst_image = VFunctrans(in_filename, imageInfo, nbands, trans, resolution,
                           ntimesteps, minval, compress, &dest_nbands);
    /*
    ** output
    */
    out_list = VCreateAttrList();
    VHistory(VNumber(options), options, prg_name, &list, &out_list);
    for(j = 0; j < dest_nbands; j++) {
        VAppendAttr(out_list, "image", NULL, VImageRepn, dst_image[j]);
    }
    /* Open and write the output file: */
    if(strcmp(out_filename, "-") == 0)
        out_file = stdout;
    else {
        out_file = fopen(out_filename, "w");
        if(! out_file)
            VError("Failed to open output file %s", out_filename);
    }
    if(!VWriteFile(out_file, out_list) || fclose(out_file))
        VSystemError("error writing output file");
    fprintf(stderr, "\n%s: done.\n", argv[0]);
    return (EXIT_SUCCESS);
}
Ejemplo n.º 21
0
int
main (int argc,char *argv[])
{
  static VString  filename = "";
  static VShort   first  = 2;
  static VShort   length = 0;
  static VFloat   threshold = 0.5;
  static VShort   minval = 0;
  static VShort   nproc = 4;
  static VOptionDescRec  options[] = {
    {"mask",VStringRepn,1,(VPointer) &filename,VOptionalOpt,NULL,"mask"},
    {"minval",VShortRepn,1,(VPointer) &minval,VOptionalOpt,NULL,"signal threshold"},
    {"first",VShortRepn,1,(VPointer) &first,VOptionalOpt,NULL,"first timestep to use"},
    {"length",VShortRepn,1,(VPointer) &length,VOptionalOpt,NULL,"length of time series to use, '0' to use full length"},
    {"threshold",VFloatRepn,1,(VPointer) &threshold,VOptionalOpt,NULL,"threshold"},
    {"j",VShortRepn,1,(VPointer) &nproc,VOptionalOpt,NULL,"number of processors to use, '0' to use all"}
  };
  FILE *in_file,*out_file,*fp;
  VAttrList list=NULL,list1=NULL,out_list=NULL;
  VAttrListPosn posn;
  VImage mask=NULL;
  char *prg = "vncm";

  VParseFilterCmd (VNumber (options),options,argc,argv,&in_file,&out_file);


  /*
  ** read mask
  */
  fp = VOpenInputFile (filename, TRUE);
  list1 = VReadFile (fp, NULL);
  if (! list1) VError("Error reading mask file");
  fclose(fp);

  for (VFirstAttr (list1, & posn); VAttrExists (& posn); VNextAttr (& posn)) {
    if (VGetAttrRepn (& posn) != VImageRepn) continue;
    VGetAttrValue (& posn, NULL,VImageRepn, & mask);
    if (VPixelRepn(mask) != VBitRepn && VPixelRepn(mask) != VUByteRepn && VPixelRepn(mask) != VShortRepn) {
      mask = NULL;
      continue;
    }
  }
  if (mask == NULL) VError(" no mask found");


  /*
  ** read functional data
  */
  if (! (list = VReadFile (in_file, NULL))) exit (1);
  fclose(in_file);

  /* omp-stuff */
#ifdef _OPENMP
  int num_procs=omp_get_num_procs();
  if (nproc > 0 && nproc < num_procs) num_procs = nproc;
  printf("using %d cores\n",(int)num_procs);
  omp_set_num_threads(num_procs);
#endif /* _OPENMP */

  /*
  ** process
  */
  out_list = VNCM(list,mask,minval,first,length,threshold);
  VHistory(VNumber(options),options,prg,&list,&out_list);
  if (! VWriteFile (out_file, out_list)) exit (1);
  fprintf (stderr, "%s: done.\n", argv[0]);
  return 0;
}
Ejemplo n.º 22
0
int main(int argc, char *argv[]) {
    static VArgVector in_files;
    static VString  out_filename;
    static VBoolean level  = FALSE;
    static VBoolean zscore = FALSE;
    static VBoolean in_found, out_found;
    static VOptionDescRec options[] = {
        {
            "in", VStringRepn, 0, & in_files,  & in_found, NULL,
            "Contrast images"
        },
        {
            "out", VStringRepn, 1, & out_filename, & out_found, NULL,
            "Output file"
        },
        {
            "level", VBooleanRepn, 1, & level, VOptionalOpt, NULL,
            "Whether to produce output to be used for 3rd level analysis"
        }
        /*    { "zscore", VBooleanRepn, 1, & zscore, VOptionalOpt, NULL,
          "Whether to produce z-scores as output"} */
    };
    FILE *f;
    VStringConst in_filename;
    VAttrList list, out_list;
    VAttrListPosn posn;
    VImage src = NULL;
    VImage cbeta_images[N], sd_images[N];
    int i, nimages = 0;
    VString str = NULL;
    char prg_name[100];
	char ver[100];
	getLipsiaVersion(ver, sizeof(ver));
	sprintf(prg_name, "vbayes V%s", ver);
    fprintf(stderr, "%s\n", prg_name);
    /* Parse command line arguments: */
    if(! VParseCommand(VNumber(options), options, & argc, argv) ||
            ! VIdentifyFiles(VNumber(options), options, "in", & argc, argv, 0) ||
            ! VIdentifyFiles(VNumber(options), options, "out", & argc, argv, -1))
        goto Usage;
    if(argc > 1) {
        VReportBadArgs(argc, argv);
Usage:
        VReportUsage(argv[0], VNumber(options), options, NULL);
        exit(EXIT_FAILURE);
    }
    nimages = in_files.number;
    fprintf(stderr, "Processing %d input files\n\n", nimages);
    if(nimages >= N)
        VError("Too many input images, max: %d", N);
    if(nimages == 0)
        VError("Input images missing");
    /* loop through all input files */
    for(i = 0; i < nimages; i++) {
        in_filename = ((VStringConst *) in_files.vector)[i];
        fprintf(stderr, "%s\n", in_filename);
        f = fopen((char *)in_filename, "r");
        if(! f)
            VError("Failed to open input file %s", in_filename);
        if(!(list = VReadFile(f, NULL)))
            exit(EXIT_FAILURE);
        fclose(f);
        for(VFirstAttr(list, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
            if(VGetAttrRepn(& posn) != VImageRepn)
                continue;
            VGetAttrValue(& posn, NULL, VImageRepn, & src);
            if(VPixelRepn(src) != VFloatRepn)
                continue;
            VGetAttr(VImageAttrList(src), "modality", NULL, VStringRepn, &str);
            if(strcmp(str, "conimg") == 0) {
                cbeta_images[i] = VCopyImage(src, NULL, VAllBands);
            } else if(strcmp(str, "std_dev") == 0 || strcmp(str, "sd") == 0) {
                sd_images[i] = VCopyImage(src, NULL, VAllBands);
            } else
                VError(" Illegal input file! Make sure to use con-images as input");
        }
    }
    /* calculate probabilities */
    out_list = VBayes(cbeta_images, sd_images, nimages, level, zscore);
    if(out_list == NULL)
        VError(" no result");
    /*
    ** output
    */
    VHistory(VNumber(options), options, prg_name, &list, &out_list);
    if(strcmp(out_filename, "-") == 0)
        VError("Output file required");
    f = fopen(out_filename, "w");
    if(! f)
        VError("Failed to open output file %s", out_filename);
    if(! VWriteFile(f, out_list))
        exit(EXIT_FAILURE);
    fprintf(stderr, "\n%s: done \n", argv[0]);
    return EXIT_SUCCESS;
}
Ejemplo n.º 23
0
int
main(int argc, char *argv[]) {
    static VLong   i0      = 5;
    static VLong   maxiter = 200;
    static VLong   step    = 3;
    static VShort  nproc = 4;
    static VString filename = "";
    static VOptionDescRec  options[] = {
        {"tref", VLongRepn, 1, (VPointer) &i0, VOptionalOpt, NULL, "reference time step"},
        {"report", VStringRepn, 1, (VPointer) &filename, VOptionalOpt, NULL, "report file"},
        {"step", VLongRepn, 1, (VPointer) &step, VOptionalOpt, NULL, "Step size (e.g. 2 or 3)"},
        {"iterations", VLongRepn, 1, (VPointer) &maxiter, VOptionalOpt, NULL, "Max number of iterations"}/*,
	{"j", VShortRepn, 1,(VPointer) &nproc, VOptionalOpt, NULL, "number of processors to use, '0' to use al l"} */
    };
    FILE *in_file = NULL, *out_file = NULL;
    VImage motion = NULL;
    VAttrList list = NULL;
    char prg_name[100];
	char ver[100];
	getLipsiaVersion(ver, sizeof(ver));
	sprintf(prg_name, "vmovcorrection V%s", ver);
    fprintf(stderr, "%s\n", prg_name);
    /* parse command line */
    VParseFilterCmd(VNumber(options), options, argc, argv, &in_file, &out_file);
    if(step < 1)
        VError(" illegal step size %d", step);
    if(i0 < 0)
        VError(" illegal reference time step %d", i0);


/*openmp stuff */
/*#ifdef _OPENMP
    int num_procs=omp_get_num_procs();
    if (nproc > 0 && nproc < num_procs) num_procs = nproc;
    printf("using %d cores\n",(int)num_procs);
    omp_set_num_threads(num_procs);
#endif /*OPENMP */

    /* read data */
    if(!(list = VReadFile(in_file, NULL)))
        VError(" error reading data, perhaps insufficient memory ?");
    /* spatial smoothing */
    VSpatialFilter1(list);
    /* estimate motion parameters using smoothed data */
    motion = VMotionCorrection3d(list, i0, step, maxiter);
    /* re-read original data from file */
    VReleaseStorage(list);
    list = NULL;
    rewind(in_file);
    if(!(list = VReadFile(in_file, NULL)))
        VError(" error reading data, perhaps insufficient memory ?");
    fclose(in_file);
    /* apply motion correction */
    VApplyMotionCorrection3d(list, motion, filename);
    /* write output */
    VHistory(VNumber(options), options, prg_name, &list, &list);
    if(! VWriteFile(out_file, list))
        exit(1);
    fprintf(stderr, "%s: done.\n", argv[0]);
    exit(0);
}
Ejemplo n.º 24
0
int main(int argc, char *argv[])
{
  static VLong op = 0;
  static VLong dim = 1;
  static VShort radius = 2;
  static VString mask_filename=" ";
  static VOptionDescRec options[] = {
    { "op", VLongRepn, 1, &op, VOptionalOpt, OPDict,
        "type of operation" },
    { "dim", VLongRepn, 1, &dim, VOptionalOpt, DIMDict,
        "dim of structuring element (2D or 3D)" },
    { "radius", VShortRepn, 1,(VPointer) & radius, 
	VOptionalOpt, NULL,"radius of structuring element" },
    { "file", VStringRepn, 1, & mask_filename, VOptionalOpt, NULL,
      "File containing structuring element" }
  };


  FILE *in_file, *out_file, *mask_file;
  VAttrList list, list2;
  VAttrListPosn posn;
  VImage src=NULL, se=NULL, result, tmp;
  char prg[50];	
  sprintf(prg,"vgreymorph3d V%s", getVersion());
  fprintf (stderr, "%s\n", prg);

  /* Parse command line arguments and identify files: */
  VParseFilterCmd(VNumber(options),options,argc,argv,&in_file,&out_file);

  if (strlen(mask_filename) < 2) {
    if (dim == 0)
      se = VGenSphere2d(radius);
    else if (dim == 1)
      se = VGenSphere3d(radius);
    else
      VError("illegal choice of parameter 'dim' (%d), must be 2 or 3",dim);
  }
  else {
    mask_file = VOpenInputFile (mask_filename, TRUE);
    list2 = VReadFile (mask_file, NULL);
    if (! list2)
      VError("Error reading structuring element");
    fclose(mask_file);
    for (VFirstAttr (list2,&posn); VAttrExists (& posn); VNextAttr (& posn)) {
      if (VGetAttrRepn (& posn) != VImageRepn) continue;
      VGetAttrValue (& posn, NULL, VImageRepn, & se);
      if (VPixelRepn(se) != VBitRepn) 
	VError("Structuring element must be of type VBit"); 
    }
  }


  /* Read the input file: */
  list = VReadFile (in_file, 0); if (! list) exit(1);
  fclose(in_file);

  /* For each attribute read... */
  for (VFirstAttr (list, & posn); VAttrExists (& posn); VNextAttr(& posn)) {

    if (VGetAttrRepn (& posn) != VImageRepn) continue;
    VGetAttrValue (& posn, NULL, VImageRepn, & src);
    
    switch (op) {
    case 0:
      result = VGreyDilation3d(src,se,NULL);
      break;
    case 1:
      result = VGreyErosion3d(src,se,NULL);
      break;
    case 2:
      tmp = VGreyErosion3d(src,se,NULL);
      result = VGreyDilation3d(tmp,se,NULL);
      VDestroyImage(tmp);
      break;
    case 3:
      tmp = VGreyDilation3d(src,se,NULL);
      result = VGreyErosion3d(tmp,se,NULL);
      VDestroyImage(tmp);
      break;
    }
      
    if (! result) exit(1);
    VSetAttrValue(&posn, 0, VImageRepn, result);
    VDestroyImage (src);
  } 
  
  /* Write out the results: */
  VHistory(VNumber(options),options,prg,&list,&list);
  if (! VWriteFile (out_file, list)) exit(1);
  fprintf(stderr, "%s: done.\n", argv[0]);
  return 0;
}
Ejemplo n.º 25
0
int main(int argc, char *argv[]) {
    static VFloat reso   = -1.0;
    static VLong itype   = 0;
    static VBoolean flip = TRUE;
    static VBoolean reorder = TRUE;
    static VOptionDescRec  options[] = {
        {
            "reso", VFloatRepn, 1, (VPointer) &reso,
            VOptionalOpt, NULL, "New voxel resolution in mm, def: -1 means min(1.0,\"best source resolution\")"
        },

        {
            "flip", VBooleanRepn, 1, (VPointer) &flip,
            VOptionalOpt, NULL, "Whether to flip to natural convention"
        },

        {
            "reorder", VBooleanRepn, 1, (VPointer) &reorder,
            VOptionalOpt, NULL, "Whether to reorder axial slices from axial source image"
        },

        {
            "interpolation", VLongRepn, 1, & itype, VOptionalOpt, ITYPDict,
            "Type of interpolation (0: linear, 1: nearest neighbour, 2: cubic spline)"
        }
    };
    FILE *in_file, *out_file;
    VAttrList list;
    VAttrListPosn posn;
    int nobjects = 0;
    VImage src = NULL, dest = NULL, result = NULL;
    int i, b, r, c, nbands, nrows, ncols;
    VString str, newstr, fixpointString, caString, cpString;
    float fix_c, fix_r, fix_b;
    float ca_c, ca_r, ca_b;
    float cp_c, cp_r, cp_b;
    float x, y, z, min;
    VDouble v, scale_band, scale_row, scale_col;
    float scale[3], shift[3];
    /* print information */
    char prg_name[100];
	char ver[100];
	getLipsiaVersion(ver, sizeof(ver));
	sprintf(prg_name, "visotrop V%s", ver);
    fprintf(stderr, "%s\n", prg_name);
    fflush(stderr);
    /* Parse command line arguments: */
    VParseFilterCmd(VNumber(options), options, argc, argv,
                    & in_file, & out_file);
    /* Read source image(s): */
    if(!(list = VReadFile(in_file, NULL)))
        exit(EXIT_FAILURE);
    /* Scale each object: */
    for(VFirstAttr(list, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
        switch(VGetAttrRepn(& posn)) {
        case VImageRepn:
            VGetAttrValue(& posn, NULL, VImageRepn, & src);
            if(VGetAttr(VImageAttrList(src), "voxel", NULL,
                        VStringRepn, (VPointer) & str) == VAttrFound) {
                sscanf(str, "%f %f %f", &x, &y, &z);
                fprintf(stderr, " voxel: %f %f %f\n", x, y, z);
                min = x < y ? x : y;
                min = z < min ? z : min;
                /* if resolution is not set, use default value 1 or
                   smaler value if the image resolution is better */
                if(reso < 0.0)
                    reso = min < 1.0 ? min : 1.0;
                if(reso <= 0.0)
                    exit(EXIT_FAILURE);
                fprintf(stderr, " new resolution: %f \n", reso);
                scale_col  = x / reso;
                scale_row  = y / reso;
                scale_band = z / reso;
                nbands = VImageNBands(src) * scale_band;
                nrows = VImageNRows(src) * scale_row;
                ncols = VImageNColumns(src) * scale_col;
                if(VImageNBands(src) == nbands
                        && VImageNRows(src) == nrows
                        && VImageNColumns(src) == ncols) {
                    itype = 0;
				}
                fprintf(stderr, " interpolation type: %s\n", ITYPDict[itype].keyword);
                fprintf(stderr, " old dim: %3d %3d %3d\n",
                        VImageNBands(src), VImageNRows(src), VImageNColumns(src));
                for(i = 0; i < 3; i++)
                    shift[i] = scale[i] = 0;
                scale[0] = scale_band;
                scale[1] = scale_row;
                scale[2] = scale_col;
                switch(itype) {
                    /* trilinear interpolation resampling */
                case 0:
                    dest = VTriLinearScale3d(src, NULL, (int)nbands, (int)nrows, (int)ncols,
                                             shift, scale);
                    break;
                    /* nearest neightbour resampling */
                case 1:
                    dest = VNNScale3d(src, NULL, (int)nbands, (int)nrows, (int)ncols,
                                      shift, scale);
                    break;
                    /* cubic spline */
                case 2:
                    dest = VCubicSplineScale3d(src, NULL, (int)nbands, (int)nrows, (int)ncols,
                                               shift, scale);
                    break;
                case 3: /* no interpolation, just reshuffle */
                    dest = VCopyImage(src, NULL, VAllBands);
                    break;
                default:
                    VError(" unknown resampling type %d", itype);
                }
                if(! dest)
                    exit(EXIT_FAILURE);
                /*aa 2003/09/11 added function not to rotate siemens data*/
                if(! VGetAttr(VImageAttrList(src), "orientation", NULL,
                              VStringRepn, (VPointer) & str) == VAttrFound)
                    VError(" attribute 'orientation' missing");
                if(strcmp(str, "axial") == 0) {
                    fprintf(stderr, " new dim: %3d %3d %3d\n", nbands, nrows, ncols);
                    result = VCreateImage(nbands, nrows, ncols, VPixelRepn(src));
                    VFillImage(result, VAllBands, 0);
                    for(b = 0; b < nbands; b++)
                        for(r = 0; r < nrows; r++)
                            for(c = 0; c < ncols; c++) {
                                v = VGetPixel(dest, b, r, c);
                                if((flip == FALSE) && (reorder == FALSE))
                                    VSetPixel(result, b, r, ncols - c - 1, v);
                                else if((flip == TRUE)  && (reorder == FALSE))
                                    VSetPixel(result, b, r, c, v);
                                else if((flip == FALSE) && (reorder == TRUE))
                                    VSetPixel(result, nbands - b - 1, r, ncols - c - 1, v);
                                else if((flip == TRUE)  && (reorder == TRUE))
                                    VSetPixel(result, nbands - b - 1, r, c, v);
                            }
                } else if(strcmp(str, "sagittal") == 0) {
                    /* re-arrange from sagittal to axial orientation */
                    fprintf(stderr, " new dim: %3d %3d %3d\n", nrows, ncols, nbands);
                    result = VCreateImage(nrows, ncols, nbands, VPixelRepn(src));
                    VFillImage(result, VAllBands, 0);
                    for(b = 0; b < nbands; b++)
                        for(r = 0; r < nrows; r++)
                            for(c = 0; c < ncols; c++) {
                                v = VGetPixel(dest, b, r, c);
                                if(flip == FALSE)
                                    VSetPixel(result, r, c, nbands - b - 1, v);
                                else
                                    VSetPixel(result, r, c, b, v);
                            }
                } else if(strcmp(str, "coronal") == 0) {
                    /* re-arrange from coronal to axial orientation */
                    fprintf(stderr, " new dim: %3d %3d %3d\n", nrows, nbands, ncols);
                    result = VCreateImage(nrows, nbands, ncols, VPixelRepn(src));
                    VFillImage(result, VAllBands, 0);
                    for(b = 0; b < nbands; b++)
                        for(r = 0; r < nrows; r++)
                            for(c = 0; c < ncols; c++) {
                                v = VGetPixel(dest, b, r, c);
                                if(flip == FALSE)
                                    VSetPixel(result, r, b, ncols - c - 1, v);
                                else
                                    VSetPixel(result, r, b, c, v);
                            }
                } else {
                    VError(" unknown resampling type %d", itype);
                    exit(EXIT_FAILURE);
                }
                /* copy attributes from source image */
                VCopyImageAttrs(src, result);
                // [TS] 08/03/27
                // correct 'fixpoint', 'ca' and 'cp' if they exist in the source image
                //
                // NOTE:
                // this is only done when no flipping or reordering is requested :-(
                // (WARNING!!!!) '-flip true' actually means that no flipping is done (WHAAAAT ????)
                // and therefore we test for reorder = false and flip = true
                fixpointString = VMalloc(80);
                caString       = VMalloc(80);
                cpString       = VMalloc(80);
                VBoolean _issueWarning = FALSE;
                if(VGetAttr(VImageAttrList(src), "fixpoint", NULL, VStringRepn, (VPointer)&fixpointString) == VAttrFound) {
                    if(reorder == FALSE && flip == TRUE) {
                        sscanf(fixpointString, "%f %f %f", &fix_c, &fix_r, &fix_b);
                        fix_c *= scale_col;
                        fix_r *= scale_row;
                        fix_b *= scale_band;
                        sprintf((char *)fixpointString, "%f %f %f", fix_c, fix_r, fix_b);
                        VSetAttr(VImageAttrList(result), "fixpoint", NULL, VStringRepn, fixpointString);
                    } else {
                        _issueWarning = TRUE;
                    }
                }
                if(VGetAttr(VImageAttrList(src), "ca", NULL, VStringRepn, (VPointer)&caString) == VAttrFound) {
                    if(reorder == FALSE && flip == TRUE) {
                        sscanf(caString, "%f %f %f", &ca_c, &ca_r, &ca_b);
                        ca_c *= scale_col;
                        ca_r *= scale_row;
                        ca_b *= scale_band;
                        sprintf((char *)caString, "%f %f %f", ca_c, ca_r, ca_b);
                        VSetAttr(VImageAttrList(result), "ca", NULL, VStringRepn, caString);
                    } else {
                        _issueWarning = TRUE;
                    }
                }
                if(VGetAttr(VImageAttrList(src), "cp", NULL, VStringRepn, (VPointer)&cpString) == VAttrFound) {
                    if(reorder == FALSE && flip == TRUE) {
                        sscanf(cpString, "%f %f %f", &cp_c, &cp_r, &cp_b);
                        cp_c *= scale_col;
                        cp_r *= scale_row;
                        cp_b *= scale_band;
                        sprintf((char *)cpString, "%f %f %f", cp_c, cp_r, cp_b);
                        VSetAttr(VImageAttrList(result), "cp", NULL, VStringRepn, cpString);
                    } else {
                        _issueWarning = TRUE;
                    }
                }
                if(_issueWarning) {
                    VWarning("Attributes 'fixpoint', 'ca' and 'cp' exist but were not corrected and are therefore likely to be wrong");
                    VWarning("This was caused by setting -flip to false or -reorder to true");
                    VWarning("Please correct the values manually using vattredit");
                }
                /* set the attributes to the changed values */
                newstr = VMalloc(80);
                sprintf((char *)newstr, "%f %f %f", reso, reso, reso);
                VSetAttr(VImageAttrList(result), "voxel", NULL, VStringRepn, newstr);
                VSetAttr(VImageAttrList(result), "orientation", NULL, VStringRepn, "axial");
                if(flip)
                    VSetAttr(VImageAttrList(result), "convention", NULL, VStringRepn, "natural");
                else
                    VSetAttr(VImageAttrList(result), "convention", NULL, VStringRepn, "radiologic");
            }
            VSetAttrValue(& posn, NULL, VImageRepn, result);
            VDestroyImage(src);
            break;
        default:
            continue;
        }
        nobjects++;
    }
    /* Make History */
    VHistory(VNumber(options), options, prg_name, &list, &list);
    /* Write the results to the output file: */
    if(! VWriteFile(out_file, list))
        exit(EXIT_FAILURE);
    fprintf(stderr, "%s: done.\n", argv[0]);
    return EXIT_SUCCESS;
}
Ejemplo n.º 26
0
int main(int argc, char *argv[]) {
    static VArgVector in_files1;
    static VArgVector in_files2;
    static VString out_filename;
    static VShort type = 1;
    static VBoolean gauss = FALSE;
    static VOptionDescRec options[] = {
        {"in1", VStringRepn, 0, & in_files1, VRequiredOpt, NULL, "Input files 1" },
        {"in2", VStringRepn, 0, & in_files2, VRequiredOpt, NULL, "Input files 2" },
        {"type", VShortRepn, 1, (VPointer) &type, VOptionalOpt, TypeDict, "output type"},
        {"gaussianize", VBooleanRepn, 1, (VPointer) &gauss, VOptionalOpt, NULL, "Whether to Gaussianize"},
        {"out", VStringRepn, 1, & out_filename, VRequiredOpt, NULL, "Output file" }
    };
    FILE *fp = NULL;
    VStringConst in_filename, buf1, buf2;
    VAttrList list1, list2, out_list;
    VAttrListPosn posn;
    VString str;
    VImage src, *src1, *src2, dest = NULL;
    int i, nimages, npix = 0;
	char prg_name[100];
	char ver[100];
	getLipsiaVersion(ver, sizeof(ver));
	sprintf(prg_name, "vpaired_ttest V%s", ver);
    fprintf(stderr, "%s\n", prg_name);
    /*
    ** parse command line
    */
    if(! VParseCommand(VNumber(options), options, & argc, argv)) {
        VReportUsage(argv[0], VNumber(options), options, NULL);
        exit(EXIT_FAILURE);
    }
    if(argc > 1) {
        VReportBadArgs(argc, argv);
        exit(EXIT_FAILURE);
    }
    if(type < 0 || type > 1)
        VError(" illegal type");
    /* ini */
    nimages = in_files1.number;
    if(in_files2.number != nimages)
        VError(" inconsistent number of files %d %d", nimages, in_files2.number);
    for(i = 0; i < nimages; i++) {
        buf1 = ((VStringConst *) in_files1.vector)[i];
        buf2 = ((VStringConst *) in_files2.vector)[i];
        fprintf(stderr, "%3d:  %s  %s\n", i, buf1, buf2);
    }
    fprintf(stderr, "\n");
    /* images 1 */
    src1 = (VImage *) VCalloc(nimages, sizeof(VImage));
    for(i = 0; i < nimages; i++) {
        src1[i] = NULL;
        in_filename = ((VStringConst *) in_files1.vector)[i];
        fp = VOpenInputFile(in_filename, TRUE);
        list1 = VReadFile(fp, NULL);
        if(! list1)
            VError("Error reading image");
        fclose(fp);
        for(VFirstAttr(list1, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
            if(VGetAttrRepn(& posn) != VImageRepn)
                continue;
            VGetAttrValue(& posn, NULL, VImageRepn, & src);
            if(VPixelRepn(src) != VFloatRepn)
                continue;
            if(VGetAttr(VImageAttrList(src), "modality", NULL, VStringRepn, &str) == VAttrFound) {
                if(strcmp(str, "conimg") != 0)
                    continue;
            }
            if(i == 0)
                npix = VImageNPixels(src);
            else if(npix != VImageNPixels(src))
                VError(" inconsistent image dimensions");
            src1[i] = src;
            break;
        }
        if(src1[i] == NULL)
            VError(" no contrast image found in %s", in_filename);
    }
    /* images 2 */
    src2 = (VImage *) VCalloc(nimages, sizeof(VImage));
    for(i = 0; i < nimages; i++) {
        src2[i] = NULL;
        in_filename = ((VStringConst *) in_files2.vector)[i];
        fp = VOpenInputFile(in_filename, TRUE);
        list2 = VReadFile(fp, NULL);
        if(! list2)
            VError("Error reading image");
        fclose(fp);
        for(VFirstAttr(list2, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
            if(VGetAttrRepn(& posn) != VImageRepn)
                continue;
            VGetAttrValue(& posn, NULL, VImageRepn, & src);
            if(VPixelRepn(src) != VFloatRepn)
                continue;
            if(VGetAttr(VImageAttrList(src), "modality", NULL, VStringRepn, &str) == VAttrFound) {
                if(strcmp(str, "conimg") != 0)
                    continue;
            }
            if(npix != VImageNPixels(src))
                VError(" inconsistent image dimensions");
            src2[i] = src;
            break;
        }
        if(src2[i] == NULL)
            VError(" no contrast image found in %s", in_filename);
    }
    /* make normally distributed */
    if(gauss) {
        VGaussianize(src1, nimages);
        VGaussianize(src2, nimages);
    }
    /* paired t-test */
    dest = PairedTest(src1, src2, dest, nimages, type);
    /*
    ** output
    */
    out_list = VCreateAttrList();
    VHistory(VNumber(options), options, prg_name, &list1, &out_list);
    VAppendAttr(out_list, "image", NULL, VImageRepn, dest);
    fp = VOpenOutputFile(out_filename, TRUE);
    if(! VWriteFile(fp, out_list))
        exit(1);
    fclose(fp);
    fprintf(stderr, "%s: done.\n", argv[0]);
    exit(0);
}
Ejemplo n.º 27
0
int main(int argc, char *argv[]) {
    static VArgVector in_files1;
    static VArgVector in_files2;
    static VString out_filename;
    static VOptionDescRec options[] = {
        { "in1", VStringRepn, 0, & in_files1, VRequiredOpt, NULL, "Input files 1" },
        { "in2", VStringRepn, 0, & in_files2, VRequiredOpt, NULL, "Input files 2" },
        { "out", VStringRepn, 1, & out_filename, VRequiredOpt, NULL, "Output file" }
    };
    FILE *fp = NULL;
    VStringConst in_filename, buf1, buf2;
    VAttrList list1, list2, out_list;
    VAttrListPosn posn;
    VImage src, *src1, *src2, dest = NULL;
    int i, nimages, npix = 0;
    char prg_name[100];
	char ver[100];
	getLipsiaVersion(ver, sizeof(ver));
	sprintf(prg_name, "vpaired_wilcoxtest V%s", ver);
    fprintf(stderr, "%s\n", prg_name);
    /*
    ** parse command line
    */
    if(! VParseCommand(VNumber(options), options, & argc, argv)) {
        VReportUsage(argv[0], VNumber(options), options, NULL);
        exit(EXIT_FAILURE);
    }
    if(argc > 1) {
        VReportBadArgs(argc, argv);
        exit(EXIT_FAILURE);
    }
    /* number of images */
    nimages = in_files1.number;
    if(in_files2.number != nimages)
        VError(" inconsistent number of files ");
    for(i = 0; i < nimages; i++) {
        buf1 = ((VStringConst *) in_files1.vector)[i];
        buf2 = ((VStringConst *) in_files2.vector)[i];
        fprintf(stderr, "%3d:  %s  %s\n", i, buf1, buf2);
    }
    fprintf(stderr, "\n");
    /*
    ** read images 1
    */
    src1 = (VImage *) VCalloc(nimages, sizeof(VImage));
    for(i = 0; i < nimages; i++) {
        src1[i] = NULL;
        in_filename = ((VStringConst *) in_files1.vector)[i];
        fp = VOpenInputFile(in_filename, TRUE);
        list1 = VReadFile(fp, NULL);
        if(! list1)
            VError("Error reading image");
        fclose(fp);
        for(VFirstAttr(list1, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
            if(VGetAttrRepn(& posn) != VImageRepn)
                continue;
            VGetAttrValue(& posn, NULL, VImageRepn, & src);
            if(VPixelRepn(src) != VFloatRepn)
                continue;
            src1[i] = src;
            break;
        }
        if(i == 0)
            npix = VImageNPixels(src1[i]);
        else if(npix != VImageNPixels(src1[i]))
            VError(" inconsistent image dimensions");
        if(src1[i] == NULL)
            VError(" no image found in %s", in_filename);
    }
    /*
    ** read images 2
    */
    src2 = (VImage *) VCalloc(nimages, sizeof(VImage));
    for(i = 0; i < nimages; i++) {
        src2[i] = NULL;
        in_filename = ((VStringConst *) in_files2.vector)[i];
        fp = VOpenInputFile(in_filename, TRUE);
        list2 = VReadFile(fp, NULL);
        if(! list2)
            VError("Error reading image");
        fclose(fp);
        for(VFirstAttr(list2, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
            if(VGetAttrRepn(& posn) != VImageRepn)
                continue;
            VGetAttrValue(& posn, NULL, VImageRepn, & src);
            if(VPixelRepn(src) != VFloatRepn)
                continue;
            src2[i] = src;
            break;
        }
        if(npix != VImageNPixels(src2[i]))
            VError(" inconsistent image dimensions");
        if(src2[i] == NULL)
            VError(" no image found in %s", in_filename);
    }
    /*
    ** paired wilcoxon test
    */
    dest = PairedWilcoxTest(src1, src2, dest, nimages);
    /*
    ** output
    */
    out_list = VCreateAttrList();
    VHistory(VNumber(options), options, prg_name, &list1, &out_list);
    VAppendAttr(out_list, "image", NULL, VImageRepn, dest);
    fp = VOpenOutputFile(out_filename, TRUE);
    if(! VWriteFile(fp, out_list))
        exit(1);
    fclose(fp);
    fprintf(stderr, "%s: done.\n", argv[0]);
    exit(0);
}
Ejemplo n.º 28
0
int main(int argc, char *argv[]) {
    static VLong objnr = -1;
    static VString name = "";
    static VString value = "";
    static VOptionDescRec options[] = {
        {
            "obj", VLongRepn, 1, (VPointer) &objnr,
            VOptionalOpt, NULL, "object number, all objects (-1)"
        },
        {
            "name", VStringRepn, 1, (VPointer) &name,
            VRequiredOpt, NULL, "attribute name"
        },
        {
            "value", VStringRepn, 1, (VPointer) &value,
            VRequiredOpt, NULL, "attribute value"
        }
    };
    FILE *in_file, *out_file;
    VAttrList list, olist;
    VAttrListPosn posn;
    VImage isrc;
    VGraph gsrc;
    Volumes vsrc;
    VString buf;
    int nobj;
    char prg_name[100];
    char ver[100];
    getLipsiaVersion(ver, sizeof(ver));
    sprintf(prg_name, "vattredit V%s", ver);
    fprintf(stderr, "%s\n", prg_name);
    /* Parse command line arguments and identify files: */
    VParseFilterCmd(VNumber(options), options, argc, argv,
                    &in_file, & out_file);
    /* Read source image(s): */
    if(!(list = VReadFile(in_file, NULL)))
        exit(1);
    /* Process each image: */
    nobj = 0;
    for(VFirstAttr(list, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
        olist = NULL;
        if(nobj == objnr || objnr < 0) {
            if(VGetAttrRepn(& posn) == VImageRepn) {
                VGetAttrValue(& posn, NULL, VImageRepn, & isrc);
                olist = VImageAttrList(isrc);
            } else if(VGetAttrRepn(& posn) == VGraphRepn) {
                VGetAttrValue(& posn, NULL, VGraphRepn, & gsrc);
                olist = VGraphAttrList(gsrc);
            } else if(VGetAttrRepn(& posn) == VolumesRepn) {
                VGetAttrValue(& posn, NULL, VolumesRepn, & vsrc);
                olist = VolumesAttrList(vsrc);
            }
            if(olist != NULL) {
                if(VGetAttr(olist, name, NULL, VStringRepn, &buf) == VAttrFound)
                    fprintf(stderr, " object %3d, old value: %s\n", nobj, buf);
                VSetAttr(olist, name, NULL, VStringRepn, value);
                fprintf(stderr, " object %3d, new value: %s\n", nobj, value);
            }
        }
        nobj++;
    }
    /* Make History */
    VHistory(VNumber(options), options, prg_name, &list, &list);
    /* Write out the results: */
    if(! VWriteFile(out_file, list))
        exit(1);
    fprintf(stderr, "%s: done.\n", argv[0]);
    return 0;
}
Ejemplo n.º 29
0
int
main(int argc, char *argv[]) {
    static VArgVector in_files;
    static VString out_filename;
    static VString filename;
    static VShort minval = 0;
    static VFloat fwhm = 4.0;
    static VOptionDescRec  options[] = {
        {"in", VStringRepn, 0, & in_files, VRequiredOpt, NULL, "Input files" },
        {"out", VStringRepn, 1, & out_filename, VRequiredOpt, NULL, "Output file" },
        {"design", VStringRepn, 1, (VPointer) &filename, VRequiredOpt, NULL, "Design file"},
        {
            "fwhm", VFloatRepn, 1, (VPointer) &fwhm, VOptionalOpt, NULL,
            "FWHM of temporal Gaussian filter in seconds"
        },
        {"minval", VShortRepn, 1, (VPointer) &minval, VOptionalOpt, NULL, "Signal threshold"}
    };
    FILE *fp = NULL, *f = NULL;
    VStringConst in_filename;
    VString ifilename;
    VAttrList list = NULL, list1 = NULL;
    VAttrList out_list = NULL, history_list = NULL;
    VAttrListPosn posn;
    VImage design = NULL;
    ListInfo *linfo;
    VLong itr = 0;
    VFloat sigma = 0, tr = 0;
    int  i, n, nimages;
   char prg_name[100];
	char ver[100];
	getLipsiaVersion(ver, sizeof(ver));
	sprintf(prg_name, "vcolorglm V%s", ver);
    fprintf(stderr, "%s\n", prg_name);
    /*
    ** parse command line
    */
    if(! VParseCommand(VNumber(options), options, & argc, argv)) {
        VReportUsage(argv[0], VNumber(options), options, NULL);
        exit(EXIT_FAILURE);
    }
    if(argc > 1) {
        VReportBadArgs(argc, argv);
        exit(EXIT_FAILURE);
    }
    /*
    ** read design matrix
    */
    fp = VOpenInputFile(filename, TRUE);
    list1 = VReadFile(fp, NULL);
    if(! list1)
        VError("Error reading design file");
    fclose(fp);
    n = 0;
    for(VFirstAttr(list1, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
        if(VGetAttrRepn(& posn) != VImageRepn)
            continue;
        VGetAttrValue(& posn, NULL, VImageRepn, & design);
        if(VPixelRepn(design) != VFloatRepn /* && VPixelRepn(design) != VDoubleRepn */)
            continue;
        n++;
        break;
    }
    if(n == 0)
        VError(" design matrix not found ");
    /*
    ** get pre-coloring info
    */
    if(VGetAttr(VImageAttrList(design), "repetition_time", NULL, VLongRepn, &itr) != VAttrFound)
        VError(" TR info missing in header");
    tr = (float) itr / 1000.0;
    sigma = 0;
    if(tr > 0.001 && fwhm > 0.001) {
        fprintf(stderr, " TR: %.3f seconds\n", tr);
        sigma = fwhm / 2.35482;
        sigma /= tr;
        if(sigma < 0.1) {
            VWarning(" 'fwhm/sigma' too small (%.3f / %.3f), will be set to zero", fwhm, sigma);
            sigma = 0;
        }
    }
    /*
    ** Read each input file
    */
    nimages = in_files.number;
    linfo = (ListInfo *) VMalloc(sizeof(ListInfo) * nimages);
    for(i = 0; i < nimages; i++) {
        in_filename = ((VStringConst *) in_files.vector)[i];
        ifilename = VNewString(in_filename);
        fprintf(stderr, " file:  %s\n", ifilename);
        list = GetListInfo(ifilename, &linfo[i]);
        /* Create history */
        if(i == 0) {
            history_list = VReadHistory(&list);
            if(history_list == NULL)
                history_list = VCreateAttrList();
            VPrependHistory(VNumber(options), options, prg_name, &history_list);
        }
    }

    /*
    ** GLM
    */
    out_list = VRegression(linfo, nimages, minval, design, sigma, itr);


    /*
    **  Output:
    */
    VPrependAttr(out_list, "history", NULL, VAttrListRepn, history_list);
    f = VOpenOutputFile(out_filename, TRUE);
    if(!f)
        VError(" error opening outout file %s", out_filename);
    if(! VWriteFile(f, out_list))
        exit(1);
    fprintf(stderr, "%s: done.\n", argv[0]);
    return 0;
}
Ejemplo n.º 30
0
int main(int argc, char *argv[]) {
    VAttrList list, out_list;
    VImage src;
    VImage dest = NULL;
    VAttrListPosn posn;
    VString str;
    int nimages;
    char historystr[] = "history";
    char prg_name[100];
    char ver[100];
    getLipsiaVersion(ver, sizeof(ver));
    sprintf(prg_name, "vdelcereb V%s", ver);
    fprintf(stderr, "%s\n", prg_name);
    /* Parse command line arguments: */
    if(!VParseCommand(VNumber(options), options, &argc, argv) ||
            ! VIdentifyFiles(VNumber(options), options, "in", & argc, argv, 0) ||
            ! VIdentifyFiles(VNumber(options), options, "out", & argc, argv, -1))
        goto Usage;
    if(argc > 1) {
        VReportBadArgs(argc, argv);
Usage:
        VReportUsage(argv[0], VNumber(options), options, NULL);
        exit(EXIT_FAILURE);
    }
    /* Read source image(s): */
    if(strcmp(in_filename, "-") == 0)
        in_file = stdin;
    else {
        in_file = fopen(in_filename, "r");
        if(! in_file)
            VError("Failed to open input file %s", in_filename);
    }
    if(!(list = VReadFile(in_file, NULL)))
        exit(EXIT_FAILURE);
    fclose(in_file);
    /* Process image */
    nimages = 0;
    for(VFirstAttr(list, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
        if(VGetAttrRepn(& posn) != VImageRepn)
            continue;
        VGetAttrValue(& posn, NULL, VImageRepn, & src);
        dest = VCerebellum(src);
        VSetAttrValue(& posn, NULL, VImageRepn, dest);
        VDestroyImage(src);
        nimages++;
        break;
    }
    /* Create outlist */
    out_list = VCreateAttrList();
    /* Make History */
    VHistory(VNumber(options), options, prg_name, &list, &out_list);
    /*  Alle Attribute (ausser history:) in die neue Liste schreiben: */
    for(VFirstAttr(list, &posn); VAttrExists(&posn); VNextAttr(&posn)) {
        if(strncmp(VGetAttrName(&posn), historystr, strlen(historystr)) == 0)
            continue;
        switch(VGetAttrRepn(&posn)) {
        case VImageRepn:
            VGetAttrValue(&posn, NULL, VImageRepn, &src);
            VAppendAttr(out_list, VGetAttrName(&posn), NULL, VImageRepn, src);
            break;
        case VStringRepn:
            VGetAttrValue(&posn, NULL, VStringRepn, &str);
            VAppendAttr(out_list, VGetAttrName(&posn), NULL, VImageRepn, str);
            break;
        default:
            break;
        }
    }
    /* Write the results to the output file: */
    if(strcmp(out_filename, "-") == 0)
        out_file = stdout;
    else {
        out_file = fopen(out_filename, "w");
        if(! out_file)
            VError("Failed to open output file %s", out_filename);
    }
    if(VWriteFile(out_file, out_list)) {
        if(verbose >= 1)
            fprintf(stderr, "%s: processed %d image%s.\n",
                    argv[0], nimages, nimages == 1 ? "" : "s");
        fprintf(stderr, "%s: done.\n", argv[0]);
    }
    return 0;
}