/// <summary>
        /// Resize image depending on a reference image.
        /// </summary>
        /// <param name="toResize">image</param>
        /// <param name="referenceImage">reference image</param>
        /// <returns>resampled image</returns>
        public static sitk.Image ResizeImage(sitk.Image toResize, sitk.Image referenceImage)
        {
            if (toResize.GetWidth() == referenceImage.GetWidth() && toResize.GetHeight() == referenceImage.GetHeight())
            {
                return(toResize);
            }

            uint width  = toResize.GetWidth() < referenceImage.GetWidth() ? referenceImage.GetWidth() : toResize.GetWidth();
            uint height = toResize.GetHeight() < referenceImage.GetHeight() ? referenceImage.GetHeight() : toResize.GetHeight();

            sitk.VectorUInt32 vec = new sitk.VectorUInt32();
            vec.Add(width);
            vec.Add(height);

            sitk.ResampleImageFilter resampleFilter = new sitk.ResampleImageFilter();
            resampleFilter.SetSize(vec);
            resampleFilter.SetOutputOrigin(toResize.GetOrigin());
            resampleFilter.SetOutputDirection(toResize.GetDirection());
            resampleFilter.SetOutputSpacing(toResize.GetSpacing());
            resampleFilter.SetOutputPixelType(referenceImage.GetPixelID());
            resampleFilter.SetDefaultPixelValue(255.0);
            sitk.Image resultImage = resampleFilter.Execute(toResize);

            return(resultImage);
        }
        /// <summary>
        /// Create a checkerboard image of two corresponding images.
        /// </summary>
        /// <param name="fImg01">image 1</param>
        /// <param name="fImg02">image 2</param>
        /// <param name="size">grid size of the checker boar</param>
        /// <returns>checker board image</returns>
        public static sitk.Image GetCheckerBoardV2(string fImg01, string fImg02, uint size = 0)
        {
            sitk.Image img01 = ReadWriteUtils.ReadITKImageFromFile(fImg01);
            sitk.Image img02 = ReadWriteUtils.ReadITKImageFromFile(fImg02);

            uint width  = img01.GetWidth() > img02.GetWidth() ? img01.GetWidth() : img02.GetWidth();
            uint height = img01.GetHeight() > img02.GetHeight() ? img01.GetHeight() : img02.GetHeight();

            sitk.Image reference   = ImageUtils.ResizeImage(img01, width, height);
            sitk.Image transformed = ImageUtils.ResizeImage(img02, width, height);

            sitk.CheckerBoardImageFilter checkerBoard = new sitk.CheckerBoardImageFilter();
            uint lx = size;
            uint ly = width / (height / size);

            if (size != 0)
            {
                sitk.VectorUInt32 vec = new sitk.VectorUInt32();
                vec.Add(ly);
                vec.Add(lx);
                checkerBoard.SetCheckerPattern(vec);
            }
            sitk.Image result = checkerBoard.Execute(reference, transformed);
            img01.Dispose();
            img02.Dispose();
            reference.Dispose();
            transformed.Dispose();
            return(result);
        }
        public static sitk.Image GetCheckerBoard(sitk.Image img01, sitk.Image img02, uint size = 0)
        {
            uint width  = img01.GetWidth() > img02.GetWidth() ? img01.GetWidth() : img02.GetWidth();
            uint height = img01.GetHeight() > img02.GetHeight() ? img01.GetHeight() : img02.GetHeight();

            //Console.WriteLine(string.Format("width: Img01 [{0}] - Img02 [{1}]", img01.GetWidth(), img02.GetWidth()));
            //Console.WriteLine(string.Format("height: Img01 [{0}] - Img02 [{1}]", img01.GetHeight(), img02.GetHeight()));
            //Console.WriteLine(string.Format("pixel type: Img01 [{0}] - Img02 [{1}]", img01.GetPixelIDTypeAsString(), img02.GetPixelIDTypeAsString()));

            sitk.Image reference   = ImageUtils.ResizeImage(img01, width, height, sitk.PixelIDValueEnum.sitkFloat32);
            sitk.Image transformed = ImageUtils.ResizeImage(img02, width, height, sitk.PixelIDValueEnum.sitkFloat32);

            sitk.CheckerBoardImageFilter checkerBoard = new sitk.CheckerBoardImageFilter();

            if (size != 0)
            {
                sitk.VectorUInt32 vec = new sitk.VectorUInt32();
                vec.Add(size);
                vec.Add(size);
                checkerBoard.SetCheckerPattern(vec);
            }

            sitk.Image           temp            = checkerBoard.Execute(reference, transformed);
            sitk.CastImageFilter castImageFilter = new sitk.CastImageFilter();
            castImageFilter.SetOutputPixelType(sitk.PixelIDValueEnum.sitkUInt8);
            sitk.Image result = castImageFilter.Execute(temp);
            temp.Dispose();
            return(result);
        }
        /// <summary>
        /// Load and resize image depending on the width and height of the largest image in stack.
        /// </summary>
        /// <param name="filename">filename of the image to load</param>
        /// <param name="writeFilename">output filename if image should be written back to disk</param>
        /// <returns>simpleitk image</returns>
        private sitk.Image LoadAndResizeImage(string filename, string writeFilename = null)
        {
            sitk.Image refImage = ReadWriteUtils.ReadITKImageFromFile(filename, sitk.PixelIDValueEnum.sitkVectorUInt8);

            if (refImage.GetWidth() == _parameters.LargestImageWidth && refImage.GetHeight() == _parameters.LargestImageHeight)
            {
                return(refImage);
            }
            else
            {
                sitk.Image refResized = ImageUtils.ResizeImage(refImage, _parameters.LargestImageWidth, _parameters.LargestImageHeight);

                // write image if output filename is defined
                if (writeFilename != null)
                {
                    ReadWriteUtils.WriteSitkImage(refResized, Path.Combine(_parameters.OutputDirectory, Path.GetFileName(writeFilename)));
                }

                return(refResized);
            }
        }
        /// <summary>
        /// Resize image by new width and height.
        /// </summary>
        /// <param name="image">input image</param>
        /// <param name="newWidth">width</param>
        /// <param name="newHeight">height</param>
        /// <returns>resized image</returns>
        public static sitk.Image ResizeImage(sitk.Image image, uint newWidth, uint newHeight)
        {
            if (image.GetWidth() == newWidth && image.GetHeight() == newHeight)
            {
                return(image);
            }

            sitk.VectorUInt32 vec = new sitk.VectorUInt32();
            vec.Add(newWidth);
            vec.Add(newHeight);

            sitk.ResampleImageFilter resampleFilter = new sitk.ResampleImageFilter();
            resampleFilter.SetSize(vec);
            resampleFilter.SetOutputOrigin(image.GetOrigin());
            resampleFilter.SetOutputDirection(image.GetDirection());
            resampleFilter.SetOutputSpacing(image.GetSpacing());
            resampleFilter.SetOutputPixelType(image.GetPixelID());
            resampleFilter.SetDefaultPixelValue(255.0);
            sitk.Image resultImage = resampleFilter.Execute(image);

            return(resultImage);
        }