/// <summary>
 /// Binarize image by a lower and upper threshold.
 /// </summary>
 /// <param name="img">image</param>
 /// <param name="lowerT">lower threshold</param>
 /// <param name="upperT">upper threshold</param>
 /// <returns></returns>
 public static sitk.Image Binarize(sitk.Image img, int lowerT = 127, int upperT = 255)
 {
     sitk.BinaryThresholdImageFilter binaryFilter1 = new sitk.BinaryThresholdImageFilter();
     binaryFilter1.SetLowerThreshold(lowerT);
     binaryFilter1.SetUpperThreshold(upperT);
     binaryFilter1.SetInsideValue(1);
     binaryFilter1.SetOutsideValue(0);
     return(binaryFilter1.Execute(img));
 }
Esempio n. 2
0
        static void Main(string[] args)
        {
            string catalog = @"C:\Users\vroob\Downloads\projektKWDM\serie";

            string[] pathToSeries = Directory.GetFiles(catalog);

            sitk.VectorString fileNames = sitk.ImageSeriesReader.GetGDCMSeriesFileNames(catalog);

            sitk.ImageSeriesReader imageSeriesReader = new sitk.ImageSeriesReader();
            imageSeriesReader.SetFileNames(fileNames);
            imageSeriesReader.SetOutputPixelType(sitk.PixelIDValueEnum.sitkInt16);
            sitk.Image imageDicomOrg = imageSeriesReader.Execute();

            // binaryzacja
            sitk.BinaryThresholdImageFilter binthr = new sitk.BinaryThresholdImageFilter();
            binthr.SetLowerThreshold(-950);
            binthr.SetUpperThreshold(-720);
            binthr.SetOutsideValue(0);
            binthr.SetInsideValue(1);
            sitk.Image imageDicom = binthr.Execute(imageDicomOrg);

            sitk.VotingBinaryIterativeHoleFillingImageFilter holeFiller = new sitk.VotingBinaryIterativeHoleFillingImageFilter();
            holeFiller.SetRadius(2);
            holeFiller.SetForegroundValue(1);
            holeFiller.SetBackgroundValue(0);
            imageDicom = holeFiller.Execute(imageDicom);

            sitk.ConnectedComponentImageFilter labeler = new sitk.ConnectedComponentImageFilter();
            labeler.SetFullyConnected(true);
            sitk.Image labelImage = labeler.Execute(imageDicom);

            sitk.RelabelComponentImageFilter relabeler = new sitk.RelabelComponentImageFilter();
            relabeler.SetMinimumObjectSize(700);
            labelImage = relabeler.Execute(labelImage);

            sitk.ThresholdImageFilter thresholder = new sitk.ThresholdImageFilter();
            thresholder.SetLower(2);
            thresholder.SetUpper(2);
            thresholder.SetOutsideValue(0);
            labelImage = thresholder.Execute(labelImage);

            SaveImage(imageDicom, "labelImage.vtk");
        }
Esempio n. 3
0
        public static sitk.Image BinaryThinning(sitk.Image inputImage)
        {
            sitk.VectorIndexSelectionCastImageFilter vectorIndexSelectionCastImageFilter = new sitk.VectorIndexSelectionCastImageFilter();
            sitk.CastImageFilter castImageFilter = new sitk.CastImageFilter();
            sitk.Image           image           = vectorIndexSelectionCastImageFilter.Execute(inputImage, 0, castImageFilter.GetOutputPixelType());

            sitk.BinaryThresholdImageFilter binaryThresholdImageFilter = new sitk.BinaryThresholdImageFilter();
            binaryThresholdImageFilter.SetInsideValue(0);
            binaryThresholdImageFilter.SetOutsideValue(255);
            binaryThresholdImageFilter.SetLowerThreshold(0);
            binaryThresholdImageFilter.SetUpperThreshold(100);
            sitk.Image binaryThresholdImage = binaryThresholdImageFilter.Execute(image);

            sitk.BinaryThinningImageFilter binaryThinningImageFilter = new sitk.BinaryThinningImageFilter();
            sitk.Image binaryThinningImage = binaryThinningImageFilter.Execute(binaryThresholdImage);

            sitk.RescaleIntensityImageFilter rescaleIntensityImageFilter = new sitk.RescaleIntensityImageFilter();
            rescaleIntensityImageFilter.SetOutputMinimum(0);
            rescaleIntensityImageFilter.SetOutputMaximum(255);
            sitk.Image rescaleIntensityImage = rescaleIntensityImageFilter.Execute(binaryThinningImage);

            return(rescaleIntensityImage);
        }