diff --git a/src/Cxx/ImageProcessing/HybridMedianComparison.cxx b/src/Cxx/ImageProcessing/HybridMedianComparison.cxx index 5d5b169a6c6824e0cff017d0ee3fcee40ad093aa..88ebbaeb1e1883d92475c453b0f881ba21111e06 100644 --- a/src/Cxx/ImageProcessing/HybridMedianComparison.cxx +++ b/src/Cxx/ImageProcessing/HybridMedianComparison.cxx @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -23,6 +22,13 @@ #include #include +// #define USE_IMAGE_THRESHOLD +#ifdef USE_IMAGE_THRESHOLD +#include +#else +#include +#endif + namespace { void AddShotNoise(vtkImageData* inputImage, vtkImageData* outputImage, double noiseAmplitude, double noiseFraction, int extent[6]); @@ -151,6 +157,9 @@ int main(int argc, char* argv[]) renderWindow->AddRenderer(renderers[index]); } } + // Renderer positions in the window: + // Original Noisy + // Hybrid Median renderWindow->SetWindowName("HybridMedianComparison"); vtkNew renderWindowInteractor; @@ -182,17 +191,41 @@ void AddShotNoise(vtkImageData* inputImage, vtkImageData* outputImage, shotNoiseSource->SetMinimum(0.0); shotNoiseSource->SetMaximum(1.0); +#ifdef USE_IMAGE_THRESHOLD vtkNew shotNoiseThresh1; shotNoiseThresh1->SetInputConnection(shotNoiseSource->GetOutputPort()); shotNoiseThresh1->ThresholdByLower(1.0 - noiseFraction); shotNoiseThresh1->SetInValue(0); shotNoiseThresh1->SetOutValue(noiseAmplitude); +#else + vtkNew shotNoiseThresh1; + shotNoiseThresh1->SetInputConnection(shotNoiseSource->GetOutputPort()); + shotNoiseThresh1->SetThresholdFunction( + vtkImageBinaryThreshold::THRESHOLD_UPPER); + shotNoiseThresh1->SetLowerThreshold(1.0 - noiseFraction); + shotNoiseThresh1->ReplaceInOn(); + shotNoiseThresh1->ReplaceOutOn(); + shotNoiseThresh1->SetInValue(0); + shotNoiseThresh1->SetOutValue(noiseAmplitude); +#endif +#ifdef USE_IMAGE_THRESHOLD vtkNew shotNoiseThresh2; shotNoiseThresh2->SetInputConnection(shotNoiseSource->GetOutputPort()); shotNoiseThresh2->ThresholdByLower(noiseFraction); shotNoiseThresh2->SetInValue(1.0 - noiseAmplitude); shotNoiseThresh2->SetOutValue(0.0); +#else + vtkNew shotNoiseThresh2; + shotNoiseThresh2->SetInputConnection(shotNoiseSource->GetOutputPort()); + shotNoiseThresh1->SetThresholdFunction( + vtkImageBinaryThreshold::THRESHOLD_UPPER); + shotNoiseThresh2->SetLowerThreshold(noiseFraction); + shotNoiseThresh2->ReplaceInOn(); + shotNoiseThresh2->ReplaceOutOn(); + shotNoiseThresh2->SetInValue(1.0 - noiseAmplitude); + shotNoiseThresh2->SetOutValue(0.0); +#endif vtkNew shotNoise; shotNoise->SetInputConnection(0, shotNoiseThresh1->GetOutputPort()); diff --git a/src/Cxx/ImageProcessing/MedianComparison.cxx b/src/Cxx/ImageProcessing/MedianComparison.cxx index de129e18a528ddda7de160b36b8b0c7cf9b97290..d57800fd183ab649cbaf7726e2ccbbc3d4cd34ee 100644 --- a/src/Cxx/ImageProcessing/MedianComparison.cxx +++ b/src/Cxx/ImageProcessing/MedianComparison.cxx @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -23,6 +22,13 @@ #include #include +// #define USE_IMAGE_THRESHOLD +#ifdef USE_IMAGE_THRESHOLD +#include +#else +#include +#endif + namespace { void AddShotNoise(vtkImageData* inputImage, vtkImageData* outputImage, double noiseAmplitude, double noiseFraction, int extent[6]); @@ -178,17 +184,41 @@ void AddShotNoise(vtkImageData* inputImage, vtkImageData* outputImage, shotNoiseSource->SetMinimum(0.0); shotNoiseSource->SetMaximum(1.0); +#ifdef USE_IMAGE_THRESHOLD vtkNew shotNoiseThresh1; shotNoiseThresh1->SetInputConnection(shotNoiseSource->GetOutputPort()); shotNoiseThresh1->ThresholdByLower(1.0 - noiseFraction); shotNoiseThresh1->SetInValue(0); shotNoiseThresh1->SetOutValue(noiseAmplitude); +#else + vtkNew shotNoiseThresh1; + shotNoiseThresh1->SetInputConnection(shotNoiseSource->GetOutputPort()); + shotNoiseThresh1->SetThresholdFunction( + vtkImageBinaryThreshold::THRESHOLD_UPPER); + shotNoiseThresh1->SetLowerThreshold(1.0 - noiseFraction); + shotNoiseThresh1->ReplaceInOn(); + shotNoiseThresh1->ReplaceOutOn(); + shotNoiseThresh1->SetInValue(0); + shotNoiseThresh1->SetOutValue(noiseAmplitude); +#endif +#ifdef USE_IMAGE_THRESHOLD vtkNew shotNoiseThresh2; shotNoiseThresh2->SetInputConnection(shotNoiseSource->GetOutputPort()); shotNoiseThresh2->ThresholdByLower(noiseFraction); shotNoiseThresh2->SetInValue(1.0 - noiseAmplitude); shotNoiseThresh2->SetOutValue(0.0); +#else + vtkNew shotNoiseThresh2; + shotNoiseThresh2->SetInputConnection(shotNoiseSource->GetOutputPort()); + shotNoiseThresh1->SetThresholdFunction( + vtkImageBinaryThreshold::THRESHOLD_UPPER); + shotNoiseThresh2->SetLowerThreshold(noiseFraction); + shotNoiseThresh2->ReplaceInOn(); + shotNoiseThresh2->ReplaceOutOn(); + shotNoiseThresh2->SetInValue(1.0 - noiseAmplitude); + shotNoiseThresh2->SetOutValue(0.0); +#endif vtkNew shotNoise; shotNoise->SetInputConnection(0, shotNoiseThresh1->GetOutputPort()); diff --git a/src/Cxx/Images/ImageThreshold.cxx b/src/Cxx/Images/ImageThreshold.cxx index 0b23b43932c64cfeaa87d81714a9ffb5c4b875e0..da454afd88fad64f105e1de1b3ba4855ada5f9e3 100644 --- a/src/Cxx/Images/ImageThreshold.cxx +++ b/src/Cxx/Images/ImageThreshold.cxx @@ -1,13 +1,19 @@ #include #include #include -#include #include #include #include #include #include +// #define USE_IMAGE_THRESHOLD +#ifdef USE_IMAGE_THRESHOLD +#include +#else +#include +#endif + int main(int, char*[]) { vtkNew colors; @@ -16,14 +22,29 @@ int main(int, char*[]) vtkNew imageSource; imageSource->Update(); - vtkNew imageThreshold; - imageThreshold->SetInputConnection(imageSource->GetOutputPort()); unsigned char lower = 100; unsigned char upper = 200; +#ifdef USE_IMAGE_THRESHOLD + vtkNew imageThreshold; + imageThreshold->SetInputConnection(imageSource->GetOutputPort()); imageThreshold->ThresholdBetween(lower, upper); imageThreshold->ReplaceInOn(); + imageThreshold->ReplaceOutOn(); + imageThreshold->SetInValue(255); + imageThreshold->SetOutValue(0); +#else + vtkNew imageThreshold; + imageThreshold->SetInputConnection(imageSource->GetOutputPort()); + imageThreshold->SetThresholdFunction( + vtkImageBinaryThreshold::THRESHOLD_BETWEEN); + imageThreshold->SetLowerThreshold(lower); + imageThreshold->SetUpperThreshold(upper); + imageThreshold->ReplaceInOn(); + imageThreshold->ReplaceOutOn(); imageThreshold->SetInValue(255); + imageThreshold->SetOutValue(0); +#endif imageThreshold->Update(); // Create actors. diff --git a/src/Cxx/Modelling/DiscreteMarchingCubes.cxx b/src/Cxx/Modelling/DiscreteMarchingCubes.cxx index de7184d380ca247263b108e95989cbda5700eb05..ec91832063b08248d35ee19706c1377e29fc450b 100644 --- a/src/Cxx/Modelling/DiscreteMarchingCubes.cxx +++ b/src/Cxx/Modelling/DiscreteMarchingCubes.cxx @@ -1,7 +1,6 @@ #include #include #include -#include #include #include #include @@ -28,6 +27,13 @@ #include #endif +// #define USE_IMAGE_THRESHOLD +#ifdef USE_IMAGE_THRESHOLD +#include +#else +#include +#endif + namespace { vtkSmartPointer MakeColors(unsigned int n); @@ -108,6 +114,7 @@ vtkSmartPointer MakeBlob(int n, double radius) sampler->SetSampleDimensions(100, 100, 100); sampler->SetModelBounds(-50, 50, -50, 50, -50, 50); +#ifdef USE_IMAGE_THRESHOLD vtkNew thres; thres->SetInputConnection(sampler->GetOutputPort()); thres->ThresholdByLower(radius * radius); @@ -115,6 +122,17 @@ vtkSmartPointer MakeBlob(int n, double radius) thres->ReplaceOutOn(); thres->SetInValue(i + 1); thres->SetOutValue(0); +#else + vtkNew thres; + thres->SetInputConnection(sampler->GetOutputPort()); + thres->SetThresholdFunction(vtkImageBinaryThreshold::THRESHOLD_LOWER); + thres->SetUpperThreshold(radius * radius); + thres->ReplaceInOn(); + thres->ReplaceOutOn(); + thres->SetInValue(i + 1); + thres->SetOutValue(0); +#endif + thres->Update(); if (i == 0) { diff --git a/src/Cxx/Modelling/SmoothDiscreteMarchingCubes.cxx b/src/Cxx/Modelling/SmoothDiscreteMarchingCubes.cxx index b02157ea0b791f3d42f9817729bb95bb94427aa6..e1f15740738b6650cf364349af176e420eb61a76 100644 --- a/src/Cxx/Modelling/SmoothDiscreteMarchingCubes.cxx +++ b/src/Cxx/Modelling/SmoothDiscreteMarchingCubes.cxx @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include @@ -16,6 +15,13 @@ #include #include +// #define USE_IMAGE_THRESHOLD +#ifdef USE_IMAGE_THRESHOLD +#include +#else +#include +#endif + namespace { vtkSmartPointer MakeColors(unsigned int n); @@ -109,6 +115,7 @@ vtkSmartPointer MakeBlob(int n, double radius) sampler->SetSampleDimensions(100, 100, 100); sampler->SetModelBounds(-50, 50, -50, 50, -50, 50); +#ifdef USE_IMAGE_THRESHOLD vtkNew thres; thres->SetInputConnection(sampler->GetOutputPort()); thres->ThresholdByLower(radius * radius); @@ -116,6 +123,17 @@ vtkSmartPointer MakeBlob(int n, double radius) thres->ReplaceOutOn(); thres->SetInValue(i + 1); thres->SetOutValue(0); +#else + vtkNew thres; + thres->SetInputConnection(sampler->GetOutputPort()); + thres->SetThresholdFunction(vtkImageBinaryThreshold::THRESHOLD_LOWER); + thres->SetUpperThreshold(radius * radius); + thres->ReplaceInOn(); + thres->ReplaceOutOn(); + thres->SetInValue(i + 1); + thres->SetOutValue(0); +#endif + thres->Update(); if (i == 0) { diff --git a/src/Cxx/Points/MaskPointsFilter.cxx b/src/Cxx/Points/MaskPointsFilter.cxx index ca3d985fedb2a00524acff8deb41d6eaf190bb98..9cef7d7a30e3f3d8255af916618fc72325fdcebe 100644 --- a/src/Cxx/Points/MaskPointsFilter.cxx +++ b/src/Cxx/Points/MaskPointsFilter.cxx @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -17,6 +16,13 @@ #include #include +// #define USE_IMAGE_THRESHOLD +#ifdef USE_IMAGE_THRESHOLD +#include +#else +#include +#endif + namespace { vtkSmartPointer CreatePoints(); } @@ -42,6 +48,7 @@ int main(int argc, char* argv[]) reader->SetFileName(argv[1]); reader->Update(); +#ifdef USE_IMAGE_THRESHOLD vtkNew threshold; threshold->SetInputConnection(reader->GetOutputPort()); threshold->ThresholdByUpper(upper); @@ -51,6 +58,19 @@ int main(int argc, char* argv[]) threshold->SetOutValue(0); threshold->ReplaceOutOn(); threshold->Update(); +#else + vtkNew threshold; + threshold->SetInputConnection(reader->GetOutputPort()); + threshold->SetThresholdFunction(vtkImageBinaryThreshold::THRESHOLD_UPPER); + threshold->SetOutputScalarTypeToUnsignedChar(); + threshold->SetLowerThreshold(upper); + threshold->ReplaceInOn(); + threshold->ReplaceOutOn(); + threshold->SetInValue(255); + threshold->SetOutValue(0); +#endif + + threshold->Update(); imageMask = dynamic_cast(threshold->GetOutput()); } vtkNew pointSource; @@ -98,6 +118,7 @@ int main(int argc, char* argv[]) // Generate an interesting view // + renWin->Render(); ren1->GetActiveCamera()->SetPosition(1, 0, 0); ren1->GetActiveCamera()->SetFocalPoint(0, 1, 0); ren1->GetActiveCamera()->SetViewUp(0, 0, -1); @@ -129,14 +150,27 @@ vtkSmartPointer CreatePoints() sample->SetImplicitFunction(implicitFunction); sample->SetInputData(image); +#ifdef USE_IMAGE_THRESHOLD vtkNew threshold; threshold->SetInputConnection(sample->GetOutputPort()); - threshold->ThresholdByLower(.5); + threshold->ThresholdByLower(0.5); threshold->SetOutputScalarTypeToUnsignedChar(); threshold->ReplaceInOn(); threshold->SetInValue(255); threshold->SetOutValue(0); threshold->ReplaceOutOn(); +#else + vtkNew threshold; + threshold->SetInputConnection(sample->GetOutputPort()); + threshold->SetThresholdFunction(vtkImageBinaryThreshold::THRESHOLD_LOWER); + threshold->SetUpperThreshold(0.5); + threshold->SetOutputScalarTypeToUnsignedChar(); + threshold->ReplaceInOn(); + threshold->ReplaceOutOn(); + threshold->SetInValue(255); + threshold->SetOutValue(0); +#endif + threshold->Update(); imageMask = dynamic_cast(threshold->GetOutput()); return imageMask; diff --git a/src/Cxx/Visualization/ClipArt.cxx b/src/Cxx/Visualization/ClipArt.cxx index f7ac0bd62b166889124067c7a81ece174fe9bebb..ae0031409e4bd4bd281d4bc6043aa3fe2bbb2e99 100644 --- a/src/Cxx/Visualization/ClipArt.cxx +++ b/src/Cxx/Visualization/ClipArt.cxx @@ -2,13 +2,13 @@ #include #include #include +#include #include #include #include #include #include #include -#include #include #include #include @@ -25,7 +25,13 @@ #include #include -#include + +// #define USE_IMAGE_THRESHOLD +#ifdef USE_IMAGE_THRESHOLD +#include +#else +#include +#endif int main(int argc, char* argv[]) { @@ -49,12 +55,23 @@ int main(int argc, char* argv[]) extractImage->SetComponents(2); // Threshold to a black/white image. +#ifdef USE_IMAGE_THRESHOLD vtkNew threshold1; threshold1->SetInputConnection(extractImage->GetOutputPort()); threshold1->ThresholdByUpper(230); threshold1->SetInValue(255); threshold1->SetOutValue(0); threshold1->Update(); +#else + vtkNew threshold1; + threshold1->SetInputConnection(extractImage->GetOutputPort()); + threshold1->SetLowerThreshold(230); + threshold1->SetInValue(255); + threshold1->SetOutValue(0); + threshold1->ReplaceInOn(); + threshold1->ReplaceOutOn(); + threshold1->Update(); +#endif // Place a seed in each corner and label connected pixels with 255. threshold1->UpdateInformation(); diff --git a/src/Cxx/Visualization/ClipArt.md b/src/Cxx/Visualization/ClipArt.md index 51161a0284cef78208dc34f911ab5ab87252d148..67bc689a0ab6910bbbfa72d81360dcccfcbcd5d2 100644 --- a/src/Cxx/Visualization/ClipArt.md +++ b/src/Cxx/Visualization/ClipArt.md @@ -1,5 +1,5 @@ ### Description -This is an adaptation of the VTK test [clipArt.tcl](http://vtk.org/gitweb?p=VTK.git;a=blob;f=Graphics/Testing/Tcl/clipArt.tcl;h=85a39f9821b999145119a5a8ca492a6ae705ed09;hb=HEAD). Provide a jpg file with 2D clipart and the example will create 3D polydata model. The examples illustrates a number of VTK classes including vtkImageThreshold, vtkImageSeedConnectivity, vtkDecimatePro and vtkClipPolyData. +This is an adaptation of the VTK test [clipArt.tcl](http://vtk.org/gitweb?p=VTK.git;a=blob;f=Graphics/Testing/Tcl/clipArt.tcl;h=85a39f9821b999145119a5a8ca492a6ae705ed09;hb=HEAD). Provide a jpg file with 2D clipart and the example will create 3D polydata model. The examples illustrates a number of VTK classes including vtkImageBinaryThreshold, vtkImageSeedConnectivity, vtkDecimatePro and vtkClipPolyData. The example assumes that the image has a white background. Try it with this `src/Testing/Data/stormy.jpg`. diff --git a/src/Cxx/Visualization/FrogBrain.cxx b/src/Cxx/Visualization/FrogBrain.cxx index 5ad9d5c38dbc9fbd4a48d4a35d8dd2e2445dd9e7..9c49c3ac76a178302a8db650825001a11d60e690 100644 --- a/src/Cxx/Visualization/FrogBrain.cxx +++ b/src/Cxx/Visualization/FrogBrain.cxx @@ -1,7 +1,6 @@ #include #include #include -#include #include #include #include @@ -29,6 +28,13 @@ #include #endif +// #define USE_IMAGE_THRESHOLD +#ifdef USE_IMAGE_THRESHOLD +#include +#else +#include +#endif + #include #include @@ -45,7 +51,8 @@ int main(int argc, char* argv[]) if (argc < 3) { std::cerr << "Usage: " << argv[0] - << "InputFile(.mhd) Tissue e.g.frogtissue.mhd brain" << std::endl; + << "InputFile(.mhd) Tissue e.g.Frog/frogtissue.mhd brain" + << std::endl; return EXIT_FAILURE; } @@ -132,11 +139,26 @@ void CreateSmoothFrogActor(std::string const& fileName, int tissue, reader->SetFileName(fileName.c_str()); reader->Update(); +#ifdef USE_IMAGE_THRESHOLD vtkNew selectTissue; + selectTissue->SetInputConnection(reader->GetOutputPort()); selectTissue->ThresholdBetween(tissue, tissue); + selectTissue->ReplaceInOn(); selectTissue->SetInValue(255); selectTissue->SetOutValue(0); +#else + vtkNew selectTissue; selectTissue->SetInputConnection(reader->GetOutputPort()); + selectTissue->SetThresholdFunction( + vtkImageBinaryThreshold::THRESHOLD_BETWEEN); + selectTissue->SetLowerThreshold(tissue); + selectTissue->SetUpperThreshold(tissue); + selectTissue->ReplaceInOn(); + selectTissue->ReplaceOutOn(); + selectTissue->SetInValue(255); + selectTissue->SetOutValue(0); +#endif + selectTissue->Update(); int gaussianRadius = 1; double gaussianStandardDeviation = 2.0; @@ -193,11 +215,27 @@ void CreateFrogActor(std::string const& fileName, int tissue, vtkActor* actor) reader->SetFileName(fileName.c_str()); reader->Update(); +#ifdef USE_IMAGE_THRESHOLD vtkNew selectTissue; + selectTissue->SetInputConnection(reader->GetOutputPort()); selectTissue->ThresholdBetween(tissue, tissue); + selectTissue->ReplaceInOn(); selectTissue->SetInValue(255); selectTissue->SetOutValue(0); + selectTissue->Update(); +#else + vtkNew selectTissue; selectTissue->SetInputConnection(reader->GetOutputPort()); + selectTissue->SetThresholdFunction( + vtkImageBinaryThreshold::THRESHOLD_BETWEEN); + selectTissue->SetLowerThreshold(tissue); + selectTissue->SetUpperThreshold(tissue); + selectTissue->ReplaceInOn(); + selectTissue->ReplaceOutOn(); + selectTissue->SetInValue(255); + selectTissue->SetOutValue(0); +#endif + selectTissue->Update(); double isoValue = 63.5; #ifdef USE_FLYING_EDGES diff --git a/src/Cxx/Visualization/FroggieSurface.cxx b/src/Cxx/Visualization/FroggieSurface.cxx index c87d84d72c61c438e4240655620cc6de98d81451..ba03d42737ccd8fa539b176df622355ebbc1dd43 100644 --- a/src/Cxx/Visualization/FroggieSurface.cxx +++ b/src/Cxx/Visualization/FroggieSurface.cxx @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -47,6 +46,13 @@ #include #include +// #define USE_IMAGE_THRESHOLD +#ifdef USE_IMAGE_THRESHOLD +#include +#else +#include +#endif + namespace fs = std::filesystem; namespace { @@ -972,7 +978,11 @@ void CreateTissueActor( auto gaussianFlag{false}; vtkNew islandRemover; +#ifdef USE_IMAGE_THRESHOLD vtkNew selectTissue; +#else + vtkNew selectTissue; +#endif if (name != "skin") { auto islandRemoverFlag{false}; @@ -988,9 +998,22 @@ void CreateTissueActor( islandRemover->Update(); islandRemoverFlag = true; } +#ifdef USE_IMAGE_THRESHOLD selectTissue->ThresholdBetween(idx, idx); + selectTissue->ReplaceInOn(); + selectTissue->ReplaceOutOn(); + selectTissue->SetInValue(255); + selectTissue->SetOutValue(0); +#else + selectTissue->SetThresholdFunction( + vtkImageBinaryThreshold::THRESHOLD_BETWEEN); + selectTissue->SetLowerThreshold(idx); + selectTissue->SetUpperThreshold(idx); + selectTissue->ReplaceInOn(); + selectTissue->ReplaceOutOn(); selectTissue->SetInValue(255); selectTissue->SetOutValue(0); +#endif if (islandRemoverFlag) { selectTissue->SetInputConnection(islandRemover->GetOutputPort()); diff --git a/src/Python/ImageProcessing/HybridMedianComparison.py b/src/Python/ImageProcessing/HybridMedianComparison.py index fc6b9b28b55162c621f028778f7bb4b38626839e..bdec55eae421ec4be6a63ad427ba2ca79468b487 100755 --- a/src/Python/ImageProcessing/HybridMedianComparison.py +++ b/src/Python/ImageProcessing/HybridMedianComparison.py @@ -1,12 +1,12 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # noinspection PyUnresolvedReferences import vtkmodules.vtkRenderingOpenGL2 from vtkmodules.vtkCommonDataModel import vtkImageData from vtkmodules.vtkIOImage import vtkImageReader2Factory from vtkmodules.vtkImagingCore import ( + vtkImageBinaryThreshold, vtkImageCast, - vtkImageThreshold ) from vtkmodules.vtkImagingGeneral import ( vtkImageHybridMedian2D, @@ -26,19 +26,19 @@ from vtkmodules.vtkRenderingCore import ( def main(): # colors = vtkNamedColors() - fileName = get_program_parameters() + file_name = get_program_parameters() # Read the image. - readerFactory = vtkImageReader2Factory() - reader = readerFactory.CreateImageReader2(fileName) - reader.SetFileName(fileName) + reader_factory = vtkImageReader2Factory() + reader = reader_factory.CreateImageReader2(file_name) + reader.SetFileName(file_name) reader.Update() - scalarRange = [0] * 2 - scalarRange[0] = reader.GetOutput().GetPointData().GetScalars().GetRange()[0] - scalarRange[1] = reader.GetOutput().GetPointData().GetScalars().GetRange()[1] - print("Range:", scalarRange) - middleSlice = (reader.GetOutput().GetExtent()[5] - reader.GetOutput().GetExtent()[4]) // 2 + scalar_range = [0] * 2 + scalar_range[0] = reader.GetOutput().GetPointData().GetScalars().GetRange()[0] + scalar_range[1] = reader.GetOutput().GetPointData().GetScalars().GetRange()[1] + print("Range:", scalar_range) + middle_slice = (reader.GetOutput().GetExtent()[5] - reader.GetOutput().GetExtent()[4]) // 2 # Work with double images. cast = vtkImageCast() @@ -46,99 +46,98 @@ def main(): cast.SetOutputScalarTypeToDouble() cast.Update() - originalData = vtkImageData() - originalData.DeepCopy(cast.GetOutput()) + original_data = vtkImageData() + original_data.DeepCopy(cast.GetOutput()) - noisyData = vtkImageData() + noisy_data = vtkImageData() - AddShotNoise(originalData, noisyData, 2000.0, 0.1, reader.GetOutput().GetExtent()) + add_shot_noise(original_data, noisy_data, 2000.0, 0.1, reader.GetOutput().GetExtent()) median = vtkImageMedian3D() - median.SetInputData(noisyData) + median.SetInputData(noisy_data) median.SetKernelSize(5, 5, 1) - hybridMedian1 = vtkImageHybridMedian2D() - hybridMedian1.SetInputData(noisyData) - hybridMedian = vtkImageHybridMedian2D() - hybridMedian.SetInputConnection(hybridMedian1.GetOutputPort()) - - colorWindow = (scalarRange[1] - scalarRange[0]) * 0.8 - colorLevel = colorWindow / 2 - originalActor = vtkImageActor() - originalActor.GetMapper().SetInputData(originalData) - originalActor.GetProperty().SetColorWindow(colorWindow) - originalActor.GetProperty().SetColorLevel(colorLevel) - originalActor.GetProperty().SetInterpolationTypeToNearest() - originalActor.SetDisplayExtent(reader.GetDataExtent()[0], reader.GetDataExtent()[1], reader.GetDataExtent()[2], - reader.GetDataExtent()[3], middleSlice, middleSlice) - - noisyActor = vtkImageActor() - noisyActor.GetMapper().SetInputData(noisyData) - noisyActor.GetProperty().SetColorWindow(colorWindow) - noisyActor.GetProperty().SetColorLevel(colorLevel) - noisyActor.GetProperty().SetInterpolationTypeToNearest() - noisyActor.SetDisplayExtent(originalActor.GetDisplayExtent()) - - hybridMedianActor = vtkImageActor() - hybridMedianActor.GetMapper().SetInputConnection(hybridMedian.GetOutputPort()) - hybridMedianActor.GetProperty().SetColorWindow(colorWindow) - hybridMedianActor.GetProperty().SetColorLevel(colorLevel) - hybridMedianActor.GetProperty().SetInterpolationTypeToNearest() - hybridMedianActor.SetDisplayExtent(originalActor.GetDisplayExtent()) - - medianActor = vtkImageActor() - medianActor.GetMapper().SetInputConnection(median.GetOutputPort()) - medianActor.GetProperty().SetColorWindow(colorWindow) - medianActor.GetProperty().SetColorLevel(colorLevel) - medianActor.GetProperty().SetInterpolationTypeToNearest() + hybrid_median_1 = vtkImageHybridMedian2D() + hybrid_median_1.SetInputData(noisy_data) + hybrid_median = vtkImageHybridMedian2D() + hybrid_median.SetInputConnection(hybrid_median_1.GetOutputPort()) + + color_window = (scalar_range[1] - scalar_range[0]) * 0.8 + color_level = color_window / 2 + original_actor = vtkImageActor() + original_actor.GetMapper().SetInputData(original_data) + original_actor.GetProperty().SetColorWindow(color_window) + original_actor.GetProperty().SetColorLevel(color_level) + original_actor.GetProperty().SetInterpolationTypeToNearest() + original_actor.SetDisplayExtent(reader.GetDataExtent()[0], reader.GetDataExtent()[1], reader.GetDataExtent()[2], + reader.GetDataExtent()[3], middle_slice, middle_slice) + + noisy_actor = vtkImageActor() + noisy_actor.GetMapper().SetInputData(noisy_data) + noisy_actor.GetProperty().SetColorWindow(color_window) + noisy_actor.GetProperty().SetColorLevel(color_level) + noisy_actor.GetProperty().SetInterpolationTypeToNearest() + noisy_actor.SetDisplayExtent(original_actor.GetDisplayExtent()) + + hybrid_median_actor = vtkImageActor() + hybrid_median_actor.GetMapper().SetInputConnection(hybrid_median.GetOutputPort()) + hybrid_median_actor.GetProperty().SetColorWindow(color_window) + hybrid_median_actor.GetProperty().SetColorLevel(color_level) + hybrid_median_actor.GetProperty().SetInterpolationTypeToNearest() + hybrid_median_actor.SetDisplayExtent(original_actor.GetDisplayExtent()) + + median_actor = vtkImageActor() + median_actor.GetMapper().SetInputConnection(median.GetOutputPort()) + median_actor.GetProperty().SetColorWindow(color_window) + median_actor.GetProperty().SetColorLevel(color_level) + median_actor.GetProperty().SetInterpolationTypeToNearest() # Setup the renderers. - originalRenderer = vtkRenderer() - originalRenderer.AddActor(originalActor) - noisyRenderer = vtkRenderer() - noisyRenderer.AddActor(noisyActor) - hybridRenderer = vtkRenderer() - hybridRenderer.AddActor(hybridMedianActor) - medianRenderer = vtkRenderer() - medianRenderer.AddActor(medianActor) + originalrenderer = vtkRenderer() + originalrenderer.AddActor(original_actor) + noisy_renderer = vtkRenderer() + noisy_renderer.AddActor(noisy_actor) + hybrid_renderer = vtkRenderer() + hybrid_renderer.AddActor(hybrid_median_actor) + median_renderer = vtkRenderer() + median_renderer.AddActor(median_actor) renderers = list() - renderers.append(originalRenderer) - renderers.append(noisyRenderer) - renderers.append(hybridRenderer) - renderers.append(medianRenderer) + renderers.append(originalrenderer) + renderers.append(noisy_renderer) + renderers.append(hybrid_renderer) + renderers.append(median_renderer) # Setup viewports for the renderers. - rendererSize = 400 - xGridDimensions = 2 - yGridDimensions = 2 - - renderWindow = vtkRenderWindow() - renderWindow.SetSize( - rendererSize * xGridDimensions, rendererSize * yGridDimensions) - for row in range(0, yGridDimensions): - for col in range(xGridDimensions): - index = row * xGridDimensions + col + renderer_size = 400 + x_grid_dimensions = 2 + y_grid_dimensions = 2 + + render_window = vtkRenderWindow() + render_window.SetSize(renderer_size * x_grid_dimensions, renderer_size * y_grid_dimensions) + for row in range(0, y_grid_dimensions): + for col in range(x_grid_dimensions): + index = row * x_grid_dimensions + col # (xmin, ymin, xmax, ymax) - viewport = [float(col) / xGridDimensions, float(yGridDimensions - (row + 1)) / yGridDimensions, - float(col + 1) / xGridDimensions, float(yGridDimensions - row) / yGridDimensions] + viewport = [float(col) / x_grid_dimensions, float(y_grid_dimensions - (row + 1)) / y_grid_dimensions, + float(col + 1) / x_grid_dimensions, float(y_grid_dimensions - row) / y_grid_dimensions] renderers[index].SetViewport(viewport) - renderWindow.AddRenderer(renderers[index]) - renderWindow.SetWindowName('HybridMedianComparison') + render_window.AddRenderer(renderers[index]) + render_window.SetWindowName('HybridMedianComparison') - renderWindowInteractor = vtkRenderWindowInteractor() + render_window_interactor = vtkRenderWindowInteractor() style = vtkInteractorStyleImage() - renderWindowInteractor.SetInteractorStyle(style) - renderWindowInteractor.SetRenderWindow(renderWindow) + render_window_interactor.SetInteractorStyle(style) + render_window_interactor.SetRenderWindow(render_window) # The renderers share one camera. - renderWindow.Render() + render_window.Render() renderers[0].GetActiveCamera().Dolly(1.5) renderers[0].ResetCameraClippingRange() for r in range(1, len(renderers)): renderers[r].SetActiveCamera(renderers[0].GetActiveCamera()) - renderWindowInteractor.Initialize() - renderWindowInteractor.Start() + render_window_interactor.Initialize() + render_window_interactor.Start() def get_program_parameters(): @@ -154,34 +153,41 @@ def get_program_parameters(): return args.filename -def AddShotNoise(inputImage, outputImage, noiseAmplitude, noiseFraction, extent): - shotNoiseSource = vtkImageNoiseSource() - shotNoiseSource.SetWholeExtent(extent) - shotNoiseSource.SetMinimum(0.0) - shotNoiseSource.SetMaximum(1.0) - - shotNoiseThresh1 = vtkImageThreshold() - shotNoiseThresh1.SetInputConnection(shotNoiseSource.GetOutputPort()) - shotNoiseThresh1.ThresholdByLower(1.0 - noiseFraction) - shotNoiseThresh1.SetInValue(0) - shotNoiseThresh1.SetOutValue(noiseAmplitude) - shotNoiseThresh2 = vtkImageThreshold() - shotNoiseThresh2.SetInputConnection(shotNoiseSource.GetOutputPort()) - shotNoiseThresh2.ThresholdByLower(noiseFraction) - shotNoiseThresh2.SetInValue(1.0 - noiseAmplitude) - shotNoiseThresh2.SetOutValue(0.0) - - shotNoise = vtkImageMathematics() - shotNoise.SetInputConnection(0, shotNoiseThresh1.GetOutputPort()) - shotNoise.SetInputConnection(1, shotNoiseThresh2.GetOutputPort()) - shotNoise.SetOperationToAdd() +def add_shot_noise(input_image, output_image, noise_amplitude, noise_fraction, extent): + shot_noise_source = vtkImageNoiseSource() + shot_noise_source.SetWholeExtent(extent) + shot_noise_source.SetMinimum(0.0) + shot_noise_source.SetMaximum(1.0) + + shot_noise_thresh_1 = vtkImageBinaryThreshold() + shot_noise_thresh_1.SetInputConnection(shot_noise_source.GetOutputPort()) + shot_noise_thresh_1.SetThresholdFunction(vtkImageBinaryThreshold.THRESHOLD_UPPER) + shot_noise_thresh_1.SetLowerThreshold(1.0 - noise_fraction) + shot_noise_thresh_1.ReplaceInOn() + shot_noise_thresh_1.ReplaceOutOn() + shot_noise_thresh_1.SetInValue(0) + shot_noise_thresh_1.SetOutValue(noise_amplitude) + + shot_noise_thresh_2 = vtkImageBinaryThreshold() + shot_noise_thresh_2.SetInputConnection(shot_noise_source.GetOutputPort()) + shot_noise_thresh_2.SetThresholdFunction(vtkImageBinaryThreshold.THRESHOLD_UPPER) + shot_noise_thresh_2.SetLowerThreshold(noise_fraction) + shot_noise_thresh_2.ReplaceInOn() + shot_noise_thresh_2.ReplaceOutOn() + shot_noise_thresh_2.SetInValue(1.0 - noise_amplitude) + shot_noise_thresh_2.SetOutValue(0.0) + + shot_noise = vtkImageMathematics() + shot_noise.SetInputConnection(0, shot_noise_thresh_1.GetOutputPort()) + shot_noise.SetInputConnection(1, shot_noise_thresh_2.GetOutputPort()) + shot_noise.SetOperationToAdd() add = vtkImageMathematics() - add.SetInputData(0, inputImage) - add.SetInputConnection(1, shotNoise.GetOutputPort()) + add.SetInputData(0, input_image) + add.SetInputConnection(1, shot_noise.GetOutputPort()) add.SetOperationToAdd() add.Update() - outputImage.DeepCopy(add.GetOutput()) + output_image.DeepCopy(add.GetOutput()) if __name__ == '__main__': diff --git a/src/Python/ImageProcessing/MedianComparison.py b/src/Python/ImageProcessing/MedianComparison.py index 0e5b137a269348da6131fb136246ad1903e24404..94b455e28daa5bd0cd4144b97c746ac720a61a1e 100755 --- a/src/Python/ImageProcessing/MedianComparison.py +++ b/src/Python/ImageProcessing/MedianComparison.py @@ -1,12 +1,12 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # noinspection PyUnresolvedReferences import vtkmodules.vtkRenderingOpenGL2 from vtkmodules.vtkCommonDataModel import vtkImageData from vtkmodules.vtkIOImage import vtkImageReader2Factory from vtkmodules.vtkImagingCore import ( - vtkImageCast, - vtkImageThreshold + vtkImageBinaryThreshold, + vtkImageCast ) from vtkmodules.vtkImagingGeneral import ( vtkImageGaussianSmooth, @@ -26,19 +26,19 @@ from vtkmodules.vtkRenderingCore import ( def main(): # colors = vtkNamedColors() - fileName = get_program_parameters() + file_name = get_program_parameters() # Read the image. readerFactory = vtkImageReader2Factory() - reader = readerFactory.CreateImageReader2(fileName) - reader.SetFileName(fileName) + reader = readerFactory.CreateImageReader2(file_name) + reader.SetFileName(file_name) reader.Update() - scalarRange = [0] * 2 - scalarRange[0] = reader.GetOutput().GetPointData().GetScalars().GetRange()[0] - scalarRange[1] = reader.GetOutput().GetPointData().GetScalars().GetRange()[1] - print("Range:", scalarRange) - middleSlice = (reader.GetOutput().GetExtent()[5] - reader.GetOutput().GetExtent()[4]) // 2 + scalar_range = [0] * 2 + scalar_range[0] = reader.GetOutput().GetPointData().GetScalars().GetRange()[0] + scalar_range[1] = reader.GetOutput().GetPointData().GetScalars().GetRange()[1] + print("Range:", scalar_range) + middle_slice = (reader.GetOutput().GetExtent()[5] - reader.GetOutput().GetExtent()[4]) // 2 # Work with double images cast = vtkImageCast() @@ -46,12 +46,12 @@ def main(): cast.SetOutputScalarTypeToDouble() cast.Update() - originalData = vtkImageData() - originalData.DeepCopy(cast.GetOutput()) + original_data = vtkImageData() + original_data.DeepCopy(cast.GetOutput()) noisyData = vtkImageData() - AddShotNoise(originalData, noisyData, 2000.0, 0.1, reader.GetOutput().GetExtent()) + add_shot_noise(original_data, noisyData, 2000.0, 0.1, reader.GetOutput().GetExtent()) median = vtkImageMedian3D() median.SetInputData(noisyData) median.SetKernelSize(5, 5, 1) @@ -62,84 +62,84 @@ def main(): gaussian.SetStandardDeviations(2.0, 2.0) gaussian.SetRadiusFactors(2.0, 2.0) - colorWindow = (scalarRange[1] - scalarRange[0]) * 0.8 - colorLevel = colorWindow / 2 - originalActor = vtkImageActor() - originalActor.GetMapper().SetInputData(originalData) - originalActor.GetProperty().SetColorWindow(colorWindow) - originalActor.GetProperty().SetColorLevel(colorLevel) - originalActor.GetProperty().SetInterpolationTypeToNearest() - originalActor.SetZSlice(middleSlice) - - noisyActor = vtkImageActor() - noisyActor.GetMapper().SetInputData(noisyData) - noisyActor.GetProperty().SetColorWindow(colorWindow) - noisyActor.GetProperty().SetColorLevel(colorLevel) - noisyActor.GetProperty().SetInterpolationTypeToNearest() - noisyActor.SetZSlice(middleSlice) - - gaussianActor = vtkImageActor() - gaussianActor.GetMapper().SetInputConnection(gaussian.GetOutputPort()) - gaussianActor.GetProperty().SetColorWindow(colorWindow) - gaussianActor.GetProperty().SetColorLevel(colorLevel) - gaussianActor.GetProperty().SetInterpolationTypeToNearest() - gaussianActor.SetZSlice(middleSlice) - - medianActor = vtkImageActor() - medianActor.GetMapper().SetInputConnection(median.GetOutputPort()) - medianActor.GetProperty().SetColorWindow(colorWindow) - medianActor.GetProperty().SetColorLevel(colorLevel) - medianActor.GetProperty().SetInterpolationTypeToNearest() - medianActor.SetZSlice(middleSlice) + color_window = (scalar_range[1] - scalar_range[0]) * 0.8 + color_level = color_window / 2 + original_actor = vtkImageActor() + original_actor.GetMapper().SetInputData(original_data) + original_actor.GetProperty().SetColorWindow(color_window) + original_actor.GetProperty().SetColorLevel(color_level) + original_actor.GetProperty().SetInterpolationTypeToNearest() + original_actor.SetZSlice(middle_slice) + + noisy_actor = vtkImageActor() + noisy_actor.GetMapper().SetInputData(noisyData) + noisy_actor.GetProperty().SetColorWindow(color_window) + noisy_actor.GetProperty().SetColorLevel(color_level) + noisy_actor.GetProperty().SetInterpolationTypeToNearest() + noisy_actor.SetZSlice(middle_slice) + + gaussian_actor = vtkImageActor() + gaussian_actor.GetMapper().SetInputConnection(gaussian.GetOutputPort()) + gaussian_actor.GetProperty().SetColorWindow(color_window) + gaussian_actor.GetProperty().SetColorLevel(color_level) + gaussian_actor.GetProperty().SetInterpolationTypeToNearest() + gaussian_actor.SetZSlice(middle_slice) + + median_actor = vtkImageActor() + median_actor.GetMapper().SetInputConnection(median.GetOutputPort()) + median_actor.GetProperty().SetColorWindow(color_window) + median_actor.GetProperty().SetColorLevel(color_level) + median_actor.GetProperty().SetInterpolationTypeToNearest() + median_actor.SetZSlice(middle_slice) # Setup the renderers. - originalRenderer = vtkRenderer() - originalRenderer.AddActor(originalActor) - noisyRenderer = vtkRenderer() - noisyRenderer.AddActor(noisyActor) - gaussRenderer = vtkRenderer() - gaussRenderer.AddActor(gaussianActor) - medianRenderer = vtkRenderer() - medianRenderer.AddActor(medianActor) + original_renderer = vtkRenderer() + original_renderer.AddActor(original_actor) + noisy_renderer = vtkRenderer() + noisy_renderer.AddActor(noisy_actor) + gauss_renderer = vtkRenderer() + gauss_renderer.AddActor(gaussian_actor) + median_renderer = vtkRenderer() + median_renderer.AddActor(median_actor) renderers = list() - renderers.append(originalRenderer) - renderers.append(noisyRenderer) - renderers.append(gaussRenderer) - renderers.append(medianRenderer) + renderers.append(original_renderer) + renderers.append(noisy_renderer) + renderers.append(gauss_renderer) + renderers.append(median_renderer) # Setup viewports for the renderers. - rendererSize = 400 - xGridDimensions = 2 - yGridDimensions = 2 - - renderWindow = vtkRenderWindow() - renderWindow.SetSize( - rendererSize * xGridDimensions, rendererSize * yGridDimensions) - for row in range(0, yGridDimensions): - for col in range(xGridDimensions): - index = row * xGridDimensions + col + renderer_size = 400 + x_grid_dimensions = 2 + y_grid_dimensions = 2 + + render_window = vtkRenderWindow() + render_window.SetSize( + renderer_size * x_grid_dimensions, renderer_size * y_grid_dimensions) + for row in range(0, y_grid_dimensions): + for col in range(x_grid_dimensions): + index = row * x_grid_dimensions + col # (xmin, ymin, xmax, ymax) - viewport = [float(col) / xGridDimensions, float(yGridDimensions - (row + 1)) / yGridDimensions, - float(col + 1) / xGridDimensions, float(yGridDimensions - row) / yGridDimensions] + viewport = [float(col) / x_grid_dimensions, float(y_grid_dimensions - (row + 1)) / y_grid_dimensions, + float(col + 1) / x_grid_dimensions, float(y_grid_dimensions - row) / y_grid_dimensions] renderers[index].SetViewport(viewport) - renderWindow.AddRenderer(renderers[index]) - renderWindow.SetWindowName('MedianComparison') + render_window.AddRenderer(renderers[index]) + render_window.SetWindowName('MedianComparison') - renderWindowInteractor = vtkRenderWindowInteractor() + render_window_interactor = vtkRenderWindowInteractor() style = vtkInteractorStyleImage() - renderWindowInteractor.SetInteractorStyle(style) - renderWindowInteractor.SetRenderWindow(renderWindow) + render_window_interactor.SetInteractorStyle(style) + render_window_interactor.SetRenderWindow(render_window) # The renderers share one camera. - renderWindow.Render() + render_window.Render() renderers[0].GetActiveCamera().Dolly(1.5) renderers[0].ResetCameraClippingRange() for r in range(1, len(renderers)): renderers[r].SetActiveCamera(renderers[0].GetActiveCamera()) - renderWindowInteractor.Initialize() - renderWindowInteractor.Start() + render_window_interactor.Initialize() + render_window_interactor.Start() def get_program_parameters(): @@ -154,34 +154,41 @@ def get_program_parameters(): return args.filename -def AddShotNoise(inputImage, outputImage, noiseAmplitude, noiseFraction, extent): - shotNoiseSource = vtkImageNoiseSource() - shotNoiseSource.SetWholeExtent(extent) - shotNoiseSource.SetMinimum(0.0) - shotNoiseSource.SetMaximum(1.0) - - shotNoiseThresh1 = vtkImageThreshold() - shotNoiseThresh1.SetInputConnection(shotNoiseSource.GetOutputPort()) - shotNoiseThresh1.ThresholdByLower(1.0 - noiseFraction) - shotNoiseThresh1.SetInValue(0) - shotNoiseThresh1.SetOutValue(noiseAmplitude) - shotNoiseThresh2 = vtkImageThreshold() - shotNoiseThresh2.SetInputConnection(shotNoiseSource.GetOutputPort()) - shotNoiseThresh2.ThresholdByLower(noiseFraction) - shotNoiseThresh2.SetInValue(1.0 - noiseAmplitude) - shotNoiseThresh2.SetOutValue(0.0) - - shotNoise = vtkImageMathematics() - shotNoise.SetInputConnection(0, shotNoiseThresh1.GetOutputPort()) - shotNoise.SetInputConnection(1, shotNoiseThresh2.GetOutputPort()) - shotNoise.SetOperationToAdd() +def add_shot_noise(input_image, output_image, noise_amplitude, noise_fraction, extent): + shot_noise_source = vtkImageNoiseSource() + shot_noise_source.SetWholeExtent(extent) + shot_noise_source.SetMinimum(0.0) + shot_noise_source.SetMaximum(1.0) + + shot_noise_thresh_1 = vtkImageBinaryThreshold() + shot_noise_thresh_1.SetInputConnection(shot_noise_source.GetOutputPort()) + shot_noise_thresh_1.SetThresholdFunction(vtkImageBinaryThreshold.THRESHOLD_UPPER) + shot_noise_thresh_1.SetLowerThreshold(1.0 - noise_fraction) + shot_noise_thresh_1.ReplaceInOn() + shot_noise_thresh_1.ReplaceOutOn() + shot_noise_thresh_1.SetInValue(0) + shot_noise_thresh_1.SetOutValue(noise_amplitude) + + shot_noise_thresh_2 = vtkImageBinaryThreshold() + shot_noise_thresh_2.SetInputConnection(shot_noise_source.GetOutputPort()) + shot_noise_thresh_2.SetThresholdFunction(vtkImageBinaryThreshold.THRESHOLD_UPPER) + shot_noise_thresh_2.SetLowerThreshold(noise_fraction) + shot_noise_thresh_2.ReplaceInOn() + shot_noise_thresh_2.ReplaceOutOn() + shot_noise_thresh_2.SetInValue(1.0 - noise_amplitude) + shot_noise_thresh_2.SetOutValue(0.0) + + shot_noise = vtkImageMathematics() + shot_noise.SetInputConnection(0, shot_noise_thresh_1.GetOutputPort()) + shot_noise.SetInputConnection(1, shot_noise_thresh_2.GetOutputPort()) + shot_noise.SetOperationToAdd() add = vtkImageMathematics() - add.SetInputData(0, inputImage) - add.SetInputConnection(1, shotNoise.GetOutputPort()) + add.SetInputData(0, input_image) + add.SetInputConnection(1, shot_noise.GetOutputPort()) add.SetOperationToAdd() add.Update() - outputImage.DeepCopy(add.GetOutput()) + output_image.DeepCopy(add.GetOutput()) if __name__ == '__main__': diff --git a/src/Python/Modelling/DiscreteMarchingCubes.py b/src/Python/Modelling/DiscreteMarchingCubes.py index 1f7c84d1b82b92094447dd93bcf76cde37e0053e..40c5dd92102357d3da094072450ef420af81bbb3 100755 --- a/src/Python/Modelling/DiscreteMarchingCubes.py +++ b/src/Python/Modelling/DiscreteMarchingCubes.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # noinspection PyUnresolvedReferences import vtkmodules.vtkInteractionStyle @@ -19,7 +19,7 @@ from vtkmodules.vtkFiltersGeneral import ( vtkDiscreteFlyingEdges3D, vtkDiscreteMarchingCubes ) -from vtkmodules.vtkImagingCore import vtkImageThreshold +from vtkmodules.vtkImagingCore import vtkImageBinaryThreshold from vtkmodules.vtkImagingHybrid import vtkSampleFunction from vtkmodules.vtkImagingMath import vtkImageMathematics from vtkmodules.vtkRenderingCore import ( @@ -127,13 +127,15 @@ def make_blob(n, radius): sampler.SetSampleDimensions(100, 100, 100) sampler.SetModelBounds(-50, 50, -50, 50, -50, 50) - thres = vtkImageThreshold() + thres = vtkImageBinaryThreshold() thres.SetInputConnection(sampler.GetOutputPort()) - thres.ThresholdByLower(radius * radius) + thres.SetThresholdFunction(vtkImageBinaryThreshold.THRESHOLD_LOWER) + thres.SetUpperThreshold(radius * radius) thres.ReplaceInOn() thres.ReplaceOutOn() thres.SetInValue(i + 1) thres.SetOutValue(0) + thres.Update() if i == 0: blob_image.DeepCopy(thres.GetOutput()) diff --git a/src/Python/Modelling/SmoothDiscreteMarchingCubes.py b/src/Python/Modelling/SmoothDiscreteMarchingCubes.py index 74021b94773d0f38931aa346dd9de6544968dca1..74cd4a66a82ddbbdd5352852ef83620ffb53f94c 100755 --- a/src/Python/Modelling/SmoothDiscreteMarchingCubes.py +++ b/src/Python/Modelling/SmoothDiscreteMarchingCubes.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # noinspection PyUnresolvedReferences import vtkmodules.vtkInteractionStyle @@ -15,7 +15,7 @@ from vtkmodules.vtkCommonDataModel import ( ) from vtkmodules.vtkFiltersCore import vtkWindowedSincPolyDataFilter from vtkmodules.vtkFiltersGeneral import vtkDiscreteMarchingCubes -from vtkmodules.vtkImagingCore import vtkImageThreshold +from vtkmodules.vtkImagingCore import vtkImageBinaryThreshold from vtkmodules.vtkImagingHybrid import vtkSampleFunction from vtkmodules.vtkImagingMath import vtkImageMathematics from vtkmodules.vtkRenderingCore import ( @@ -107,13 +107,15 @@ def make_blob(n, radius): sampler.SetSampleDimensions(100, 100, 100) sampler.SetModelBounds(-50, 50, -50, 50, -50, 50) - thres = vtkImageThreshold() + thres = vtkImageBinaryThreshold() thres.SetInputConnection(sampler.GetOutputPort()) - thres.ThresholdByLower(radius * radius) + thres.SetThresholdFunction(vtkImageBinaryThreshold.THRESHOLD_LOWER) + thres.SetUpperThreshold(radius * radius) thres.ReplaceInOn() thres.ReplaceOutOn() thres.SetInValue(i + 1) thres.SetOutValue(0) + thres.Update() if i == 0: blob_image.DeepCopy(thres.GetOutput()) diff --git a/src/Python/Visualization/FrogBrain.py b/src/Python/Visualization/FrogBrain.py index 567dca685dbcfd006de225784eb83fa6d8dac6dc..866b58962bde3fec82e686b503945c53d83abded 100755 --- a/src/Python/Visualization/FrogBrain.py +++ b/src/Python/Visualization/FrogBrain.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 from pathlib import Path @@ -20,7 +20,7 @@ from vtkmodules.vtkFiltersCore import ( vtkWindowedSincPolyDataFilter ) from vtkmodules.vtkIOImage import vtkMetaImageReader -from vtkmodules.vtkImagingCore import vtkImageThreshold +from vtkmodules.vtkImagingCore import vtkImageBinaryThreshold from vtkmodules.vtkImagingGeneral import vtkImageGaussianSmooth from vtkmodules.vtkRenderingCore import ( vtkActor, @@ -39,7 +39,7 @@ def get_program_parameters(argv): ''' parser = argparse.ArgumentParser(description=description, epilog=epilogue, formatter_class=argparse.RawDescriptionHelpFormatter) - parser.add_argument('data_folder', help='The path to the file: frogtissue.mhd.') + parser.add_argument('data_folder', help='The path to the folder containing frogtissue.mhd.') parser.add_argument('tissue', default='brain', nargs='?', help='The tissue to use.') args = parser.parse_args() return args.data_folder, args.tissue @@ -85,7 +85,7 @@ def main(data_folder, tissue): actor_smooth = create_smooth_frog_actor(file_name, tissue_map[tissue], use_flying_edges) actor_smooth.GetProperty().SetDiffuseColor(lut.GetTableValue(tissue_map[tissue])[:3]) actor_smooth.GetProperty().SetDiffuse(1.0) - actor_smooth.GetProperty().SetSpecular(.5) + actor_smooth.GetProperty().SetSpecular(0.5) actor_smooth.GetProperty().SetSpecularPower(100) renderer_right.AddActor(actor_smooth) @@ -111,11 +111,16 @@ def create_smooth_frog_actor(file_name, tissue, use_flying_edges): reader.SetFileName(str(file_name)) reader.Update() - select_tissue = vtkImageThreshold() - select_tissue.ThresholdBetween(tissue, tissue) + select_tissue = vtkImageBinaryThreshold() + select_tissue.SetThresholdFunction(vtkImageBinaryThreshold.THRESHOLD_BETWEEN) + select_tissue.SetLowerThreshold(tissue) + select_tissue.SetUpperThreshold(tissue) + select_tissue.ReplaceInOn() + select_tissue.ReplaceOutOn() select_tissue.SetInValue(255) select_tissue.SetOutValue(0) select_tissue.SetInputConnection(reader.GetOutputPort()) + select_tissue.Update() gaussian_radius = 1 gaussian_standard_deviation = 2.0 @@ -175,11 +180,16 @@ def create_frog_actor(file_name, tissue, use_flying_edges): reader.SetFileName(str(file_name)) reader.Update() - select_tissue = vtkImageThreshold() - select_tissue.ThresholdBetween(tissue, tissue) + select_tissue = vtkImageBinaryThreshold() + select_tissue.SetThresholdFunction(vtkImageBinaryThreshold.THRESHOLD_BETWEEN) + select_tissue.SetLowerThreshold(tissue) + select_tissue.SetUpperThreshold(tissue) + select_tissue.ReplaceInOn() + select_tissue.ReplaceOutOn() select_tissue.SetInValue(255) select_tissue.SetOutValue(0) select_tissue.SetInputConnection(reader.GetOutputPort()) + select_tissue.Update() iso_value = 63.5 if use_flying_edges: diff --git a/src/Python/Visualization/FroggieSurface.py b/src/Python/Visualization/FroggieSurface.py index 0cab6d92f27229c181d2b8b2410e4ed8d439bcdd..a2d8878eb57086ffa0856c7b37a370b8af4465aa 100755 --- a/src/Python/Visualization/FroggieSurface.py +++ b/src/Python/Visualization/FroggieSurface.py @@ -23,8 +23,9 @@ from vtkmodules.vtkFiltersCore import ( from vtkmodules.vtkFiltersGeneral import vtkTransformPolyDataFilter from vtkmodules.vtkIOImage import vtkMetaImageReader from vtkmodules.vtkImagingCore import ( + vtkImageBinaryThreshold, vtkImageShrink3D, - vtkImageThreshold + # vtkImageThreshold ) from vtkmodules.vtkImagingGeneral import vtkImageGaussianSmooth from vtkmodules.vtkImagingMorphological import vtkImageIslandRemoval2D @@ -272,7 +273,7 @@ def parse_json(fn_path): for k, v in json_data.items(): if k == 'files': if 'root' in v: - root = Path(v['root']) + root = fn_path.parent / Path(v['root']) if not root.exists(): print(f'Bad path: {root}') paths_ok = False @@ -383,11 +384,17 @@ def create_tissue_actor(name, tissue, files, flying_edges, decimate, lut, so): island_remover.Update() last_connection = island_remover - select_tissue = vtkImageThreshold() - select_tissue.ThresholdBetween(tissue['tissue'], tissue['tissue']) + select_tissue = vtkImageBinaryThreshold() + select_tissue.SetThresholdFunction(vtkImageBinaryThreshold.THRESHOLD_BETWEEN) + select_tissue.SetLowerThreshold(tissue['tissue']) + select_tissue.SetUpperThreshold(tissue['tissue']) + select_tissue.ReplaceInOn() + select_tissue.ReplaceOutOn() select_tissue.SetInValue(255) select_tissue.SetOutValue(0) select_tissue.SetInputConnection(last_connection.GetOutputPort()) + # select_tissue.Update() + last_connection = select_tissue sample_rate = [ diff --git a/src/PythonicAPI/ImageProcessing/HybridMedianComparison.py b/src/PythonicAPI/ImageProcessing/HybridMedianComparison.py index e6870f77e39869d9a39469e29610fe9872986cce..26fbda2d21913fdd6f48e4824afc50310a8da00b 100755 --- a/src/PythonicAPI/ImageProcessing/HybridMedianComparison.py +++ b/src/PythonicAPI/ImageProcessing/HybridMedianComparison.py @@ -10,11 +10,10 @@ from vtkmodules.vtkCommonColor import vtkNamedColors from vtkmodules.vtkCommonCore import vtkPoints from vtkmodules.vtkCommonDataModel import vtkCellArray, vtkPolyData, vtkPolyLine from vtkmodules.vtkCommonDataModel import vtkImageData -from vtkmodules.vtkFiltersCore import vtkAppendPolyData from vtkmodules.vtkIOImage import vtkImageReader2Factory from vtkmodules.vtkImagingCore import ( + vtkImageBinaryThreshold, vtkImageCast, - vtkImageThreshold ) from vtkmodules.vtkImagingGeneral import ( vtkImageHybridMedian2D, @@ -112,8 +111,8 @@ def main(): grid_cols = 2 grid_rows = 2 # Define side length (in pixels) of each renderer rectangle. - col_size = 255 - row_size = 255 + col_size = 400 + row_size = 400 size = (col_size * grid_cols, row_size * grid_rows) ren_win = vtkRenderWindow(size=size, window_name='HybridMedianComparison') @@ -142,16 +141,16 @@ def main(): ) if last_row and last_col: - border = ViewPort.Border.TOP_LEFT_BOTTOM_RIGHT + border = ViewPortBorders.tlbr last_row = False last_col = False elif last_col: - border = ViewPort.Border.RIGHT_TOP_LEFT + border = ViewPortBorders.rtl last_col = False elif last_row: - border = ViewPort.Border.TOP_LEFT_BOTTOM + border = ViewPortBorders.tlb else: - border = ViewPort.Border.TOP_LEFT + border = ViewPortBorders.tl vp_params = VP_Params(viewport, border) viewports[keys[index]] = vp_params @@ -194,7 +193,8 @@ def main(): # Draw a line around the viewport of each renderer. for k in actors.keys(): border = viewports[k].border - draw_viewport_border(renderers[k], border=border, color=colors.GetColor3d('Yellow'), line_width=4) + # draw_viewport_border(renderers[k], border=border, color=colors.GetColor3d('Yellow'), line_width=4) + draw_viewport_border(renderers[k], sides=border, border_color='Yellow', border_width=4) # The renderers share one camera. ren_win.Render() @@ -216,12 +216,16 @@ def main(): def add_shot_noise(input_image, noise_amplitude, noise_fraction, extent): shot_noise_source = vtkImageNoiseSource(whole_extent=extent, minimum=0.0, maximum=1.0) - shot_noise_thresh1 = vtkImageThreshold(in_value=0, out_value=noise_amplitude) - shot_noise_thresh1.ThresholdByLower(1.0 - noise_fraction) + shot_noise_thresh1 = vtkImageBinaryThreshold(in_value=0, out_value=noise_amplitude, + threshold_function=vtkImageBinaryThreshold.THRESHOLD_UPPER, + lower_threshold=1.0 - noise_fraction, + replace_in=True, replace_out=True) shot_noise_source >> shot_noise_thresh1 - shot_noise_thresh2 = vtkImageThreshold(in_value=1.0 - noise_amplitude, out_value=0.0) - shot_noise_thresh2.ThresholdByLower(noise_fraction) + shot_noise_thresh2 = vtkImageBinaryThreshold(in_value=1.0 - noise_amplitude, out_value=noise_amplitude, + threshold_function=vtkImageBinaryThreshold.THRESHOLD_UPPER, + lower_threshold=noise_fraction, + replace_in=True, replace_out=True) shot_noise_source >> shot_noise_thresh2 shot_noise = vtkImageMathematics(operation=ImageMathematics.Operation.VTK_ADD) @@ -303,95 +307,98 @@ def get_text_positions(names, justification=0, vertical_justification=0, width=0 return text_positions -def draw_viewport_border(renderer, border, color=(0, 0, 0), line_width=2): +def draw_viewport_border(renderer, sides, border_color, border_width): """ - Draw a border around the viewport of a renderer. + Set a border around a viewport. - :param renderer: The renderer. - :param border: The border to draw, it must be one of the constants in ViewPort.Border. - :param color: The color. - :param line_width: The line width of the border. + :param renderer: The renderer corresponding to the viewport. + :param sides: An array of boolean corresponding to [top, left, bottom, right] + :param border_color: The color of the border. + :param border_width: The width of the border. :return: """ + colors = vtkNamedColors() - def generate_border_lines(border_type): - """ - Generate the lines for the border. - - :param border_type: The border type to draw, it must be one of the constants in ViewPort.Border - :return: The points and lines. - """ - if border_type >= ViewPort.Border.NUMBER_OF_BORDER_TYPES: - print('Not a valid border type.') - return None - - # Points start at upper right and proceed anti-clockwise. - pts = ( - (1, 1, 0), - (0, 1, 0), - (0, 0, 0), - (1, 0, 0), - (1, 1, 0), - ) - pt_orders = { - ViewPort.Border.TOP: (0, 1), - ViewPort.Border.LEFT: (1, 2), - ViewPort.Border.BOTTOM: (2, 3), - ViewPort.Border.RIGHT: (3, 4), - ViewPort.Border.LEFT_BOTTOM: (1, 2, 3), - ViewPort.Border.BOTTOM_RIGHT: (2, 3, 4), - ViewPort.Border.RIGHT_TOP: (3, 4, 1), - ViewPort.Border.RIGHT_TOP_LEFT: (3, 4, 1, 2), - ViewPort.Border.TOP_LEFT: (0, 1, 2), - ViewPort.Border.TOP_LEFT_BOTTOM: (0, 1, 2, 3), - ViewPort.Border.TOP_LEFT_BOTTOM_RIGHT: (0, 1, 2, 3, 4) - } - pt_order = pt_orders[border_type] - number_of_points = len(pt_order) - points = vtkPoints(number_of_points=number_of_points) - i = 0 - for pt_id in pt_order: - points.InsertPoint(i, *pts[pt_id]) - i += 1 - - lines = vtkPolyLine() - lines.point_ids.SetNumberOfIds(number_of_points) - for i in range(0, number_of_points): - lines.point_ids.id = (i, i) - - cells = vtkCellArray() - cells.InsertNextCell(lines) - - # Make the polydata and return. - return vtkPolyData(points=points, lines=cells) + # Points start at upper right and proceed anti-clockwise. + points = vtkPoints() + points.SetNumberOfPoints(4) + points.InsertPoint(0, 1, 1, 0) + points.InsertPoint(1, 0, 1, 0) + points.InsertPoint(2, 0, 0, 0) + points.InsertPoint(3, 1, 0, 0) + + cells = vtkCellArray() + cells.Initialize() + + if sides[0]: + # Top + top = vtkPolyLine() + top.GetPointIds().SetNumberOfIds(2) + top.GetPointIds().SetId(0, 0) + top.GetPointIds().SetId(1, 1) + cells.InsertNextCell(top) + if sides[1]: + # Left + left = vtkPolyLine() + left.GetPointIds().SetNumberOfIds(2) + left.GetPointIds().SetId(0, 1) + left.GetPointIds().SetId(1, 2) + cells.InsertNextCell(left) + if sides[2]: + # Bottom + bottom = vtkPolyLine() + bottom.GetPointIds().SetNumberOfIds(2) + bottom.GetPointIds().SetId(0, 2) + bottom.GetPointIds().SetId(1, 3) + cells.InsertNextCell(bottom) + if sides[3]: + # Right + right = vtkPolyLine() + right.GetPointIds().SetNumberOfIds(2) + right.GetPointIds().SetId(0, 3) + right.GetPointIds().SetId(1, 0) + cells.InsertNextCell(right) + + # Now make the polydata and display it. + poly = vtkPolyData() + poly.Initialize() + poly.SetPoints(points) + poly.SetLines(cells) # Use normalized viewport coordinates since # they are independent of window size. - coordinate = vtkCoordinate(coordinate_system=Coordinate.CoordinateSystem.VTK_NORMALIZED_VIEWPORT) - poly = vtkAppendPolyData() - if border == ViewPort.Border.TOP_BOTTOM: - ( - generate_border_lines(ViewPort.Border.TOP), - generate_border_lines(ViewPort.Border.BOTTOM) - ) >> poly - elif border == ViewPort.Border.LEFT_RIGHT: - ( - generate_border_lines(ViewPort.Border.LEFT), - generate_border_lines(ViewPort.Border.RIGHT) - ) >> poly - else: - generate_border_lines(border) >> poly - - mapper = vtkPolyDataMapper2D(transform_coordinate=coordinate) - poly >> mapper - actor = vtkActor2D(mapper=mapper) - actor.property.color = color - # Line width should be at least 2 to be visible at the extremes. - actor.property.line_width = line_width + coordinate = vtkCoordinate() + coordinate.SetCoordinateSystemToNormalizedViewport() + + mapper = vtkPolyDataMapper2D() + mapper.SetInputData(poly) + mapper.SetTransformCoordinate(coordinate) + + actor = vtkActor2D() + actor.SetMapper(mapper) + actor.GetProperty().SetColor(colors.GetColor3d(border_color)) + + # Line width should be at least 2 to be visible at extremes. + actor.GetProperty().SetLineWidth(border_width) renderer.AddViewProp(actor) +@dataclass(frozen=True) +class ViewPortBorders: + # Define borders for the viewports = [top, left, bottom, right]. + t = [True, False, False, False] + l = [False, True, False, False] + b = [False, False, True, False] + r = [False, False, False, True] + lb = [False, True, True, False] + lbr = [False, True, True, True] + tlb = [True, True, True, False] + tlbr = [True, True, True, True] + rtl = [True, True, False, True] + tl = [True, True, False, False] + + @dataclass(frozen=True) class Coordinate: @dataclass(frozen=True) @@ -473,25 +480,5 @@ class TextProperty: VTK_TEXT_TOP: int = 2 -@dataclass(frozen=True) -class ViewPort: - @dataclass(frozen=True) - class Border: - TOP: int = 0 - LEFT: int = 1 - BOTTOM: int = 2 - RIGHT: int = 3 - LEFT_BOTTOM: int = 4 - BOTTOM_RIGHT: int = 5 - RIGHT_TOP: int = 6 - RIGHT_TOP_LEFT: int = 7 - TOP_LEFT: int = 8 - TOP_LEFT_BOTTOM: int = 9 - TOP_LEFT_BOTTOM_RIGHT: int = 10 - TOP_BOTTOM: int = 11 - LEFT_RIGHT: int = 12 - NUMBER_OF_BORDER_TYPES: int = 13 - - if __name__ == '__main__': main() diff --git a/src/PythonicAPI/Points/MaskPointsFilter.py b/src/PythonicAPI/Points/MaskPointsFilter.py index 51c907a90ef3eaa03c8eb7d0668917e46a8b3b1a..c08bec333beb8238641c764f7e1fccf74b96dabb 100755 --- a/src/PythonicAPI/Points/MaskPointsFilter.py +++ b/src/PythonicAPI/Points/MaskPointsFilter.py @@ -3,6 +3,7 @@ from dataclasses import dataclass from pathlib import Path +import vtk # noinspection PyUnresolvedReferences import vtkmodules.vtkInteractionStyle # noinspection PyUnresolvedReferences @@ -17,7 +18,7 @@ from vtkmodules.vtkFiltersGeneral import vtkSampleImplicitFunctionFilter from vtkmodules.vtkFiltersPoints import vtkBoundedPointSource, vtkMaskPointsFilter from vtkmodules.vtkFiltersSources import vtkSphereSource from vtkmodules.vtkIOImage import vtkMetaImageReader -from vtkmodules.vtkImagingCore import vtkImageThreshold +from vtkmodules.vtkImagingCore import vtkImageBinaryThreshold from vtkmodules.vtkRenderingCore import ( vtkActor, vtkPolyDataMapper, @@ -55,9 +56,12 @@ def main(): reader = vtkMetaImageReader(file_name=fn_path) reader.update() - threshold = vtkImageThreshold(output_scalar_type=ImageThreshold.ScalarType.VTK_UNSIGNED_CHAR, - replace_in=True, in_value=255, replace_out=True, out_value=0) - threshold.ThresholdByUpper(upper) + threshold = vtkImageBinaryThreshold(in_value=255, out_value=0, + output_scalar_type=vtk.VTK_UNSIGNED_CHAR, + threshold_function=vtkImageBinaryThreshold.THRESHOLD_UPPER, + lower_threshold=upper, + replace_in=True, replace_out=True) + reader >> threshold image_mask = threshold.update().output @@ -92,6 +96,7 @@ def main(): ren.AddActor(glyph3d_actor) # Generate an interesting view. + ren_win.Render() ren.active_camera.position = (1, 0, 0) ren.active_camera.focal_point = (0, 1, 0) ren.active_camera.view_up = (0, 0, -1) @@ -113,9 +118,12 @@ def create_points(): implicit_function = vtkCone() sample = vtkSampleImplicitFunctionFilter(implicit_function=implicit_function, input_data=image) - threshold = vtkImageThreshold(output_scalar_type=ImageThreshold.ScalarType.VTK_UNSIGNED_CHAR, - replace_in=True, in_value=255, replace_out=True, out_value=0) - threshold.ThresholdByLower(0.5) + threshold = vtkImageBinaryThreshold(in_value=255, out_value=0, + output_scalar_type=vtk.VTK_UNSIGNED_CHAR, + threshold_function=vtkImageBinaryThreshold.THRESHOLD_LOWER, + upper_threshold=0.5, + replace_in=True, replace_out=True) + sample >> threshold return threshold.update().output diff --git a/src/PythonicAPI/Snippets/DrawViewportBorder.md b/src/PythonicAPI/Snippets/DrawViewportBorder.md index 8a595345af1bccb96e8a78030328d0d674885eac..949bd6d83fae91b68c4148a875b5a5b30b49a052 100644 --- a/src/PythonicAPI/Snippets/DrawViewportBorder.md +++ b/src/PythonicAPI/Snippets/DrawViewportBorder.md @@ -8,7 +8,8 @@ To use the snippet, click the *Copy to clipboard* at the upper right of the code ``` Python # from dataclasses import dataclass -# +# +# from vtkmodules.vtkCommonColor import vtkNamedColors # from vtkmodules.vtkCommonCore import vtkPoints # from vtkmodules.vtkCommonDataModel import vtkCellArray, vtkPolyData, vtkPolyLine # from vtkmodules.vtkRenderingCore import vtkActor2D, vtkPolyDataMapper2D, vtkRenderer diff --git a/src/PythonicAPI/Visualization/FroggieSurface.py b/src/PythonicAPI/Visualization/FroggieSurface.py index a101de601b10f64f392720a5a7a90ab2b5d4b3df..0fd8a150267d008950c7d2b246fdb7a7f0eb23e8 100755 --- a/src/PythonicAPI/Visualization/FroggieSurface.py +++ b/src/PythonicAPI/Visualization/FroggieSurface.py @@ -23,8 +23,8 @@ from vtkmodules.vtkFiltersCore import ( from vtkmodules.vtkFiltersGeneral import vtkTransformPolyDataFilter from vtkmodules.vtkIOImage import vtkMetaImageReader from vtkmodules.vtkImagingCore import ( + vtkImageBinaryThreshold, vtkImageShrink3D, - vtkImageThreshold ) from vtkmodules.vtkImagingGeneral import vtkImageGaussianSmooth from vtkmodules.vtkImagingMorphological import vtkImageIslandRemoval2D @@ -367,9 +367,14 @@ def create_tissue_actor(name, tissue, files, flying_edges, decimate, lut, so): replace_value=tissue['tissue']) last_connection = island_remover - select_tissue = vtkImageThreshold(input_connection=last_connection.output_port, - in_value=255, out_value=0) - select_tissue.ThresholdBetween(tissue['tissue'], tissue['tissue']) + # select_tissue = vtkImageThreshold(input_connection=last_connection.output_port, + # in_value=255, out_value=0) + select_tissue = vtkImageBinaryThreshold(input_connection=last_connection.output_port, + in_value=255, out_value=0, + threshold_function=vtkImageBinaryThreshold.THRESHOLD_BETWEEN, + lower_threshold=tissue['tissue'], + upper_threshold=tissue['tissue'], + replace_in=True, replace_out=True) last_connection = select_tissue sample_rate = [ diff --git a/src/Testing/Baseline/PythonicAPI/ImageProcessing/TestHybridMedianComparison.png b/src/Testing/Baseline/PythonicAPI/ImageProcessing/TestHybridMedianComparison.png index 39c8a9acef6c7dd12972a5c8103e4bbe453d6443..5cc382e566be2936a1d9dd625aa61b0af900047d 100644 --- a/src/Testing/Baseline/PythonicAPI/ImageProcessing/TestHybridMedianComparison.png +++ b/src/Testing/Baseline/PythonicAPI/ImageProcessing/TestHybridMedianComparison.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:092aa368dec3d95f1e71f4efbe8772dd267964a6d968cd4264dae7e873d74cef -size 23313 +oid sha256:4e147ea1b0dd249c7e596b4893d069e6ddaf153218ee60a00cb9c29d6996e0ee +size 52992