コード例 #1
0
ファイル: vcovariates.c プロジェクト: Rollmops/lipsia
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;
}
コード例 #2
0
ファイル: vgetcontrast.c プロジェクト: Rollmops/lipsia
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;
}
コード例 #3
0
ファイル: vgen_wilcoxtable.c プロジェクト: Rollmops/lipsia
int
main(int argc, char *argv[]) {
    int i, n, m;
    double W, p;
    char prg_name[100];
    char ver[100];
    getLipsiaVersion(ver, sizeof(ver));
    sprintf(prg_name, "vgen_wilcoxtable V%s", ver);
    fprintf(stderr, "%s\n", prg_name);
    n = atoi(argv[1]);
    m = 0;
    for(i = 1; i <= n; i++)
        m += i;
    printf("float *table%d(void)\n", n);
    printf("{\n");
    printf("  float *table=NULL;\n");
    printf("  table = (float *) malloc(%d*sizeof(float));\n", m);
    for(i = 0; i < m; i++) {
        W = i;
        p = LevelOfSignificanceWXMPSR(W, (long int)n);
        printf("  table[%d]=%f;\n", i, p);
    }
    printf("  return table;\n");
    printf("}\n");
    return 0;
}
コード例 #4
0
ファイル: vsimmat.c プロジェクト: Rollmops/lipsia
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;
}
コード例 #5
0
ファイル: vslicetime.c プロジェクト: Rollmops/lipsia
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);
}
コード例 #6
0
ファイル: vbrainpeel.c プロジェクト: Rollmops/lipsia
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;
}
コード例 #7
0
ファイル: vflip3d.c プロジェクト: Rollmops/lipsia
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;
}
コード例 #8
0
ファイル: vaddcovariates.c プロジェクト: Rollmops/lipsia
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;
}
コード例 #9
0
ファイル: vmovcorrection.c プロジェクト: Rollmops/lipsia
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);
}
コード例 #10
0
ファイル: vcatdesign.c プロジェクト: Rollmops/lipsia
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;
}
コード例 #11
0
ファイル: vfunctrans.c プロジェクト: Rollmops/lipsia
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);
}
コード例 #12
0
ファイル: vdeform.C プロジェクト: Rollmops/lipsia
int main (int argc, char* argv[])
{
   VString        inname;            /* name of input images      */
   VString        outname;           /* name of output images     */
   VString        fieldname;         /* name of deformation field */
   VBoolean       verbose = TRUE;    /* verbose flag              */
   VOptionDescRec options[] =        /* options of program        */
   {
      {"in",      VStringRepn,  1, &inname,    VRequiredOpt, NULL, "Input image"},
      {"out",     VStringRepn,  1, &outname,   VRequiredOpt, NULL, "Deformed output image"},
      {"field",   VStringRepn,  1, &fieldname, VRequiredOpt, NULL, "3D deformation field"},
      {"verbose", VBooleanRepn, 1, &verbose,   VOptionalOpt, NULL, "Show status messages. Optional"}
   };

   VAttrList in_history=NULL;      /* history of input images      */
   VAttrList field_history=NULL;   /* history of deformation field */

   VAttrList In;           /* input images  */
   VImage    Dx, Dy, Dz;   /* field images  */

   VAttrListPosn pos;   /* position in list */
   VImage        in;    /* image in list    */

   float  fx, fy, fz;   /* scaling factors          */
   VImage dx, dy, dz;   /* scaled deformation field */

   VAttrListPosn rider;                         /* functional data rider   */
   int           bands, rows, columns, steps;   /* size of functional data */
   VImage        data;                          /* functional data         */
   VShort        *src, *dest;                   /* functional data pointer */

   VBoolean success;   /* success flag */

   int n, t, z;   /* indices */


   /* print information */
   char prg_name[100];
	char ver[100];
	getLipsiaVersion(ver, sizeof(ver));
	sprintf(prg_name, "vdeform V%s", ver);
  
   fprintf (stderr, "%s\n", prg_name); fflush (stderr);

   /* parse command line */
   if (!VParseCommand (VNumber (options), options, &argc, argv))
   {
      if (argc > 1) VReportBadArgs (argc, argv);
      VReportUsage (argv[0], VNumber (options), options, NULL);
      exit (1);
   }

   /* read input images */
   if (verbose) {fprintf (stderr, "Reading input image '%s' ...\n", inname); fflush (stderr);}
   ReadImages (inname, In, in_history);
   if (!In) exit (2);

   /* read deformation field */
   if (verbose) {fprintf (stderr, "Reading 3D deformation field '%s' ...\n", fieldname); fflush (stderr);}
   ReadField (fieldname, Dx, Dy, Dz, field_history);
   if (!Dx || !Dy || !Dz) exit (3);


   /* deform anatomical images */
   for (VFirstAttr (In, &pos); VAttrExists (&pos); VNextAttr (&pos))
   {
      /* get image */
      VGetAttrValue (&pos, NULL, VImageRepn, &in);
      if (VPixelRepn (in) != VUByteRepn) break;

      /* compare image and field */
      if (verbose) {fprintf (stderr, "Comparing anatomical image and deformation field ...\n"); fflush (stderr);}
      if (!Compatible (in, Dx)) exit (4);
      if (!Compatible (in, Dy)) exit (4);
      if (!Compatible (in, Dz)) exit (4);

      /* deform image */
      if (verbose) {fprintf (stderr, "Deforming anatomical image ...\n"); fflush (stderr);}
      RTTI (in, TrilinearInverseDeform, (in, Dx, Dy, Dz));
      VSetAttrValue (&pos, NULL, VImageRepn, in);
   }


   /* deform map images */
   for (; VAttrExists (&pos); VNextAttr (&pos))
   {
      /* get image */
      VGetAttrValue (&pos, NULL, VImageRepn, &in);
      if (VPixelRepn (in) != VFloatRepn) break;

      /* scale field */
      if (verbose) {fprintf (stderr, "Scaling deformation field ...\n"); fflush (stderr);}
      fx = (float) VImageNColumns (in) / (float) VImageNColumns (Dx);
      fy = (float) VImageNRows    (in) / (float) VImageNRows    (Dy);
      fz = (float) VImageNBands   (in) / (float) VImageNBands   (Dz);
      TrilinearScale<VFloat> (Dx, fx, fy, fz, dx); Multiply<VFloat> (dx, fx);
      TrilinearScale<VFloat> (Dy, fx, fy, fz, dy); Multiply<VFloat> (dy, fy);
      TrilinearScale<VFloat> (Dz, fx, fy, fz, dz); Multiply<VFloat> (dz, fz);

      /* compare image and field */
      if (verbose) {fprintf (stderr, "Comparing map image and deformation field ...\n"); fflush (stderr);}
      if (!Compatible (in, dx)) exit (5);
      if (!Compatible (in, dy)) exit (5);
      if (!Compatible (in, dz)) exit (5);

      /* deform image */
      if (verbose) {fprintf (stderr, "Deforming map image ...\n"); fflush (stderr);}
      RTTI (in, TrilinearInverseDeform, (in, dx, dy, dz));
      VSetAttrValue (&pos, NULL, VImageRepn, in);

      /* clean-up */
      VDestroyImage (dx);
      VDestroyImage (dy);
      VDestroyImage (dz);
   }


   /* deform functional images */
   if (VAttrExists (&pos))
   {
      /* get data size */
      bands = rows = columns = steps = 0;
      for (rider = pos; VAttrExists (&rider); VNextAttr (&rider))
      {
         /* get image */
         VGetAttrValue (&rider, NULL, VImageRepn, &data);
         if (VPixelRepn (data) != VShortRepn) break;

         /* store image size */
         if (VImageNBands   (data) > steps)   steps   = VImageNBands   (data);
         if (VImageNRows    (data) > rows)    rows    = VImageNRows    (data);
         if (VImageNColumns (data) > columns) columns = VImageNColumns (data);
         bands++;
      }
      in = VCreateImage (bands, rows, columns, VShortRepn);

      /* scale field */
      if (verbose) {fprintf (stderr, "Scaling deformation field ...\n"); fflush (stderr);}
      fx = (float) VImageNColumns (in) / (float) VImageNColumns (Dx);
      fy = (float) VImageNRows    (in) / (float) VImageNRows    (Dy);
      fz = (float) VImageNBands   (in) / (float) VImageNBands   (Dz);
      TrilinearScale<VFloat> (Dx, fx, fy, fz, dx); Multiply<VFloat> (dx, fx);
      TrilinearScale<VFloat> (Dy, fx, fy, fz, dy); Multiply<VFloat> (dy, fy);
      TrilinearScale<VFloat> (Dz, fx, fy, fz, dz); Multiply<VFloat> (dz, fz);

      /* compare image and field */
      if (verbose) {fprintf (stderr, "Comparing functional images and deformation field ...\n"); fflush (stderr);}
      if (!Compatible (in, dx)) exit (6);
      if (!Compatible (in, dy)) exit (6);
      if (!Compatible (in, dz)) exit (6);


      /* expand zero images */
      for (rider = pos, z = 0; z < bands; z++, VNextAttr (&rider))
      {
         VGetAttrValue (&rider, NULL, VImageRepn, &data);
         if (FunctionalZero (data))
         {
            FunctionalResize (data, steps, rows, columns);
            VSetAttrValue (&rider, NULL, VImageRepn, data);
         }
      }

      /* deform images */
      if (verbose) {fprintf (stderr, "Deforming functional images ...\n"); fflush (stderr);}
      for (t = 0; t < steps; t++)
      {
         /* collect data */
         dest = (VShort*) VPixelPtr (in, 0, 0, 0);
         for (rider = pos, z = 0; z < bands; z++, VNextAttr (&rider))
         {
            VGetAttrValue (&rider, NULL, VImageRepn, &data);
            src = (VShort*) VPixelPtr (data, t, 0, 0);
            for (n = 0; n < rows * columns; ++n)
               *(dest++) = *(src++);
         }

         /* deform image */
         if (verbose) {fprintf (stderr, "Timestep %d of %d ...\r", t + 1, steps); fflush (stderr);}
         RTTI (in, TrilinearInverseDeform, (in, dx, dy, dz));

         /* spread data */
         src = (VShort*) VPixelPtr (in, 0, 0, 0);
         for (rider = pos, z = 0; z < bands; z++, VNextAttr (&rider))
         {
            VGetAttrValue (&rider, NULL, VImageRepn, &data);
            dest = (VShort*) VPixelPtr (data, t, 0, 0);
            for (n = 0; n < rows * columns; ++n)
               *(dest++) = *(src++);
         }
      }

      /* collapse zero images */
      for (rider = pos, z = 0; z < bands; z++, VNextAttr (&rider))
      {
         VGetAttrValue (&rider, NULL, VImageRepn, &data);
         if (FunctionalZero (data))
         {
            FunctionalResize (data, 1, 1, 1);
            VSetAttrValue (&rider, NULL, VImageRepn, data);
         }
      }


      /* clean-up */
      VDestroyImage (in);
      VDestroyImage (dx);
      VDestroyImage (dy);
      VDestroyImage (dz);

      /* proceed */
      pos = rider;
   }


   /* check list */
   if (VAttrExists (&pos))
   {
      VError ("Remaining image does not contain valid data");
      exit (7);
   }

   /* Prepend History */
   VPrependHistory(VNumber(options),options,prg_name,&in_history);

   /* write output images */
   if (verbose) {fprintf (stderr, "Writing output image '%s' ...\n", outname); fflush (stderr);}
   success = WriteImages (outname, In, in_history);
   if (!success) exit (8);


   /* clean-up 
      VDestroyAttrList (inhistory);
      VDestroyAttrList (fieldhistory);
      VDestroyAttrList (In);
      VDestroyImage (Dx);
      VDestroyImage (Dy);
      VDestroyImage (Dz); */

   /* exit */
   if (verbose) {fprintf (stderr, "Finished.\n"); fflush (stderr);}
   return 0;

} /* main */
コード例 #13
0
ファイル: visotrop.c プロジェクト: Rollmops/lipsia
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;
}
コード例 #14
0
ファイル: vpaired_ttest.c プロジェクト: Rollmops/lipsia
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);
}
コード例 #15
0
ファイル: vcolorglm.c プロジェクト: karda/lipsia
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;
}
コード例 #16
0
ファイル: vROIpaired_ttest.c プロジェクト: Rollmops/lipsia
int main(int argc, char *argv[]) {
    static VArgVector in_files1;
    static VArgVector in_files2;
    static VArgVector mask_file;
    static VArgVector report_file;
    static VOptionDescRec options[] = {
        { "in1", VStringRepn, 0, & in_files1, VRequiredOpt, NULL, "Input files 1" },
        { "in2", VStringRepn, 0, & in_files2, VRequiredOpt, NULL, "Input files 2" },
        { "report", VStringRepn, 0, & report_file, VRequiredOpt, NULL, "Report file" },
        { "mask", VStringRepn, 0, & mask_file, VRequiredOpt, NULL, "Mask file(s)" }
    };
    FILE *fp = NULL;
    VStringConst in_filename;
    VAttrList list1, list2, list3;
    VAttrListPosn posn;
    VString str;
    VImage src, *src1, *src2, *mask;
    int i, nimages = 0, mimages = 0;
    char prg_name[100];
	char ver[100];
	getLipsiaVersion(ver, sizeof(ver));
	sprintf(prg_name, "vROIpaired_ttest V%s", ver);
    fprintf(stderr, "%s\n", prg_name);
    if(!VParseCommand(VNumber(options), options, & argc, argv)) {
        VReportUsage(argv[0], VNumber(options), options, NULL);
        exit(0);
    }
    /* get number of input images */
    nimages = in_files1.number;
    if(in_files2.number != nimages)
        VError(" inconsistent number of files: in1: %d, in2: %d ",
               nimages, in_files2.number);
    mimages = mask_file.number;
    if(nimages != mimages && mimages > 1)
        VError(" inconsistent number of files, images: %d, masks: %d", nimages, mimages);
    /* images 1 */
    src1 = (VImage *) VMalloc(sizeof(VImage) * nimages);
    for(i = 0; i < nimages; i++) {
        src1[i] = NULL;
        in_filename = ((VStringConst *) in_files1.vector)[i];
        fp = VOpenInputFile(in_filename, TRUE);
        if(!fp)
            VError("Error opening file %s", in_filename);
        list1 = VReadFile(fp, NULL);
        if(! list1)
            VError("Error reading file %s", in_filename);
        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;
            }
            src1[i] = src;
            break;
        }
        if(src1[i] == NULL)
            VError(" no contrast image found in %s", in_filename);
    }
    /* images 2 */
    src2 = (VImage *) VMalloc(sizeof(VImage) * nimages);
    for(i = 0; i < nimages; i++) {
        src2[i] = NULL;
        in_filename = ((VStringConst *) in_files2.vector)[i];
        fp = VOpenInputFile(in_filename, TRUE);
        if(!fp)
            VError("Error opening file %s", in_filename);
        list2 = VReadFile(fp, NULL);
        if(! list2)
            VError("Error reading file %s", in_filename);
        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;
            }
            src2[i] = src;
            break;
        }
        if(src2[i] == NULL)
            VError(" no contrast image found in %s", in_filename);
    }
    for(i = 0; i < nimages; i++) {
        fprintf(stderr, "%3d:  %s  %s\n", i,
                ((VStringConst *) in_files1.vector)[i],
                ((VStringConst *) in_files2.vector)[i]);
    }
    fprintf(stderr, "\n");
    /* mask images */
    mask = (VImage *) VMalloc(sizeof(VImage) * mimages);
    for(i = 0; i < mimages; i++) {
        mask[i] = NULL;
        in_filename = ((VStringConst *) mask_file.vector)[i];
        fp = VOpenInputFile(in_filename, TRUE);
        if(!fp)
            VError("Error opening file %s", in_filename);
        list3 = VReadFile(fp, NULL);
        if(! list3)
            VError("Error reading file", in_filename);
        fclose(fp);
        for(VFirstAttr(list3, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
            if(VGetAttrRepn(& posn) != VImageRepn)
                continue;
            VGetAttrValue(& posn, NULL, VImageRepn, & src);
            if(VPixelRepn(src) != VUByteRepn)
                mask[i] = VConvertImageCopy(src, NULL, VAllBands, VUByteRepn);
            else
                mask[i] = src;
            break;
        }
        if(mask[i] == NULL)
            VError(" mask %d not found", i);
    }
    /* open report_file */
    fp = NULL;
    in_filename = ((VStringConst *) report_file.vector)[0];
    fp = fopen(in_filename, "w");
    if(!fp)
        VError(" error opening file %s", in_filename);
    /* paired t-test in ROIs */
    VROIpaired_ttest(src1, src2, mask, nimages, mimages, fp);
    exit(0);
}
コード例 #17
0
ファイル: vbayes.c プロジェクト: Rollmops/lipsia
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;
}
コード例 #18
0
ファイル: vattredit.c プロジェクト: Rollmops/lipsia
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;
}
コード例 #19
0
ファイル: vpaired_wilcoxtest.c プロジェクト: Rollmops/lipsia
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);
}
コード例 #20
0
ファイル: vdelcereb.c プロジェクト: tibu-mpg/Lipsia
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;
}
コード例 #21
0
ファイル: vlview.C プロジェクト: Rollmops/lipsia
/* the main routine */
int main (int argc,char *argv[]) {
  QApplication::setColorSpec( QApplication::ManyColor );                                                                                  

  /* initialize preferences variables */
  pr = prefsini();

  /* write out the revision string */
  char prg_name[100];
	char ver[100];
	getLipsiaVersion(ver, sizeof(ver));
	sprintf(prg_name, "vlview V%s", ver);
  
  fprintf (stderr, "%s\n", prg_name);
    
  /* Parse command line arguments and identify files: */
  if (! VParseCommand (VNumber (options), options, & argc, argv) ||
      ! VIdentifyFiles (VNumber (options), options, "in", & argc, argv, 0))
    goto Usage;
  if (argc > 1) {
    VReportBadArgs (argc, argv);
  Usage:	VReportUsage (argv[0], VNumber (options), options, NULL);
    exit (EXIT_FAILURE);
  }

  /* A. Hagert: exceptions */
  if (mincol == 123456 && maxcol == 123456) { pr->col_min = 0; pr->col_max = 0; }
  else if (mincol != 123456 && maxcol == 123456) 
    { printf("ERROR: maximum not given -> ignoring given minimum.\n"); pr->col_min = 0; pr->col_max = 0; }
  else if (mincol == 123456 && maxcol != 123456)
    { printf("ERROR: minimum not given -> ignoring given maximum.\n"); pr->col_min = 0; pr->col_max = 0; }
  else if (mincol<=maxcol) { pr->col_min=mincol; pr->col_max=maxcol; }
  else { printf("ERROR: given minimum is higher than maximum -> ignoring both.\n"); 
  pr->col_min = 0; pr->col_max = 0; 
  }
  
  /* set verbose option to prefs */
  pr->prg_name=prg_name;
  pr->verbose=verbose;
  pr->raw=rawfile;
  pr->des=desfile;
  pr->beta=betafile;
  pr->colortable=colortable_filename;
  pr->graph[0]=graphfile;
  pr->files=0;
  pr->infilenum=in_files.number;
  pr->zmapfilenum=zmap_files.number;
  pr->thresh=th11;
  pr->background0=background[0];
  pr->background1=background[1];

  if (pr->infilenum > pr->zmapfilenum)
    pr->files=pr->infilenum;
  else 
    pr->files=pr->zmapfilenum;

  if (pr->infilenum==0) 
    VError("No infile specified");

  if (pr->files>1) 
    VError("Use 'vlv' for visualization of data sets > 1");

  /* get the number of graphs (pr->g_number) */
  myload_.testFiles();

  /* initialize open the main window */
  QApplication a( argc, argv );
  lView ww;
  
  a.setMainWidget( &ww );
  ww.show();
  

  return a.exec();
  /* end of the program */
}
コード例 #22
0
ファイル: vtomat.c プロジェクト: Rollmops/lipsia
int
main(int argc, char *argv[]) {
    /* Command line options: */
    static VString mat = NULL;
    static VBoolean funconly = FALSE;
    static VOptionDescRec  options[] = {
        {"out", VStringRepn, 1, &mat, VRequiredOpt, 0, "Matfile"},
        {"funconly", VBooleanRepn, 1, &funconly, VOptionalOpt, 0, "Functional data only (in one single 4D-object)"},
    };
    FILE *in_file;
    VAttrList in_list;
    VAttrListPosn posn;
    VImage src = NULL;
    VBit     *bit_pp = NULL, *pbSRC = NULL;
    VShort *short_pp = NULL, *psSRC = NULL;
    VUByte *ubyte_pp = NULL, *puSRC = NULL;
    VFloat *float_pp = NULL, *pfSRC = NULL;
    VDouble *double_pp = NULL, *pdSRC = NULL;
    VString mode = NULL, name = NULL;
    mxArray *SRC = NULL;
    MATFile *fp;
    int n = 0, dims[4];
    int bands = 0, rows = 0, cols = 0;
    char prg_name[100];
	char ver[100];
	getLipsiaVersion(ver, sizeof(ver));
	sprintf(prg_name, "vtomat 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 */ NULL);
    /* Read the input file */
    in_list = VReadFile(in_file, NULL);
    if(!in_list)
        exit(1);
    /* strings */
    mode = (VString)malloc(sizeof(char));
    name = (VString)malloc(sizeof(char) * 50);
    strcpy(mode, "w");
    fp = matOpen(mat, mode);
    if(funconly == TRUE) {
        /*******************************************************************
         *                                                                 *
         *                   L O O P over objects in vista file            *
         *                                                                 *
         *******************************************************************/
        n = 0;
        for(VFirstAttr(in_list, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
            if(VGetAttrRepn(& posn) != VImageRepn)
                continue;
            VGetAttrValue(& posn, NULL, VImageRepn, & src);
            if(VPixelRepn(src) == VShortRepn) {
                if(bands < 2)
                    bands = VImageNBands(src);
                if(rows  < 2)
                    rows  = VImageNRows(src);
                if(cols  < 2)
                    cols  = VImageNColumns(src);
                if(bands != VImageNBands(src))
                    VError("Different bands in functional objects");
                if(rows  != VImageNRows(src))
                    VError("Different rows  in functional objects");
                if(cols  != VImageNColumns(src))
                    VError("Different cols  in functional objects");
                n++;
            }
        }
        /*dimensions */
        dims[3] = n;
        dims[2] = bands;
        dims[1] = rows;
        dims[0] = cols;
        SRC   = mxCreateNumericArray(4, dims, mxINT16_CLASS, mxREAL);
        psSRC = (VShort *) mxGetPr(SRC);
        /* copy data to SRC */
        for(VFirstAttr(in_list, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
            if(VGetAttrRepn(& posn) != VImageRepn)
                continue;
            VGetAttrValue(& posn, NULL, VImageRepn, & src);
            if(VPixelRepn(src) == VShortRepn) {
                short_pp = (VShort *) VPixelPtr(src, 0, 0, 0);
                memcpy(psSRC, short_pp, sizeof(VShort) * dims[0] * dims[1] * dims[2]);
                psSRC += dims[0] * dims[1] * dims[2];
            }
        }
        /* save data into file */
        if(matPutVariable(fp, "fnc", SRC))
            VError("Could not save data in MATLAB file");
        /* destroy array */
        mxDestroyArray(SRC);
    } else {
        /*******************************************************************
         *                                                                 *
         *                   L O O P over objects in vista file            *
         *                                                                 *
         *******************************************************************/
        n = 0;
        for(VFirstAttr(in_list, & posn); VAttrExists(& posn); VNextAttr(& posn)) {
            if(VGetAttrRepn(& posn) != VImageRepn)
                continue;
            VGetAttrValue(& posn, NULL, VImageRepn, & src);
            /*dimensions */
            dims[3] = 1;
            dims[2] = VImageNBands(src);
            dims[1] = VImageNRows(src);
            dims[0] = VImageNColumns(src);
            sprintf(name, "obj%d\0", n);
            /* Bit ONLY */
            if(VPixelRepn(src) == VBitRepn) {
                SRC    = mxCreateNumericArray(3, dims, mxLOGICAL_CLASS, mxREAL);
                pbSRC  = (VBit *) mxGetPr(SRC);
                bit_pp = (VBit *) VPixelPtr(src, 0, 0, 0);
                memcpy(pbSRC, bit_pp, sizeof(VBit) * dims[0] * dims[1] * dims[2]);
            }
            /* Short ONLY */
            if(VPixelRepn(src) == VShortRepn) {
                SRC      = mxCreateNumericArray(3, dims, mxINT16_CLASS, mxREAL);
                psSRC    = (VShort *) mxGetPr(SRC);
                short_pp = (VShort *) VPixelPtr(src, 0, 0, 0);
                memcpy(psSRC, short_pp, sizeof(VShort) * dims[0] * dims[1] * dims[2]);
            }
            /* UByte ONLY */
            if(VPixelRepn(src) == VUByteRepn) {
                SRC      = mxCreateNumericArray(3, dims, mxUINT8_CLASS, mxREAL);
                puSRC    = (VUByte *) mxGetPr(SRC);
                ubyte_pp = (VUByte *) VPixelPtr(src, 0, 0, 0);
                memcpy(puSRC, ubyte_pp, sizeof(VUByte) * dims[0] * dims[1] * dims[2]);
            }
            /* Float ONLY */
            if(VPixelRepn(src) == VFloatRepn) {
                SRC      = mxCreateNumericArray(3, dims, mxSINGLE_CLASS, mxREAL);
                pfSRC    = (VFloat *) mxGetPr(SRC);
                float_pp = (VFloat *) VPixelPtr(src, 0, 0, 0);
                memcpy(pfSRC, float_pp, sizeof(VFloat) * dims[0] * dims[1] * dims[2]);
            }
            /* Double ONLY */
            if(VPixelRepn(src) == VDoubleRepn) {
                SRC       = mxCreateNumericArray(3, dims, mxDOUBLE_CLASS, mxREAL);
                pdSRC     = (VDouble *) mxGetPr(SRC);
                double_pp = (VDouble *) VPixelPtr(src, 0, 0, 0);
                memcpy(pdSRC, double_pp, sizeof(VDouble) * dims[0] * dims[1] * dims[2]);
            }
            /* save data into file */
            if(matPutVariable(fp, name, SRC))
                VError("Could not save data in MATLAB file");
            /* destroy array */
            mxDestroyArray(SRC);
            n++;
        }
    }
    /* Terminate */
    matClose(fp);
    return 0;
}