コード例 #1
0
        public static INifti <float> ANTSRegistration(INifti <float> floating, INifti <float> reference, DataReceivedEventHandler updates = null)
        {
            // Setup our temp file names.
            string niftiInPath  = Path.GetFullPath(Tools.TEMPDIR + floating.GetHashCode() + ".antsrego.in.nii");
            string niftiRefPath = Path.GetFullPath(Tools.TEMPDIR + floating.GetHashCode() + ".antsrego.ref.nii");

            floating.WriteNifti(niftiInPath);
            reference.WriteNifti(niftiRefPath);

            string niftiOutPath = Path.GetFullPath(ANTSRegistration(niftiInPath, niftiRefPath, updates));

            var output = floating.DeepCopy();

            output = output.ReadNifti(niftiOutPath);

            return(output);
        }
コード例 #2
0
        /// <summary>
        /// Uses the CMTK registration and reformatx tools to register and reslice the floating nifti to match the reference nifti.
        /// </summary>
        /// <param name="floating">Nifti to be registered</param>
        /// <param name="reference">Reference nifti</param>
        /// <param name="updates">Event handler for updates from the toolchain...</param>
        /// <returns></returns>
        public static INifti <float> CMTKRegistration(INifti <float> floating, INifti <float> reference, DataReceivedEventHandler updates = null)
        {
            // Setup our temp file names.
            string niftiInPath  = Tools.TEMPDIR + floating.GetHashCode() + ".cmtkrego.in.nii";
            string niftiRefPath = Tools.TEMPDIR + floating.GetHashCode() + ".cmtkrego.ref.nii";
            string niftiOutPath = Tools.TEMPDIR + floating.GetHashCode() + ".cmtkrego.out.nii";

            // Write nifti to temp directory.
            floating.WriteNifti(niftiInPath);
            reference.WriteNifti(niftiRefPath);

            niftiOutPath = CMTKRegistration(niftiInPath, niftiRefPath, updates);

            //INifti output = floating.DeepCopy();
            floating.ReadNifti(niftiOutPath);

            return(floating);
        }
コード例 #3
0
ファイル: BrainExtraction.cs プロジェクト: mh-cad/vistarsier
        /// <summary>
        /// Uses the BrainSuite BSE tool to extract the brain from a given INifti.
        /// </summary>
        /// <param name="input">Nifti which contains the brain to be extracted</param>
        /// <param name="updates">Data handler for updates from the BSE tool.</param>
        /// <returns>The INifti containing the extracted brain.</returns>
        public static INifti <float> BrainSuiteBSE(INifti <float> input, DataReceivedEventHandler updates = null)
        {
            // Setup our temp file names.
            string niftiInPath  = Path.GetFullPath(Tools.TEMPDIR + input.GetHashCode() + ".bse.in.nii");
            string niftiOutPath = Path.GetFullPath(Tools.TEMPDIR + input.GetHashCode() + ".bse.out.nii");

            // Write nifti to temp directory.
            input.WriteNifti(niftiInPath);

            var args = $"--auto --trim -i \"{niftiInPath}\" -o \"{niftiOutPath}\"";

            ProcessBuilder.CallExecutableFile(CapiConfig.GetConfig().Binaries.bse, args, outputDataReceived: updates);

            var output = input.DeepCopy(); // Sometimes this messes with the header and gives us a 4-up???

            output.ReadNifti(niftiOutPath);

            return(output);
        }
コード例 #4
0
        /// <summary>
        /// Uses the ANTS implementation of the N4 bias correction algorithm.
        /// </summary>
        /// <param name="input">The input nifti to be corrected</param>
        /// <param name="updates">Event handler for updates from the process</param>
        /// <returns>New, corrected nifti</returns>
        public static INifti <float> AntsN4(INifti <float> input, DataReceivedEventHandler updates = null)
        {
            // Setup our temp file names.
            string niftiInPath  = Path.GetFullPath(Tools.TEMPDIR + input.GetHashCode() + ".antsN4.in.nii");
            string niftiOutPath = Path.GetFullPath(Tools.TEMPDIR + input.GetHashCode() + ".antsN4.out.nii");

            // Write nifti to temp directory.
            input.WriteNifti(niftiInPath);

            var args = $"-i \"{niftiInPath}\" -o \"{niftiOutPath}\"";

            ProcessBuilder.CallExecutableFile(CapiConfig.GetConfig().Binaries.N4BiasFieldCorrection, args, outputDataReceived: updates);

            var output = input.DeepCopy();

            output.ReadNifti(niftiOutPath);
            output.RecalcHeaderMinMax();

            return(output);
        }