Пример #1
0
int main(int argc, char* argv[]) {
    // show which dimension this executable is handling
    cout << argv[0] << " with dimension = " << __Dim << endl;

    
    Options opts;
    opts.addOption("-o", "Specify a filename for an output image", SO_REQ_SEP);
    opts.addOption("--fusion", "label fusion from a config", "`--fusion config-file output-file target-image`", SO_REQ_SEP);
    opts.addOption("--overlap", "Compute the overlap ratio (dice|jaccard). This option can take two or arguments. The first argument is a gold standard, and other arguments are multiple number of label images to be compared.", "--overlap dice output-text ref1 ref2-1 ref2-2 ... ref2-n", SO_REQ_SEP);
    opts.addOption("--p2mat", "point list to matrix", SO_NONE);
    opts.addOption("--slice", "extract a slice from 3d volume", "--slice dim index imagefile outputfile", SO_NONE);
    opts.addOption("--imageMerge", "merge 2D images into a 3d volume (--imageMerge output input1 input2 ...)", SO_REQ_SEP);
    opts.addOption("--qa", "extract a slice with a label map", SO_NONE);
    opts.addOption("--config", "[file] use this config file", SO_REQ_SEP);
    opts.addOption("--demons", "run Demons registration", SO_NONE);
    opts.addOption("--separate", "[input] [x] [y] [z] ... separate vector images into individual image files", SO_NONE);
    opts.addOption("--rx", "registration experiments ", SO_NONE);
    opts.addOption("--dots", "--rx --dots generate a series of gaussian dot images", SO_NONE);
    opts.addOption("--sigma", "sigma value [double]", "--sigma 0.8", SO_REQ_SEP);
    opts.addOption("--entropyImage", "Compute an entropy image from a set of given images", "`--entropyImage -o output.nrrd input1.nrrd input2.nrrd ...`", SO_NONE);
    opts.addOption("--test", "Run in a test mode. The test mode is context sensitive depending on the given argument. For example, if `--entropyImage --test` is given, it will automatically provide a set of input images and produce an output into a specific directory.", SO_NONE);
    opts.addOption("--distanceMap", "Compute the Danielsson's distance map. This will also generate distmag.nrrd, x.nrrd, y.nrrd, and z.nrrd that stores the component of the vector distance map for debugging purpose.", "--distanceMap input output-vector output-magnitude", SO_NONE);
    opts.addOption("--help", "print this message", SO_NONE);

    opts.ParseOptions(argc, argv, NULL);
    StringVector& args = opts.GetStringVector("args");

    if (opts.GetBool("--help") || opts.GetBool("-h")) {
        cout << "## ParticleRun Command Line Options" << endl;
        opts.PrintUsage();
        return 0;
    }


    particle2mat(opts, args);
    doSlice(opts, args);
    doSeparate(opts, args);


    if (opts.GetBool("--qa")) {
        executeQARunner(opts, args);
    } else if (opts.GetString("--imageMerge", "") != "" && args.size() > 0) {
        doMerge(opts, args);
    } else if (opts.GetBool("--demons")) {
        executeDemonsRunner(opts, args);
    } else if (opts.GetBool("--rx")) {
        executeRxRunner(opts, args);
    } else if (opts.GetString("--fusion", "") != "") {
        executeLabelFusionRunner(opts, args);
    } else if (opts.GetBool("--entropyImage")) {
        executeEntropyImage(opts, args);
    } else if (opts.GetString("--overlap") == "dice" || opts.GetString("--overlap") == "jaccard") {
        executeVolumeOverlaps(opts, args);
    } else if (opts.GetBool("--distanceMap")) {
        executeComputeDistanceMap(opts, args);
    } else {
        executeParticleRunner(opts, args);
    }
}
Пример #2
0
int main(int argc, char* argv[]) {
    Options argParser;
    argParser.addOption("-i", "print image information as ImageStat --info option", SO_NONE);
    argParser.addOption("-e", "The equation to compute each output pixel.", "-e (A+B)", SO_REQ_SEP);
    argParser.addOption("-o", "output filename (the same data type with the last input)", "-o output.nrrd", SO_REQ_SEP);
    argParser.addOption("-h", "print this message", SO_NONE);

    StringVector args = argParser.ParseOptions(argc, argv, NULL);
    string eq = argParser.GetString("-e");
    string outputFilename = argParser.GetString("-o");
    
    if (argParser.GetBool("-i") && args.size() > 0) {
        ImageInfo lastImageInfo;
        imgIo.ReadCastedImage(args[0], lastImageInfo);
        printf("Filename: %s\n", args[0].c_str());
        printf("Dims: %d %d %d\n", lastImageInfo.dimensions[0], lastImageInfo.dimensions[1], lastImageInfo.dimensions[2]);
        printf("Pixdims: %.2f %.2f %.2f\n", lastImageInfo.spacing[0], lastImageInfo.spacing[1], lastImageInfo.spacing[2]);
        printf("Origins: %.2f %.2f %.2f\n", lastImageInfo.origin[0], lastImageInfo.origin[1], lastImageInfo.origin[2]);
        return 0;
    }

    if (argParser.GetBool("-h") || eq == "" || args.size() == 0 || outputFilename == "") {
        cout << "## kcalc usage \n"
            "\tkcalc [-e equation] [-o output-file] input1:A input2:B ...\n\n"
            "The kcalc performs a pixel-wise arithmetic. The pixel value of each input image is given as variables, A,B,C,D, and E. Several functions implemented in [MuParser](http://muparser.beltoforion.de/) includes +,-,*,/, and ? as well as trigonometric functions.\n\n"
            "Also, there are the min, max values of each input image for the use of scaling and other purposes, which are given as AMIN, AMAX, BMIN, BMAX, and etc.\n\n"
            "Note that the output data type is the same with the last input file. The order of images may produce different results, if images with different types are used.\n\n"
            "Some examples are:\n"
            "* **Addition**: kcalc -e \"(A+B)\" input1.nrrd input2.nrrd -o output.nrrd\n"
            "* **Averaging**: kcalc -e \"(A+B)/2\" input1.nrrd input2.nrrd -o output.nrrd\n"
            "* **Thresholding**: kcalc -e \"(A>10?1:0)\" input.nrrd -o output.nrrd\n"
            "* **Scaling**: -e (A-AMIN)/AMAX*255\n"
            "* **Masking**: -e (A==8?B:0)\n"
            "* ...\n\n"
            "### Options\n";
        argParser.PrintUsage();
        cout << endl;
        return 0;
    }

    if (argParser.GetBool("-2")) {
        cout << "Working on 2D images" << endl;
        ImageIO<Image2D> io2;
        ImageInfo lastImageInfo;
        PixelMathImageFilter<Image2D, Image2D>::Pointer pixelFilter = PixelMathImageFilter<Image2D, Image2D>::New();
        pixelFilter->SetEquation(eq);
        for (int i = 0; i < args.size(); i++) {
            pixelFilter->PushBackInput(io2.ReadCastedImage(args[i], lastImageInfo));
        }
        try {
            pixelFilter->Update();
        } catch (itk::ExceptionObject& e) {
            cout << e.what() << endl;
        }
        io2.WriteCastedImage(outputFilename, pixelFilter->GetOutput(), lastImageInfo.componenttype);
    } else {
        ImageInfo lastImageInfo;
        PixelMathImageFilter<ImageType, ImageType>::Pointer pixelFilter = PixelMathImageFilter<ImageType, ImageType>::New();
        pixelFilter->SetEquation(eq);
        for (int i = 0; i < args.size(); i++) {
            pixelFilter->PushBackInput(imgIo.ReadCastedImage(args[i], lastImageInfo));
        }
        try {
            pixelFilter->Update();
        } catch (itk::ExceptionObject& e) {
            cout << e.what() << endl;
        }

        imgIo.WriteCastedImage(outputFilename, pixelFilter->GetOutput(), lastImageInfo.componenttype);
    }
    return 0;
}