/// <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>
 /// Resample image output pixel type.
 /// </summary>
 /// <param name="img">image</param>
 /// <param name="pixelIDValue">output pixel type</param>
 /// <returns>sitk image</returns>
 public static sitk.Image ResampleImage(sitk.Image img, sitk.PixelIDValueEnum pixelIDValue)
 {
     sitk.ResampleImageFilter resampleImageFilter = new sitk.ResampleImageFilter();
     resampleImageFilter.SetOutputPixelType(pixelIDValue);
     resampleImageFilter.SetOutputOrigin(img.GetOrigin());
     resampleImageFilter.SetOutputDirection(img.GetDirection());
     resampleImageFilter.SetOutputSpacing(img.GetSpacing());
     return(resampleImageFilter.Execute(img));
 }
Exemple #3
0
 /// <summary>
 /// Interpolate image by interpolation type and output pixel type.
 /// </summary>
 /// <param name="img"></param>
 /// <param name="interpolator"></param>
 /// <param name="pixelIDValueEnum"></param>
 /// <returns>interpolated image</returns>
 public static sitk.Image InterpolateImage(sitk.Image img, sitk.InterpolatorEnum interpolator, sitk.PixelIDValueEnum pixelIDValueEnum, double defaultPixelType = 0.0)
 {
     sitk.ResampleImageFilter resampleImageFilter = new sitk.ResampleImageFilter();
     resampleImageFilter.SetSize(img.GetSize());
     resampleImageFilter.SetOutputOrigin(img.GetOrigin());
     resampleImageFilter.SetOutputDirection(img.GetDirection());
     resampleImageFilter.SetOutputSpacing(img.GetSpacing());
     resampleImageFilter.SetInterpolator(interpolator);
     resampleImageFilter.SetOutputPixelType(pixelIDValueEnum);
     resampleImageFilter.SetDefaultPixelValue(defaultPixelType);
     return(resampleImageFilter.Execute(img));
 }
        /// <summary>
        /// Resize image by width and height and set output pixel type.
        /// </summary>
        /// <param name="img">input image</param>
        /// <param name="width">width</param>
        /// <param name="height">height</param>
        /// <param name="pixelType">output pixel type</param>
        /// <returns>resampled image</returns>
        public static sitk.Image ResizeImage(sitk.Image img, uint width, uint height, sitk.PixelIDValueEnum pixelType)
        {
            sitk.VectorUInt32 vec = new sitk.VectorUInt32();
            vec.Add(width);
            vec.Add(height);

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

            return(resultImage);
        }
        /// <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);
        }