/// <summary>
        /// Write transformed image and deformation field to disk
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="transformparams"></param>
        private void WriteTransform(string filename, List <sitk.VectorOfParameterMap> transformparams)
        {
            string resultFilename = ReadWriteUtils.GetOutputDirectory(_parameters) + "\\" + Path.GetFileNameWithoutExtension(filename) + ".png";

            // add transform parameter map to registration parameters
            if (_parameters.TransformationParameterMap.ContainsKey(resultFilename))
            {
                _parameters.TransformationParameterMap.Remove(resultFilename);
            }
            _parameters.TransformationParameterMap.Add(resultFilename, transformparams);

            // read moving image from file
            sitk.Image movingImageToTransform = ReadWriteUtils.ReadITKImageFromFile(filename, sitk.PixelIDValueEnum.sitkVectorUInt8);
            // initialize transform instance
            TransformRGB trans = new TransformRGB(movingImageToTransform, transformparams, _parameters);

            if (_parameters.IsBinaryTransform)
            {
                // for binary reg set interpolation order to zero
                trans.SetInterpolationOrder(0);
            }

            trans.Execute();
            trans.WriteTransformedImage(resultFilename);

            // write deformation field
            sitk.Image deformationField         = trans.GetDeformationField();
            string     filenameDeformationField = ReadWriteUtils.GetOutputDirectory(_parameters, _parameters.Iteration) + "\\deformationField.mhd";

            ReadWriteUtils.WriteSitkImage(deformationField, filenameDeformationField);
            trans.Dispose();
            movingImageToTransform.Dispose();
        }
        /// <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);
        }