private void buttonSave_Click(object sender, EventArgs e) { if (filename == null) { string[] parameters = richTextBox1.Text.Split('\n'); foreach (var param in parameters) { string[] splitted = param.Split(' '); sitk.VectorString vec = GetVectorFromString(param); if (vec != null) { if (Parametermap.ContainsKey(splitted[0])) { Parametermap[splitted[0]] = vec; } else { Parametermap.Add(splitted[0], vec); } } } this.DialogResult = DialogResult.OK; this.Close(); } else { sitk.ElastixImageFilter elx = new sitk.ElastixImageFilter(); elx.WriteParameterFile(Parametermap, filename); elx.Dispose(); } }
public RigidRegistration(sitk.Image fixedImage, sitk.Image movingImage, RegistrationParameters parameters) : base(parameters) { this.fixedImage = ImageUtils.CastImageToFloat32(fixedImage); this.movingImage = ImageUtils.CastImageToFloat32(movingImage); this.registrationParameters = parameters; elastix = new sitk.ElastixImageFilter(); if (parameterMap == null) { parameterMap = RegistrationUtils.GetDefaultParameterMap(parameters.RegistrationDefaultParams); } // set output dir outputDirectory = Path.Combine(registrationParameters.OutputDirectory, registrationParameters.Iteration.ToString()); if (!Directory.Exists(outputDirectory)) { Directory.CreateDirectory(outputDirectory); } elastix.SetOutputDirectory(outputDirectory); //elastix.SetLogFileName(Path.Combine(outputDirectory, registrationParameters.ElastixLogFileName)); elastix.LogToFileOn(); //base.SetGeneralParameters(); }
private sitk.VectorOfParameterMap InvertTransformParameters(string parameterFilename) { sitk.Image fixedImage = ReadWriteUtils.ReadITKImageFromFile(registrationParameters.FixedImageFilename, sitk.PixelIDValueEnum.sitkFloat32); sitk.ElastixImageFilter elastix = null; try { // elastix manual 6.1.6: DisplacementMagnitudePenalty elastix = new sitk.ElastixImageFilter(); elastix.SetInitialTransformParameterFileName(parameterFilename); elastix.SetParameterMap(sitk.SimpleITK.GetDefaultParameterMap("rigid")); elastix.SetFixedImage(fixedImage); elastix.SetMovingImage(fixedImage); elastix.SetParameter("HowToCombineTransforms", "Compose"); elastix.SetParameter("Metric", "DisplacementMagnitudePenalty"); elastix.SetParameter("NumberOfResolutions", "1"); elastix.Execute(); return(elastix.GetTransformParameterMap()); /*sitk.TransformixImageFilter transformix = new sitk.TransformixImageFilter(); * transformix.SetTransformParameterMap(elastix.GetTransformParameterMap()); * transformix.SetTransformParameter("InitialTransformParametersFileName", "NoInitialTransform"); * transformix.Execute();*/ } catch (Exception ex) { Console.WriteLine(ex); return(null); } finally { elastix.Dispose(); fixedImage.Dispose(); } }
public MultipleParameterFileRegistration(sitk.Image fixedImage, sitk.Image movingImage, RegistrationParameters parameters) : base(parameters) { this.fixedImage = ImageUtils.CastImageToFloat32(fixedImage); this.movingImage = ImageUtils.CastImageToFloat32(movingImage); elastix = new sitk.ElastixImageFilter(); for (int i = 0; i < parameters.ParameterFiles.Count; i++) { if (i == 0) { elastix.SetParameterMap(elastix.ReadParameterFile(parameters.ParameterFiles[i])); } else { elastix.AddParameterMap(elastix.ReadParameterFile(parameters.ParameterFiles[i])); } } // set output dir outputDirectory = Path.Combine(registrationParameters.OutputDirectory, "multiple_" + DateTime.Now.ToShortDateString()); if (!Directory.Exists(outputDirectory)) { Directory.CreateDirectory(outputDirectory); } elastix.SetOutputDirectory(outputDirectory); //elastix.SetLogFileName(Path.Combine(outputDirectory, registrationParameters.ElastixLogFileName)); elastix.LogToFileOn(); }
public EditParametersForm(string parameterFilename) { InitializeComponent(); filename = parameterFilename; sitk.ElastixImageFilter elx = new sitk.ElastixImageFilter(); Parametermap = elx.ReadParameterFile(filename); elx.Dispose(); }
public NonRigidRegistration(sitk.Image fixedImage, sitk.Image movingImage, RegistrationParameters parameters) : base(parameters) { // cast images to from pixel type uint to vector of float sitk.CastImageFilter castImageFilter = new sitk.CastImageFilter(); castImageFilter.SetOutputPixelType(sitk.PixelIDValueEnum.sitkVectorFloat32); sitk.Image vector1 = castImageFilter.Execute(fixedImage); sitk.Image vector2 = castImageFilter.Execute(movingImage); sitk.Image tempImage1 = TransformationUtils.GetColorChannelAsImage(vector1, ColorChannel.R); sitk.Image tempImage2 = TransformationUtils.GetColorChannelAsImage(vector2, ColorChannel.R); this.fixedImage = tempImage1; this.movingImage = tempImage2; // initiate elastix and set default registration params elastix = new sitk.ElastixImageFilter(); if (parameterMap == null) { parameterMap = RegistrationUtils.GetDefaultParameterMap(parameters.RegistrationDefaultParams); } // coefficient map is used for penalty term if (parameters.CoefficientMapFilename != null && parameters.NonRigidOptions == MaskedNonRigidRegistrationOptions.BsplineWithPenaltyTermAndCoefficientMap) { RegistrationUtils.ChangeOrAddParamIfNotExist(ref parameterMap, "DilateRigidityImages", RegistrationUtils.GetVectorString("true")); RegistrationUtils.ChangeOrAddParamIfNotExist(ref parameterMap, "FixedRigidityImageName", RegistrationUtils.GetVectorString(parameters.CoefficientMapFilename)); } // coefficient map is used for diffuse registration if (parameters.CoefficientMapFilename != null && parameters.NonRigidOptions == MaskedNonRigidRegistrationOptions.DiffuseRegistration) { RegistrationUtils.ChangeOrAddParamIfNotExist(ref parameterMap, "UseMovingSegmentation", RegistrationUtils.GetVectorString("true")); RegistrationUtils.ChangeOrAddParamIfNotExist(ref parameterMap, "MovingSegmentationFileName", RegistrationUtils.GetVectorString(parameters.CoefficientMapFilename)); } // set output dir and log file outputDirectory = Path.Combine(registrationParameters.OutputDirectory, registrationParameters.Iteration.ToString()); if (!Directory.Exists(outputDirectory)) { Directory.CreateDirectory(outputDirectory); } elastix.SetOutputDirectory(outputDirectory); elastix.SetLogFileName(outputDirectory + registrationParameters.ElastixLogFileName); elastix.LogToConsoleOn(); }
/// <summary> /// Get default parameter map from elastix image filter for registration type. /// </summary> /// <param name="registrationType">registration type</param> /// <returns>default params</returns> private static sitk.ParameterMap GetDefaultRigidParameterMap(RegistrationDefaultParameters registrationType) { using (sitk.ElastixImageFilter elastix = new sitk.ElastixImageFilter()) { sitk.ParameterMap map = elastix.GetDefaultParameterMap(registrationType.ToString()); ChangeOrAddParamIfNotExist(ref map, "Interpolator", GetVectorString("BSplineInterpolator")); ChangeOrAddParamIfNotExist(ref map, "ResampleInterpolator", GetVectorString("FinalBSplineInterpolator")); ChangeOrAddParamIfNotExist(ref map, "FixedImagePyramid", GetVectorString("FixedRecursiveImagePyramid")); ChangeOrAddParamIfNotExist(ref map, "MovingImagePyramid", GetVectorString("MovingRecursiveImagePyramid")); ChangeOrAddParamIfNotExist(ref map, "AutomaticTransformInitialization", GetVectorString("true")); ChangeOrAddParamIfNotExist(ref map, "NumberOfResolutions", GetVectorString("8")); ChangeOrAddParamIfNotExist(ref map, "MaximumNumberOfIterations", GetVectorString("1024")); ChangeOrAddParamIfNotExist(ref map, "NumberOfSpatialSamples", GetVectorString("4096")); ChangeOrAddParamIfNotExist(ref map, "NumberOfSamplesForExactGradient", GetVectorString("4096")); ChangeOrAddParamIfNotExist(ref map, "ImageSampler", GetVectorString("Random")); ChangeOrAddParamIfNotExist(ref map, "BSplineInterpolationOrder", GetVectorString("1")); ChangeOrAddParamIfNotExist(ref map, "FinalBSplineInterpolationOrder", GetVectorString("3")); ChangeOrAddParamIfNotExist(ref map, "Metric", GetVectorString("AdvancedMeanSquares")); return(map); } }
public RigidRegistration(RegistrationParameters parameters) : base(parameters) { elastix = new sitk.ElastixImageFilter(); parameterMap = RegistrationUtils.GetDefaultParameterMap(parameters.RegistrationDefaultParams); }