From 8e28b03ab70b8eefd921db539dbd4d9687e67f6a Mon Sep 17 00:00:00 2001 From: Mathew Seng Date: Thu, 25 Feb 2021 12:26:26 -0600 Subject: [PATCH] ENH: BinaryMathematicalMorphology baseline testing This enables baseline testing for the BinaryMathematicalMorphology module. This specifically does the following: - Defines OutputBaseline for all baseline tests in Filtering/BinaryMathematicalMorphology/CMakeLists.txt - Implements ITK's WriteImage function for ClosingBinaryImage, OpenBinaryImage and PruneBinaryImage. - Saves new baseline images for ClosingBinaryImage, OpenBinaryImage, and PruneBinaryIamge. - Changes original output ClosingBinaryImage.png, OpenBinaryImage.png and PruneBinaryImage.png to clarify these are outputs in the QuickView window. - Allow user to define input and output file paths for ClosingBinaryImage, OpenBinaryImage, PruneBinaryImage. --- .../CMakeLists.txt | 8 +++---- ...=> ClosingBinaryImageQuickView.png.sha512} | 0 .../ClosingBinaryImage/Code.cxx | 14 +++++++---- .../ClosingBinaryImage/Documentation.rst | 2 +- .../OutputBaseline.png.sha512 | 1 + .../OpeningBinaryImage/Code.cxx | 15 ++++++++---- .../OpeningBinaryImage/Documentation.rst | 2 +- ...=> OpeningBinaryImageQuickView.png.sha512} | 0 .../OutputBaseline.png.sha512 | 1 + .../PruneBinaryImage/Code.cxx | 23 +++++++++++++++---- .../PruneBinaryImage/Documentation.rst | 2 +- .../OutputBaseline.png.sha512 | 1 + ...2 => PruneBinaryImageQuickView.png.sha512} | 0 .../ThinImage/Code.cxx | 2 +- .../ThinImage/Documentation.rst | 6 ++--- ...t.png.sha512 => OutputBaseline.png.sha512} | 0 16 files changed, 52 insertions(+), 25 deletions(-) rename src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/{ClosingBinaryImage.png.sha512 => ClosingBinaryImageQuickView.png.sha512} (100%) create mode 100644 src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/OutputBaseline.png.sha512 rename src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/{OpeningBinaryImage.png.sha512 => OpeningBinaryImageQuickView.png.sha512} (100%) create mode 100644 src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/OutputBaseline.png.sha512 create mode 100644 src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/OutputBaseline.png.sha512 rename src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/{PruneBinaryImage.png.sha512 => PruneBinaryImageQuickView.png.sha512} (100%) rename src/Filtering/BinaryMathematicalMorphology/ThinImage/{output.png.sha512 => OutputBaseline.png.sha512} (100%) diff --git a/src/Filtering/BinaryMathematicalMorphology/CMakeLists.txt b/src/Filtering/BinaryMathematicalMorphology/CMakeLists.txt index 9e1dabd31..2570279cc 100644 --- a/src/Filtering/BinaryMathematicalMorphology/CMakeLists.txt +++ b/src/Filtering/BinaryMathematicalMorphology/CMakeLists.txt @@ -12,20 +12,20 @@ compare_to_baseline( add_example(ThinImage) compare_to_baseline(EXAMPLE_NAME ThinImage - BASELINE_PREFIX output + BASELINE_PREFIX OutputBaseline ) add_example(PruneBinaryImage) compare_to_baseline(EXAMPLE_NAME PruneBinaryImage - BASELINE_PREFIX PruneBinaryImage + BASELINE_PREFIX OutputBaseline ) add_example(OpeningBinaryImage) compare_to_baseline(EXAMPLE_NAME OpeningBinaryImage - BASELINE_PREFIX OpeningBinaryImage + BASELINE_PREFIX OutputBaseline ) add_example(ClosingBinaryImage) compare_to_baseline(EXAMPLE_NAME ClosingBinaryImage - BASELINE_PREFIX ClosingBinaryImage + BASELINE_PREFIX OutputBaseline ) \ No newline at end of file diff --git a/src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/ClosingBinaryImage.png.sha512 b/src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/ClosingBinaryImageQuickView.png.sha512 similarity index 100% rename from src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/ClosingBinaryImage.png.sha512 rename to src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/ClosingBinaryImageQuickView.png.sha512 diff --git a/src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/Code.cxx b/src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/Code.cxx index 6c4758fd7..5053a9037 100644 --- a/src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/Code.cxx +++ b/src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/Code.cxx @@ -18,6 +18,7 @@ #include "itkImage.h" #include "itkBinaryMorphologicalClosingImageFilter.h" #include "itkImageFileReader.h" +#include "itkImageFileWriter.h" #include "itkBinaryBallStructuringElement.h" #include "itkSubtractImageFilter.h" @@ -37,23 +38,24 @@ int main(int argc, char * argv[]) { ImageType::Pointer image; + unsigned int radius = 5; + std::string outputFilename = "Output.png"; if (argc == 1) { image = ImageType::New(); CreateImage(image); } - else + else if (argc < 4) { image = itk::ReadImage(argv[1]); - } - unsigned int radius = 5; - if (argc == 3) - { std::stringstream ss(argv[2]); ss >> radius; + + outputFilename = argv[3]; } + std::cout << "Radius: " << radius << std::endl; using StructuringElementType = itk::BinaryBallStructuringElement; StructuringElementType structuringElement; @@ -87,6 +89,8 @@ main(int argc, char * argv[]) viewer.AddImage(diff->GetOutput(), true, desc3.str()); viewer.Visualize(); #endif + + itk::WriteImage(closingFilter->GetOutput(), outputFilename); return EXIT_SUCCESS; } diff --git a/src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/Documentation.rst b/src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/Documentation.rst index a1a37b50b..3a3cdfd79 100644 --- a/src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/Documentation.rst +++ b/src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/Documentation.rst @@ -16,7 +16,7 @@ Closing a binary image. Results ------- -.. figure:: ClosingBinaryImage.png +.. figure:: ClosingBinaryImageQuickView.png :scale: 70% Output In VTK Window diff --git a/src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/OutputBaseline.png.sha512 b/src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/OutputBaseline.png.sha512 new file mode 100644 index 000000000..630c0e6b2 --- /dev/null +++ b/src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/OutputBaseline.png.sha512 @@ -0,0 +1 @@ +a4ed65f70809fca3e1b6195fb7238e6d9ca46bc8cd1c34e1a1f3c49142633fbc5e9dcd40713c138fba71f913e6d1664c32165d3f5b89fcf046811faafca783a9 diff --git a/src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/Code.cxx b/src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/Code.cxx index f944340fe..544893a02 100644 --- a/src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/Code.cxx +++ b/src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/Code.cxx @@ -18,6 +18,7 @@ #include "itkImage.h" #include "itkBinaryMorphologicalOpeningImageFilter.h" #include "itkImageFileReader.h" +#include "itkImageFileWriter.h" #include "itkBinaryBallStructuringElement.h" #include "itkSubtractImageFilter.h" @@ -37,23 +38,24 @@ int main(int argc, char * argv[]) { ImageType::Pointer image; + unsigned int radius = 5; + std::string outputFilename = "Output.png"; if (argc == 1) { image = ImageType::New(); CreateImage(image); } - else + else if (argc < 4) { image = itk::ReadImage(argv[1]); - } - unsigned int radius = 5; - if (argc == 3) - { std::stringstream ss(argv[2]); ss >> radius; + + outputFilename = argv[3]; } + std::cout << "Radius: " << radius << std::endl; using StructuringElementType = itk::BinaryBallStructuringElement; StructuringElementType structuringElement; @@ -87,6 +89,9 @@ main(int argc, char * argv[]) viewer.AddImage(diff->GetOutput(), true, desc3.str()); viewer.Visualize(); #endif + + itk::WriteImage(openingFilter->GetOutput(), outputFilename); + return EXIT_SUCCESS; } diff --git a/src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/Documentation.rst b/src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/Documentation.rst index 47c6a727a..b1c8b348d 100644 --- a/src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/Documentation.rst +++ b/src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/Documentation.rst @@ -15,7 +15,7 @@ Opening a binary image. Results ------- -.. figure:: OpeningBinaryImage.png +.. figure:: OpeningBinaryImageQuickView.png :scale: 70% Output In VTK Window diff --git a/src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/OpeningBinaryImage.png.sha512 b/src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/OpeningBinaryImageQuickView.png.sha512 similarity index 100% rename from src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/OpeningBinaryImage.png.sha512 rename to src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/OpeningBinaryImageQuickView.png.sha512 diff --git a/src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/OutputBaseline.png.sha512 b/src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/OutputBaseline.png.sha512 new file mode 100644 index 000000000..630c0e6b2 --- /dev/null +++ b/src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/OutputBaseline.png.sha512 @@ -0,0 +1 @@ +a4ed65f70809fca3e1b6195fb7238e6d9ca46bc8cd1c34e1a1f3c49142633fbc5e9dcd40713c138fba71f913e6d1664c32165d3f5b89fcf046811faafca783a9 diff --git a/src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/Code.cxx b/src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/Code.cxx index 431109de9..7ccfb33e0 100644 --- a/src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/Code.cxx +++ b/src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/Code.cxx @@ -18,12 +18,18 @@ #include "itkImage.h" #include "itkBinaryPruningImageFilter.h" #include "itkImageFileReader.h" +#include "itkImageFileWriter.h" #include "itkBinaryBallStructuringElement.h" #ifdef ENABLE_QUICKVIEW # include "QuickView.h" #endif +namespace +{ +using ImageType = itk::Image; +} + template void CreateImage(TImage * const image); @@ -36,20 +42,26 @@ main(int argc, char * argv[]) using ImageType = itk::Image; ImageType::Pointer image; + std::string outputFilename = "Output.png"; + unsigned int iteration = 1; - unsigned int iteration = 1; - - if (argc < 3) + if (argc == 1) { image = ImageType::New(); CreateImage(image.GetPointer()); } - else + else if (argc < 4) { image = itk::ReadImage(argv[1]); + std::stringstream ssIteration(argv[2]); + ssIteration >> iteration; + + outputFilename = argv[3]; } + std::cout << "Iterations: " << iteration << std::endl; + using BinaryPruningImageFilterType = itk::BinaryPruningImageFilter; BinaryPruningImageFilterType::Pointer pruneFilter = BinaryPruningImageFilterType::New(); pruneFilter->SetInput(image); @@ -62,6 +74,9 @@ main(int argc, char * argv[]) viewer.AddImage(pruneFilter->GetOutput()); viewer.Visualize(); #endif + + itk::WriteImage(pruneFilter->GetOutput(), outputFilename); + return EXIT_SUCCESS; } diff --git a/src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/Documentation.rst b/src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/Documentation.rst index 4d125e625..e79511b33 100644 --- a/src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/Documentation.rst +++ b/src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/Documentation.rst @@ -15,7 +15,7 @@ Prune a binary image. Results ------- -.. figure:: PruneBinaryImage.png +.. figure:: PruneBinaryImageQuickView.png :scale: 70% Output In VTK Window diff --git a/src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/OutputBaseline.png.sha512 b/src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/OutputBaseline.png.sha512 new file mode 100644 index 000000000..0e28eefe1 --- /dev/null +++ b/src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/OutputBaseline.png.sha512 @@ -0,0 +1 @@ +93ed6019fefb93301ed2b358283bfabf2b0b0d7bfa1caaeb096eaf4bcfb9edd169a5406e2e7a26ff9bc6167051d04f84e79853989521cb03d6a59c1f6c889c59 diff --git a/src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/PruneBinaryImage.png.sha512 b/src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/PruneBinaryImageQuickView.png.sha512 similarity index 100% rename from src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/PruneBinaryImage.png.sha512 rename to src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/PruneBinaryImageQuickView.png.sha512 diff --git a/src/Filtering/BinaryMathematicalMorphology/ThinImage/Code.cxx b/src/Filtering/BinaryMathematicalMorphology/ThinImage/Code.cxx index b20e5eae2..e9beb537f 100644 --- a/src/Filtering/BinaryMathematicalMorphology/ThinImage/Code.cxx +++ b/src/Filtering/BinaryMathematicalMorphology/ThinImage/Code.cxx @@ -53,7 +53,7 @@ main(int argc, char * argv[]) rescaler->SetOutputMaximum(255); rescaler->Update(); - itk::WriteImage(rescaler->GetOutput(), "output.png"); + itk::WriteImage(rescaler->GetOutput(), "Output.png"); return EXIT_SUCCESS; } diff --git a/src/Filtering/BinaryMathematicalMorphology/ThinImage/Documentation.rst b/src/Filtering/BinaryMathematicalMorphology/ThinImage/Documentation.rst index 07309359b..a05f5d8f3 100644 --- a/src/Filtering/BinaryMathematicalMorphology/ThinImage/Documentation.rst +++ b/src/Filtering/BinaryMathematicalMorphology/ThinImage/Documentation.rst @@ -20,11 +20,11 @@ Results input.png -.. figure:: output.png +.. figure:: OutputBaseline.png :scale: 70% - :alt: output.png + :alt: OutputBaseline.png - output.png + OutputBaseline.png Code ---- diff --git a/src/Filtering/BinaryMathematicalMorphology/ThinImage/output.png.sha512 b/src/Filtering/BinaryMathematicalMorphology/ThinImage/OutputBaseline.png.sha512 similarity index 100% rename from src/Filtering/BinaryMathematicalMorphology/ThinImage/output.png.sha512 rename to src/Filtering/BinaryMathematicalMorphology/ThinImage/OutputBaseline.png.sha512