public static RegistrationParameters GetMultipleRegistrationParameters()
        {
            RegistrationParameters parameters = new RegistrationParameters();

            parameters.Type = RegistrationType.Multiple;
            return(parameters);
        }
        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();
        }
        public static RegistrationParameters GetRigidRegistrationParameters()
        {
            RegistrationParameters parameters = new RegistrationParameters();

            parameters.Type = RegistrationType.Rigid;
            parameters.RegistrationDefaultParams = RegistrationDefaultParameters.rigid;
            return(parameters);
        }
        public static RegistrationParameters GetNonRigidRegistrationParameters()
        {
            RegistrationParameters parameters = new RegistrationParameters();

            parameters.Type = RegistrationType.NonRigid;
            parameters.RegistrationDefaultParams = RegistrationDefaultParameters.bspline;
            return(parameters);
        }
        public TransformRGB(sitk.Image movingImage, List <sitk.VectorOfParameterMap> parameterMaps, RegistrationParameters parameters)
        {
            this.movingImage            = movingImage;
            this.parameterMaps          = parameterMaps;
            this.registrationParameters = parameters;

            transformix = new sitk.TransformixImageFilter();
        }
        public static List <sitk.VectorOfParameterMap> PerformMultipleRigidRegistrationForComponents(
            string fixedSegmentedMask,
            string movingSegmentedMask,
            int numberOfComposedTransformations,
            RegistrationParameters parameters)
        {
            // created corresponding masks
            Image <Gray, byte> fixedSegments  = new Image <Gray, byte>(fixedSegmentedMask);
            Image <Gray, byte> movingSegments = new Image <Gray, byte>(movingSegmentedMask);

            VectorOfVectorOfPoint contoursFixed  = new VectorOfVectorOfPoint();
            VectorOfVectorOfPoint contoursMoving = new VectorOfVectorOfPoint();

            CvInvoke.FindContours(fixedSegments, contoursFixed, null, Emgu.CV.CvEnum.RetrType.Ccomp, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple);
            CvInvoke.FindContours(movingSegments, contoursMoving, null, Emgu.CV.CvEnum.RetrType.Ccomp, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple);

            // retireve dict with contour index and area size ordered by size
            Dictionary <int, double> contoursFixedDict  = GetContourAreaDict(ref contoursFixed);
            Dictionary <int, double> contoursMovingDict = GetContourAreaDict(ref contoursMoving);

            List <Tuple <string, string> > filenameOfMaskComponents = new List <Tuple <string, string> >();

            for (int i = 0; i <= numberOfComposedTransformations; i++)
            {
                var contourFixed  = contoursFixed[contoursFixedDict.ElementAt(i).Key];
                var contourMoving = contoursMoving[contoursMovingDict.ElementAt(i).Key];

                Image <Gray, byte> maskFixed  = new Image <Gray, byte>(fixedSegments.Width, fixedSegments.Height, new Gray(0.0));
                Image <Gray, byte> maskMoving = new Image <Gray, byte>(movingSegments.Width, movingSegments.Height, new Gray(0.0));
                CvInvoke.DrawContours(maskFixed, contourFixed, -1, new MCvScalar(255.0), thickness: -1);
                CvInvoke.DrawContours(maskMoving, contourMoving, -1, new MCvScalar(255.0), thickness: -1);

                string filenameFixed  = Path.GetTempPath() + "\\fixed_0" + i + ".png";
                string filenameMoving = Path.GetTempPath() + "\\moving_0" + i + ".png";
                maskFixed.Save(filenameFixed);
                maskMoving.Save(filenameMoving);
                Tuple <string, string> temp = new Tuple <string, string>(filenameFixed, filenameMoving);
                filenameOfMaskComponents.Add(temp);
            }

            sitk.ParameterMap map = GetDefaultParameterMap(parameters.RegistrationDefaultParams);

            List <sitk.VectorOfParameterMap> list = new List <sitk.VectorOfParameterMap>();

            foreach (Tuple <string, string> tuple in filenameOfMaskComponents)
            {
                sitk.Image img01 = ReadWriteUtils.ReadITKImageFromFile(tuple.Item1);
                sitk.Image img02 = ReadWriteUtils.ReadITKImageFromFile(tuple.Item2);
                parameters.ParamMapToUse = map;
                RigidRegistration reg = new RigidRegistration(img01, img02, parameters);
                reg.Execute();
                sitk.VectorOfParameterMap toAdd = new sitk.VectorOfParameterMap(reg.GetTransformationParameterMap());
                list.Add(toAdd);
                reg.Dispose();
            }
            return(list);
        }
        public RegistrationController(RegistrationParameters parameters, BackgroundWorker worker)
        {
            _parameters = parameters;
            _worker     = worker;

            // create output directory
            if (!Directory.Exists(_parameters.OutputDirectory))
            {
                Directory.CreateDirectory(_parameters.OutputDirectory);
            }
        }
        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>
        /// Calculate a composite transform for a list of vector parameter maps.
        /// </summary>
        /// <param name="movingImage">moving image</param>
        /// <param name="parameterMaps">list of vector of parameter maps</param>
        /// <param name="parameters">registration params</param>
        /// <param name="filename">filename of the result image</param>
        public static void WriteCompositeTransformForMovingImage(
            sitk.Image movingImage,
            List <sitk.VectorOfParameterMap> parameterMaps,
            RegistrationParameters parameters,
            string filename)
        {
            sitk.VectorOfParameterMap initialTransform = parameterMaps.First();
            parameterMaps.Remove(initialTransform);

            TransformRGB transform = new TransformRGB(movingImage, parameterMaps, parameters);

            foreach (sitk.VectorOfParameterMap vectorOfMaps in parameterMaps)
            {
                transform.AddVectorOfParameterMap(vectorOfMaps);
            }
            transform.Execute();
            transform.WriteTransformedImage(filename);
        }
 public RigidRegistration(RegistrationParameters parameters) : base(parameters)
 {
     elastix      = new sitk.ElastixImageFilter();
     parameterMap = RegistrationUtils.GetDefaultParameterMap(parameters.RegistrationDefaultParams);
 }
        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();
        }
Beispiel #12
0
 protected RegInitialization(RegistrationParameters parameters)
 {
     this.registrationParameters = parameters;
     this.parameterMap           = parameters.ParamMapToUse;
 }