private Image ApplyCastImageFilter(Image image) { Ensure.ArgumentNotNull(image, nameof(image)); // TODO: find mapping between itk.simple.PixelIDValueEnum and System.Drawing.Imaging.PixelFormat // see https://github.com/SimpleITK/SimpleITK/issues/582 // Execute cast filter CastImageFilter filter = new CastImageFilter(); PixelIDValueEnum imageType = PixelIDValueEnum.swigToEnum(image.GetPixelIDValue()); if (imageType == PixelIDValueEnum.sitkVectorUInt8 || imageType == PixelIDValueEnum.sitkUInt8) { return(image); } else { if (imageType.ToString().ToLowerInvariant().Contains("vector")) { filter.SetOutputPixelType(PixelIDValueEnum.sitkVectorUInt8); } else { filter.SetOutputPixelType(PixelIDValueEnum.sitkUInt8); } Image output = filter.Execute(image); filter.Dispose(); image.Dispose(); return(output); } }
static void Main(string[] args) { try { if (args.Length < 3) { Console.WriteLine("Usage: SimpleGaussian <input> <sigma> <output>"); return; } // Read input image ImageFileReader reader = new ImageFileReader(); reader.SetFileName(args[0]); Image image = reader.Execute(); // Execute Gaussian smoothing filter SmoothingRecursiveGaussianImageFilter gaussian = new SmoothingRecursiveGaussianImageFilter(); gaussian.SetSigma(Double.Parse(args[1])); Image blurredImage = gaussian.Execute(image); // Covert the real output image back to the original pixel type , to // make writing easier , as many file formats don 't support real // pixels . CastImageFilter castFilter = new CastImageFilter(); castFilter.SetOutputPixelType(image.GetPixelIDValue()); Image destImage = castFilter.Execute(blurredImage); // Write output image ImageFileWriter writer = new ImageFileWriter(); writer.SetFileName(args[2]); writer.Execute(destImage); } catch (Exception ex) { Console.WriteLine(ex); } }
static void Main(string[] args) { try { if (args.Length < 3) { Console.WriteLine("Usage: SimpleGaussian <input> <sigma> <output>"); return; } // Read input image ImageFileReader reader = new ImageFileReader(); reader.SetFileName(args[0]); Image image = reader.Execute(); // Execute Gaussian smoothing filter SmoothingRecursiveGaussianImageFilter gaussian = new SmoothingRecursiveGaussianImageFilter(); gaussian.SetSigma(Double.Parse(args[1])); Image blurredImage = gaussian.Execute(image); // Covert the real output image back to the original pixel type , to // make writing easier , as many file formats don 't support real // pixels . CastImageFilter castFilter = new CastImageFilter(); castFilter.SetOutputPixelType(image.GetPixelID()); Image destImage = castFilter.Execute(blurredImage); // Write output image ImageFileWriter writer = new ImageFileWriter(); writer.SetFileName(args[2]); writer.Execute(destImage); } catch (Exception ex) { Console.WriteLine(ex); } }
public itk.simple.Image NalozObrazy(itk.simple.Image original, itk.simple.Image segmented) { itk.simple.MinimumMaximumImageFilter maxminFilter = new MinimumMaximumImageFilter(); maxminFilter.Execute(original); double max = maxminFilter.GetMaximum(); itk.simple.CastImageFilter caster1 = new CastImageFilter(); caster1.SetOutputPixelType(itk.simple.PixelIDValueEnum.sitkInt16); itk.simple.Image castImg = caster1.Execute(segmented); itk.simple.MultiplyImageFilter multiplyFilter = new MultiplyImageFilter(); itk.simple.Image multiplyImage = multiplyFilter.Execute(castImg, max); itk.simple.MaximumImageFilter maximumFilter = new MaximumImageFilter(); itk.simple.Image maximumImage = maximumFilter.Execute(original, multiplyImage); //itk.simple.IntensityWindowingImageFilter windower = new IntensityWindowingImageFilter(); //windower.SetWindowMinimum(0); //windower.SetWindowMaximum(255); //windower.SetOutputMinimum(0); //windower.SetOutputMaximum(1); //itk.simple.Image window = windower.Execute(maximumImage); itk.simple.ImageFileWriter writer = new ImageFileWriter(); writer.SetFileName("Wynik.dcm"); writer.Execute(maximumImage); return(maximumImage); }
/// <summary> /// Applies the cast image filter. /// </summary> /// <param name="image">The ITK image.</param> /// <returns> /// The modified ITK image. /// </returns> /// <exception cref="ArgumentNullException">image</exception> private Image ApplyCastImageFilter(Image image) { if (image == null) { throw new ArgumentNullException(nameof(image)); } // TODO: find mapping between itk.simple.PixelIDValueEnum and System.Drawing.Imaging.PixelFormat // see https://github.com/SimpleITK/SimpleITK/issues/582 // Execute cast filter CastImageFilter filterC = new CastImageFilter(); filterC.SetOutputPixelType(PixelIDValueEnum.sitkUInt8); Image output = filterC.Execute(image); filterC.Dispose(); return(output ?? image); }
public itk.simple.Image WstepnePrzetwarzanie(itk.simple.Image image) { itk.simple.BinaryMorphologicalClosingImageFilter closer = new BinaryMorphologicalClosingImageFilter(); closer.SetKernelType(KernelEnum.sitkCross); closer.SetKernelRadius(1); closer.SetForegroundValue(511); itk.simple.Image imClose = closer.Execute(image); itk.simple.SmoothingRecursiveGaussianImageFilter gauss = new SmoothingRecursiveGaussianImageFilter(); gauss.SetSigma(1); itk.simple.Image gausImage = gauss.Execute(imClose); itk.simple.CastImageFilter caster = new CastImageFilter(); caster.SetOutputPixelType(itk.simple.PixelIDValueEnum.sitkInt16); itk.simple.Image castImage = caster.Execute(gausImage); itk.simple.ImageFileWriter writer = new itk.simple.ImageFileWriter(); writer.SetFileName("WstepnePrzetwarzanie.dcm"); writer.Execute(image); return(castImage); }
public itk.simple.Image NalozObrazy(itk.simple.Image original, itk.simple.Image segmented) { itk.simple.MinimumMaximumImageFilter maxminFilter = new MinimumMaximumImageFilter(); maxminFilter.Execute(original); double max = maxminFilter.GetMaximum(); itk.simple.CastImageFilter caster1 = new CastImageFilter(); caster1.SetOutputPixelType(itk.simple.PixelIDValueEnum.sitkInt16); itk.simple.Image castImg = caster1.Execute(segmented); itk.simple.MultiplyImageFilter multiplyFilter = new MultiplyImageFilter(); itk.simple.Image multiplyImage = multiplyFilter.Execute(castImg, max); itk.simple.MaximumImageFilter maximumFilter = new MaximumImageFilter(); itk.simple.Image maximumImage = maximumFilter.Execute(original, multiplyImage); //itk.simple.IntensityWindowingImageFilter windower = new IntensityWindowingImageFilter(); //windower.SetWindowMinimum(0); //windower.SetWindowMaximum(255); //windower.SetOutputMinimum(0); //windower.SetOutputMaximum(1); //itk.simple.Image window = windower.Execute(maximumImage); itk.simple.ImageFileWriter writer = new ImageFileWriter(); writer.SetFileName("Wynik.dcm"); writer.Execute(maximumImage); return maximumImage; }
public itk.simple.Image SegmetacjaSledziony(itk.simple.Image image) { itk.simple.MorphologicalGradientImageFilter gradientFilter = new MorphologicalGradientImageFilter(); gradientFilter.SetKernelType(KernelEnum.sitkCross); gradientFilter.SetKernelRadius(1); itk.simple.Image gradientImage = gradientFilter.Execute(image); itk.simple.SigmoidImageFilter sigmoidFilter = new SigmoidImageFilter(); sigmoidFilter.SetOutputMinimum(0); sigmoidFilter.SetOutputMaximum(1); sigmoidFilter.SetAlpha(1.5); sigmoidFilter.SetBeta(100); itk.simple.Image sigmoidImage = sigmoidFilter.Execute(gradientImage); itk.simple.BinaryThresholdImageFilter threshFilter = new BinaryThresholdImageFilter(); threshFilter.SetLowerThreshold(100); threshFilter.SetUpperThreshold(180); threshFilter.SetOutsideValue(0); threshFilter.SetInsideValue(1); itk.simple.Image threshImage = threshFilter.Execute(image); itk.simple.CastImageFilter castThresh = new CastImageFilter(); castThresh.SetOutputPixelType(itk.simple.PixelIDValueEnum.sitkInt16); itk.simple.Image castThreshImage = castThresh.Execute(threshImage); itk.simple.SubtractImageFilter substractFilter = new SubtractImageFilter(); itk.simple.Image substractImage = substractFilter.Execute(castThreshImage, sigmoidImage); itk.simple.ThresholdImageFilter threshFilter2 = new ThresholdImageFilter(); threshFilter2.SetLower(0); threshFilter2.SetUpper(0); threshFilter2.SetOutsideValue(1); itk.simple.Image threshImage2 = threshFilter2.Execute(substractImage); itk.simple.BinaryErodeImageFilter erodeFilter = new BinaryErodeImageFilter(); erodeFilter.SetForegroundValue(1); erodeFilter.SetBackgroundValue(0); erodeFilter.SetKernelType(itk.simple.KernelEnum.sitkCross); erodeFilter.SetKernelRadius(5); itk.simple.Image erodeImage = erodeFilter.Execute(threshImage2); itk.simple.ConnectedComponentImageFilter connFilter = new ConnectedComponentImageFilter(); connFilter.SetFullyConnected(true); itk.simple.Image connImage = connFilter.Execute(erodeImage); itk.simple.RelabelComponentImageFilter relabelFilter = new RelabelComponentImageFilter(); relabelFilter.SetMinimumObjectSize(5000); itk.simple.Image relabelImage = relabelFilter.Execute(connImage); itk.simple.BinaryThresholdImageFilter threshFilter3 = new BinaryThresholdImageFilter(); threshFilter3.SetInsideValue(1); threshFilter3.SetOutsideValue(0); threshFilter3.SetLowerThreshold(1); threshFilter3.SetUpperThreshold(1); itk.simple.Image threshImage3 = threshFilter3.Execute(relabelImage); itk.simple.DilateObjectMorphologyImageFilter closeReconstructFilter = new DilateObjectMorphologyImageFilter(); closeReconstructFilter.SetKernelType(itk.simple.KernelEnum.sitkCross); closeReconstructFilter.SetKernelRadius(5); itk.simple.Image closeReconstructImage = closeReconstructFilter.Execute(threshImage3); itk.simple.ImageFileWriter writer = new ImageFileWriter(); writer.SetFileName("SegmentujSledzione.dcm"); writer.Execute(closeReconstructImage); return closeReconstructImage; }
public itk.simple.Image WstepnePrzetwarzanie(itk.simple.Image image) { itk.simple.BinaryMorphologicalClosingImageFilter closer = new BinaryMorphologicalClosingImageFilter(); closer.SetKernelType(KernelEnum.sitkCross); closer.SetKernelRadius(1); closer.SetForegroundValue(511); itk.simple.Image imClose = closer.Execute(image); itk.simple.SmoothingRecursiveGaussianImageFilter gauss = new SmoothingRecursiveGaussianImageFilter(); gauss.SetSigma(1); itk.simple.Image gausImage = gauss.Execute(imClose); itk.simple.CastImageFilter caster = new CastImageFilter(); caster.SetOutputPixelType(itk.simple.PixelIDValueEnum.sitkInt16); itk.simple.Image castImage = caster.Execute(gausImage); itk.simple.ImageFileWriter writer = new itk.simple.ImageFileWriter(); writer.SetFileName("WstepnePrzetwarzanie.dcm"); writer.Execute(image); return castImage; }
public itk.simple.Image SegmetacjaSledziony(itk.simple.Image image) { itk.simple.MorphologicalGradientImageFilter gradientFilter = new MorphologicalGradientImageFilter(); gradientFilter.SetKernelType(KernelEnum.sitkCross); gradientFilter.SetKernelRadius(1); itk.simple.Image gradientImage = gradientFilter.Execute(image); itk.simple.SigmoidImageFilter sigmoidFilter = new SigmoidImageFilter(); sigmoidFilter.SetOutputMinimum(0); sigmoidFilter.SetOutputMaximum(1); sigmoidFilter.SetAlpha(1.5); sigmoidFilter.SetBeta(100); itk.simple.Image sigmoidImage = sigmoidFilter.Execute(gradientImage); itk.simple.BinaryThresholdImageFilter threshFilter = new BinaryThresholdImageFilter(); threshFilter.SetLowerThreshold(100); threshFilter.SetUpperThreshold(180); threshFilter.SetOutsideValue(0); threshFilter.SetInsideValue(1); itk.simple.Image threshImage = threshFilter.Execute(image); itk.simple.CastImageFilter castThresh = new CastImageFilter(); castThresh.SetOutputPixelType(itk.simple.PixelIDValueEnum.sitkInt16); itk.simple.Image castThreshImage = castThresh.Execute(threshImage); itk.simple.SubtractImageFilter substractFilter = new SubtractImageFilter(); itk.simple.Image substractImage = substractFilter.Execute(castThreshImage, sigmoidImage); itk.simple.ThresholdImageFilter threshFilter2 = new ThresholdImageFilter(); threshFilter2.SetLower(0); threshFilter2.SetUpper(0); threshFilter2.SetOutsideValue(1); itk.simple.Image threshImage2 = threshFilter2.Execute(substractImage); itk.simple.BinaryErodeImageFilter erodeFilter = new BinaryErodeImageFilter(); erodeFilter.SetForegroundValue(1); erodeFilter.SetBackgroundValue(0); erodeFilter.SetKernelType(itk.simple.KernelEnum.sitkCross); erodeFilter.SetKernelRadius(5); itk.simple.Image erodeImage = erodeFilter.Execute(threshImage2); itk.simple.ConnectedComponentImageFilter connFilter = new ConnectedComponentImageFilter(); connFilter.SetFullyConnected(true); itk.simple.Image connImage = connFilter.Execute(erodeImage); itk.simple.RelabelComponentImageFilter relabelFilter = new RelabelComponentImageFilter(); relabelFilter.SetMinimumObjectSize(5000); itk.simple.Image relabelImage = relabelFilter.Execute(connImage); itk.simple.BinaryThresholdImageFilter threshFilter3 = new BinaryThresholdImageFilter(); threshFilter3.SetInsideValue(1); threshFilter3.SetOutsideValue(0); threshFilter3.SetLowerThreshold(1); threshFilter3.SetUpperThreshold(1); itk.simple.Image threshImage3 = threshFilter3.Execute(relabelImage); itk.simple.DilateObjectMorphologyImageFilter closeReconstructFilter = new DilateObjectMorphologyImageFilter(); closeReconstructFilter.SetKernelType(itk.simple.KernelEnum.sitkCross); closeReconstructFilter.SetKernelRadius(5); itk.simple.Image closeReconstructImage = closeReconstructFilter.Execute(threshImage3); itk.simple.ImageFileWriter writer = new ImageFileWriter(); writer.SetFileName("SegmentujSledzione.dcm"); writer.Execute(closeReconstructImage); return(closeReconstructImage); }