From b47803e733ba4977b9d9487cebb84425567fc44f Mon Sep 17 00:00:00 2001 From: Mathew Seng Date: Thu, 25 Feb 2021 12:26:26 -0600 Subject: [PATCH 1/2] 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 | 4 ++-- .../ThinImage/Code.py | 4 ++-- .../ThinImage/Documentation.rst | 10 ++++---- .../{input.png.sha512 => Input.png.sha512} | 0 ...t.png.sha512 => OutputBaseline.png.sha512} | 0 18 files changed, 57 insertions(+), 30 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/{input.png.sha512 => Input.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..ccf943e42 100644 --- a/src/Filtering/BinaryMathematicalMorphology/ThinImage/Code.cxx +++ b/src/Filtering/BinaryMathematicalMorphology/ThinImage/Code.cxx @@ -37,7 +37,7 @@ main(int argc, char * argv[]) else { CreateImage(image); - itk::WriteImage(image, "input.png"); + itk::WriteImage(image, "Input.png"); } using BinaryThinningImageFilterType = itk::BinaryThinningImageFilter; @@ -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/Code.py b/src/Filtering/BinaryMathematicalMorphology/ThinImage/Code.py index 612c9d94c..8817e99cb 100644 --- a/src/Filtering/BinaryMathematicalMorphology/ThinImage/Code.py +++ b/src/Filtering/BinaryMathematicalMorphology/ThinImage/Code.py @@ -48,7 +48,7 @@ image[50:55, 20:80] = 255 # Write Image - itk.imwrite(image, "input.png") + itk.imwrite(image, "Input.png") image = itk.binary_thinning_image_filter(image) @@ -56,4 +56,4 @@ image = itk.rescale_intensity_image_filter(image, output_minimum=0, output_maximum=255) # Write Image -itk.imwrite(image, "outputPython.png") +itk.imwrite(image, "OutputPython.png") diff --git a/src/Filtering/BinaryMathematicalMorphology/ThinImage/Documentation.rst b/src/Filtering/BinaryMathematicalMorphology/ThinImage/Documentation.rst index 07309359b..65577cdac 100644 --- a/src/Filtering/BinaryMathematicalMorphology/ThinImage/Documentation.rst +++ b/src/Filtering/BinaryMathematicalMorphology/ThinImage/Documentation.rst @@ -14,17 +14,17 @@ Skeletonix/thin an image. Results ------- -.. figure:: input.png +.. figure:: Input.png :scale: 70% - :alt: input.png + :alt: Input.png 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/input.png.sha512 b/src/Filtering/BinaryMathematicalMorphology/ThinImage/Input.png.sha512 similarity index 100% rename from src/Filtering/BinaryMathematicalMorphology/ThinImage/input.png.sha512 rename to src/Filtering/BinaryMathematicalMorphology/ThinImage/Input.png.sha512 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 From cbc92e9df3a9e79318bcc6e9cd26c6bfd4391b8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C5=BEenan=20Zuki=C4=87?= Date: Thu, 16 Sep 2021 15:47:47 -0400 Subject: [PATCH 2/2] BUG: filling the buffer was forgotten in CreateImage --- .../ClosingBinaryImage/Code.cxx | 16 ++++++++-------- .../OpeningBinaryImage/Code.cxx | 14 +++++++------- .../PruneBinaryImage/Code.cxx | 14 +++++++------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/Code.cxx b/src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/Code.cxx index 5053a9037..ed377b06f 100644 --- a/src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/Code.cxx +++ b/src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/Code.cxx @@ -41,12 +41,7 @@ main(int argc, char * argv[]) unsigned int radius = 5; std::string outputFilename = "Output.png"; - if (argc == 1) - { - image = ImageType::New(); - CreateImage(image); - } - else if (argc < 4) + if (argc >= 4) { image = itk::ReadImage(argv[1]); @@ -55,6 +50,11 @@ main(int argc, char * argv[]) outputFilename = argv[3]; } + else + { + image = ImageType::New(); + CreateImage(image); + } std::cout << "Radius: " << radius << std::endl; using StructuringElementType = itk::BinaryBallStructuringElement; @@ -98,7 +98,7 @@ main(int argc, char * argv[]) void CreateImage(ImageType * const image) { - // Create an image with 2 connected components + // Create an image with a gray square itk::Index<2> corner = { { 0, 0 } }; itk::Size<2> size; @@ -110,7 +110,7 @@ CreateImage(ImageType * const image) itk::ImageRegion<2> region(corner, size); image->SetRegions(region); - image->Allocate(); + image->Allocate(true); // Make a square for (unsigned int r = 40; r < 100; r++) diff --git a/src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/Code.cxx b/src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/Code.cxx index 544893a02..0d9ddbadb 100644 --- a/src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/Code.cxx +++ b/src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/Code.cxx @@ -41,12 +41,7 @@ main(int argc, char * argv[]) unsigned int radius = 5; std::string outputFilename = "Output.png"; - if (argc == 1) - { - image = ImageType::New(); - CreateImage(image); - } - else if (argc < 4) + if (argc >= 4) { image = itk::ReadImage(argv[1]); @@ -55,6 +50,11 @@ main(int argc, char * argv[]) outputFilename = argv[3]; } + else + { + image = ImageType::New(); + CreateImage(image); + } std::cout << "Radius: " << radius << std::endl; using StructuringElementType = itk::BinaryBallStructuringElement; @@ -111,7 +111,7 @@ CreateImage(ImageType * const image) itk::ImageRegion<2> region(corner, size); image->SetRegions(region); - image->Allocate(); + image->Allocate(true); // Make a square for (unsigned int r = 40; r < 100; r++) diff --git a/src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/Code.cxx b/src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/Code.cxx index 7ccfb33e0..a06beaf11 100644 --- a/src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/Code.cxx +++ b/src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/Code.cxx @@ -45,12 +45,7 @@ main(int argc, char * argv[]) std::string outputFilename = "Output.png"; unsigned int iteration = 1; - if (argc == 1) - { - image = ImageType::New(); - CreateImage(image.GetPointer()); - } - else if (argc < 4) + if (argc >= 4) { image = itk::ReadImage(argv[1]); @@ -59,6 +54,11 @@ main(int argc, char * argv[]) outputFilename = argv[3]; } + else + { + image = ImageType::New(); + CreateImage(image.GetPointer()); + } std::cout << "Iterations: " << iteration << std::endl; @@ -94,7 +94,7 @@ CreateImage(TImage * const image) typename TImage::RegionType region(corner, size); image->SetRegions(region); - image->Allocate(); + image->Allocate(true); // Make a square for (int r = 40; r < 100; r++)