public void Apply() { if (this.SelectedImageGraphicProvider == null) { return; } ImageGraphic image = this.SelectedImageGraphicProvider.ImageGraphic; if (image == null) { return; } if (!(image is GrayscaleImageGraphic)) { return; } itkImageBase input = ItkHelper.CreateItkImage(image as GrayscaleImageGraphic); itkImageBase output = itkImage.New(input); ItkHelper.CopyToItkImage(image as GrayscaleImageGraphic, input); FilterType filter = FilterType.New(input, output); filter.SetInput(input); String mangledType = input.MangledTypeString; intensityFilterType intensityFilter = intensityFilterType.New(mangledType + mangledType); intensityFilter.SetInput(filter.GetOutput()); intensityFilter.OutputMinimum = 0; if (image.BitsPerPixel == 16) { intensityFilter.OutputMaximum = 32767; } else { intensityFilter.OutputMaximum = 255; } intensityFilter.Update(); intensityFilter.GetOutput(output); ItkHelper.CopyFromItkImage(image as GrayscaleImageGraphic, output); image.Draw(); filter.Dispose(); intensityFilter.Dispose(); input.Dispose(); output.Dispose(); }
public void Apply() { if (this.SelectedImageGraphicProvider == null) { return; } ImageGraphic image = this.SelectedImageGraphicProvider.ImageGraphic; if (image == null) { return; } if (!(image is GrayscaleImageGraphic)) { return; } itkImageBase input = ItkHelper.CreateItkImage(image as GrayscaleImageGraphic); itkImageBase output = itkImage.New(input); ItkHelper.CopyToItkImage(image as GrayscaleImageGraphic, input); FilterType filter = FilterType.New(input, output); filter.SetInput(input); filter.Update(); filter.GetOutput(output); ItkHelper.CopyFromItkImage(image as GrayscaleImageGraphic, output); image.Draw(); filter.Dispose(); input.Dispose(); output.Dispose(); }
public void Apply() { if (this.SelectedImageGraphicProvider == null) { return; } ImageGraphic image = this.SelectedImageGraphicProvider.ImageGraphic; if (image == null) { return; } if (!(image is GrayscaleImageGraphic)) { return; } itkImageBase input = ItkHelper.CreateItkImage(image as GrayscaleImageGraphic); itkImageBase output = itkImage.New(input); ItkHelper.CopyToItkImage(image as GrayscaleImageGraphic, input); String mangledType = input.MangledTypeString; CastImageFilterType castToIF2 = CastImageFilterType.New(mangledType + "IF2"); SmoothingFilterType smoothingFilter = SmoothingFilterType.New("IF2IF2"); smoothingFilter.TimeStep = 0.125; smoothingFilter.NumberOfIterations = 5; smoothingFilter.ConductanceParameter = 9.0; GradientMagnitudeFilterType gradientMagnitudeFilter = GradientMagnitudeFilterType.New("IF2IF2"); gradientMagnitudeFilter.Sigma = 1.0; SigmoidFilterType sigmoidFilter = SigmoidFilterType.New("IF2IF2"); sigmoidFilter.OutputMinimum = 0.0; sigmoidFilter.OutputMaximum = 1.0; sigmoidFilter.Alpha = -0.5; //-0.3 sigmoidFilter.Beta = 3.0; //2.0 FastMarchingFilterType fastMarchingFilter = FastMarchingFilterType.New("IF2IF2"); double seedValue = 0.0; int[] seedPosition = { 256, 256 };// user input itkIndex seedIndex = new itkIndex(seedPosition); itkLevelSetNode[] trialPoints = { new itkLevelSetNode(seedValue, seedIndex) }; fastMarchingFilter.TrialPoints = trialPoints; fastMarchingFilter.StoppingValue = 100; BinaryThresholdFilterType binaryThresholdFilter = BinaryThresholdFilterType.New("IF2" + mangledType); //to UC2? binaryThresholdFilter.UpperThreshold = 100.0; //200 binaryThresholdFilter.LowerThreshold = 0.0; binaryThresholdFilter.OutsideValue = 0; if (image.BitsPerPixel == 16) { binaryThresholdFilter.InsideValue = (image as GrayscaleImageGraphic).ModalityLut.MaxInputValue;//32767; } else { binaryThresholdFilter.InsideValue = 255; } //intensityFilterType intensityFilter = intensityFilterType.New("UC2" + mangledType); //intensityFilter.OutputMinimum = 0; //if (image.BitsPerPixel == 16) // intensityFilter.OutputMaximum = (image as GrayscaleImageGraphic).ModalityLut.MaxInputValue;//32767; //else // intensityFilter.OutputMaximum = 255; // Make data stream connections castToIF2.SetInput(input); smoothingFilter.SetInput(castToIF2.GetOutput()); gradientMagnitudeFilter.SetInput(smoothingFilter.GetOutput()); sigmoidFilter.SetInput(gradientMagnitudeFilter.GetOutput()); fastMarchingFilter.SetInput(sigmoidFilter.GetOutput()); binaryThresholdFilter.SetInput(fastMarchingFilter.GetOutput()); //intensityFilter.SetInput(binaryThresholdFilter.GetOutput()); //smoothingFilter.Update(); fastMarchingFilter.OutputSize = input.BufferedRegion.Size;//? binaryThresholdFilter.Update(); binaryThresholdFilter.GetOutput(output); ItkHelper.CopyFromItkImage(image as GrayscaleImageGraphic, output); image.Draw(); input.Dispose(); output.Dispose(); }
public void Apply() { if (this.SelectedImageGraphicProvider == null) { return; } ImageGraphic image = this.SelectedImageGraphicProvider.ImageGraphic; if (image == null) { return; } if (!(image is GrayscaleImageGraphic)) { return; } byte[] pixels = image.PixelData.Raw; itkImageBase input = ItkHelper.CreateItkImage(image as GrayscaleImageGraphic); itkImageRegion region = input.LargestPossibleRegion; itkImageBase output = itkImage.New(input); ItkHelper.CopyToItkImage(image as GrayscaleImageGraphic, input); string mangledType = input.MangledTypeString; string mangledType2 = input.PixelType.MangledTypeString; CastImageFilterType castToIF2 = CastImageFilterType.New(mangledType + "IF2"); castToIF2.SetInput(input); FilterType filter = FilterType.New("IF2IF2"); filter.SetInput(castToIF2.GetOutput()); intensityFilterType intensityFilter = intensityFilterType.New("IF2" + mangledType); intensityFilter.SetInput(filter.GetOutput()); intensityFilter.OutputMinimum = 0; if (image.BitsPerPixel == 16) { intensityFilter.OutputMaximum = (image as GrayscaleImageGraphic).ModalityLut.MaxInputValue; } else { intensityFilter.OutputMaximum = 255; } intensityFilter.Update(); intensityFilter.GetOutput(output); ItkHelper.CopyFromItkImage(image as GrayscaleImageGraphic, output); image.Draw(); filter.Dispose(); intensityFilter.Dispose(); input.Dispose(); output.Dispose(); }
public void Apply() { if (this.SelectedImageGraphicProvider == null) { return; } ImageGraphic image = this.SelectedImageGraphicProvider.ImageGraphic; if (image == null) { return; } if (!(image is GrayscaleImageGraphic)) { return; } itkImageBase input = ItkHelper.CreateItkImage(image as GrayscaleImageGraphic); itkImageBase output = itkImage.New(input); ItkHelper.CopyToItkImage(image as GrayscaleImageGraphic, input); FilterType filter = FilterType.New(input, output); bool abc = false; if (abc) { byte[] pixels = image.PixelData.Raw; unsafe { byte[] dummy = new byte[512 * 512]; IntPtr bptr = input.Buffer; void * pbptr = bptr.ToPointer(); { filter.SetInput(bptr); } fixed(byte *dummyAddr = &dummy[0]) { *dummyAddr = 1; *(dummyAddr + 1) = 2; IntPtr ptr = new IntPtr(dummyAddr); filter.SetInput(ptr); } fixed(byte *pByte = image.PixelData.Raw) { IntPtr x = new IntPtr((void *)pByte); void * p = x.ToPointer(); filter.SetInput(x);//runtime memory protected exception because it expects x.ToPointer() is ITK::Image_XX* (see implementation of MITK) } } } else { filter.SetInput(input); } filter.NormalizeAcrossScale = false; filter.Sigma = 3; filter.Update(); filter.GetOutput(output); filter.GetOutput(output); ItkHelper.CopyFromItkImage(image as GrayscaleImageGraphic, output); image.Draw(); filter.Dispose(); input.Dispose(); output.Dispose(); }
public void Apply() { if (this.SelectedImageGraphicProvider == null) { return; } ImageGraphic image = this.SelectedImageGraphicProvider.ImageGraphic; if (image == null) { return; } if (!(image is GrayscaleImageGraphic)) { return; } byte[] pixels = image.PixelData.Raw; itkImageBase input = ItkHelper.CreateItkImage(image as GrayscaleImageGraphic); itkImageRegion region = input.LargestPossibleRegion; itkImageBase output = itkImage.New(input); ItkHelper.CopyToItkImage(image as GrayscaleImageGraphic, input); String mangledType = input.MangledTypeString; CastImageFilterType castToIF2 = CastImageFilterType.New(mangledType + "IF2"); castToIF2.SetInput(input); FilterType filter = FilterType.New("IF2IF2"); filter.SetInput(castToIF2.GetOutput()); // TODO: need to allow user to set parameters of filter filter.LowerThreshold = 90; filter.UpperThreshold = 127; //filter.OutsideValue = 0; // smoothing the edge double[] error = { 0.01, 0.01 }; filter.MaximumError = error; double[] var = { 1.0, 1.0 }; filter.Variance = var; intensityFilterType intensityFilter = intensityFilterType.New("IF2" + mangledType); intensityFilter.SetInput(filter.GetOutput()); intensityFilter.OutputMinimum = 0; if (image.BitsPerPixel == 16) { intensityFilter.OutputMaximum = (image as GrayscaleImageGraphic).ModalityLut.MaxInputValue;//32767; } else { intensityFilter.OutputMaximum = 255; } intensityFilter.Update(); #if DEBUG bool debug = false; if (debug) { itkImageBase outputIF2 = itkImage.New("IF2"); filter.GetOutput(outputIF2); float min = float.MaxValue, max = float.MinValue; unsafe { fixed(byte *pDstByte = image.PixelData.Raw) { itkImageRegionConstIterator_IF2 itkIt = new itkImageRegionConstIterator_IF2(outputIF2, region); byte *pDst = (byte *)pDstByte; int height = image.Rows; int width = image.Columns; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { float f = itkIt.Get().ValueAsF; if (f > max) { max = f; } if (f < min) { min = f; } pDst[0] = (byte)itkIt.Get().ValueAsF; pDst++; itkIt++; } } } } Console.WriteLine("min max "); Console.Write(min); Console.Write(" "); Console.WriteLine(max); } #endif intensityFilter.GetOutput(output); ItkHelper.CopyFromItkImage(image as GrayscaleImageGraphic, output); image.Draw(); filter.Dispose(); intensityFilter.Dispose(); input.Dispose(); output.Dispose(); }