コード例 #1
0
 /// <summary>
 /// Reads an ITK image from file, specifying the output pixel type.
 /// </summary>
 /// <param name="file">filename</param>
 /// <param name="outputType">output pixel type</param>
 /// <returns>image</returns>
 public static sitk.Image ReadITKImageFromFile(string file, sitk.PixelIDValueEnum outputType)
 {
     sitk.ImageFileReader reader = new sitk.ImageFileReader();
     reader.SetFileName(file);
     reader.SetOutputPixelType(outputType);
     return(reader.Execute());
 }
コード例 #2
0
 /// <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));
 }
コード例 #3
0
        /// <summary>
        /// Reads an ITK image as a grayscale image.
        /// </summary>
        /// <param name="file">filename</param>
        /// <param name="outputType">output datatype</param>
        /// <param name="channel">channel to extract</param>
        /// <returns>grayscale ITK image</returns>
        public static sitk.Image ReadITKImageAsGrayscaleFromFile(string file, sitk.PixelIDValueEnum outputType, ColorChannel channel)
        {
            sitk.ImageFileReader reader = new sitk.ImageFileReader();
            reader.SetFileName(file);
            reader.SetOutputPixelType(outputType);
            sitk.Image temp = reader.Execute();

            sitk.Image result = null;
            sitk.VectorIndexSelectionCastImageFilter rgbVector = new sitk.VectorIndexSelectionCastImageFilter();
            switch (channel)
            {
            case ColorChannel.R: result = rgbVector.Execute(temp, 0, sitk.PixelIDValueEnum.sitkFloat32); break;

            case ColorChannel.G: result = rgbVector.Execute(temp, 1, sitk.PixelIDValueEnum.sitkFloat32); break;

            case ColorChannel.B: result = rgbVector.Execute(temp, 2, sitk.PixelIDValueEnum.sitkFloat32); break;
            }

            return(result);
        }
コード例 #4
0
        /// <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);
        }
コード例 #5
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));
 }