Skip to content

Commit

Permalink
ENH: BinaryMathematicalMorphology baseline testing
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mseng10 authored and jhlegarreta committed Sep 11, 2021
1 parent e6d7775 commit 8e28b03
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 25 deletions.
8 changes: 4 additions & 4 deletions src/Filtering/BinaryMathematicalMorphology/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "itkImage.h"
#include "itkBinaryMorphologicalClosingImageFilter.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkBinaryBallStructuringElement.h"
#include "itkSubtractImageFilter.h"

Expand All @@ -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<ImageType>(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<ImageType::PixelType, ImageType::ImageDimension>;
StructuringElementType structuringElement;
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Closing a binary image.
Results
-------

.. figure:: ClosingBinaryImage.png
.. figure:: ClosingBinaryImageQuickView.png
:scale: 70%

Output In VTK Window
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a4ed65f70809fca3e1b6195fb7238e6d9ca46bc8cd1c34e1a1f3c49142633fbc5e9dcd40713c138fba71f913e6d1664c32165d3f5b89fcf046811faafca783a9
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "itkImage.h"
#include "itkBinaryMorphologicalOpeningImageFilter.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkBinaryBallStructuringElement.h"
#include "itkSubtractImageFilter.h"

Expand All @@ -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<ImageType>(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<ImageType::PixelType, ImageType::ImageDimension>;
StructuringElementType structuringElement;
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Opening a binary image.

Results
-------
.. figure:: OpeningBinaryImage.png
.. figure:: OpeningBinaryImageQuickView.png
:scale: 70%

Output In VTK Window
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a4ed65f70809fca3e1b6195fb7238e6d9ca46bc8cd1c34e1a1f3c49142633fbc5e9dcd40713c138fba71f913e6d1664c32165d3f5b89fcf046811faafca783a9
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned char, 2>;
}

template <typename TImage>
void
CreateImage(TImage * const image);
Expand All @@ -36,20 +42,26 @@ main(int argc, char * argv[])

using ImageType = itk::Image<unsigned char, 2>;
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<ImageType>(argv[1]);

std::stringstream ssIteration(argv[2]);
ssIteration >> iteration;

outputFilename = argv[3];
}

std::cout << "Iterations: " << iteration << std::endl;

using BinaryPruningImageFilterType = itk::BinaryPruningImageFilter<ImageType, ImageType>;
BinaryPruningImageFilterType::Pointer pruneFilter = BinaryPruningImageFilterType::New();
pruneFilter->SetInput(image);
Expand All @@ -62,6 +74,9 @@ main(int argc, char * argv[])
viewer.AddImage(pruneFilter->GetOutput());
viewer.Visualize();
#endif

itk::WriteImage(pruneFilter->GetOutput(), outputFilename);

return EXIT_SUCCESS;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Prune a binary image.

Results
-------
.. figure:: PruneBinaryImage.png
.. figure:: PruneBinaryImageQuickView.png
:scale: 70%

Output In VTK Window
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
93ed6019fefb93301ed2b358283bfabf2b0b0d7bfa1caaeb096eaf4bcfb9edd169a5406e2e7a26ff9bc6167051d04f84e79853989521cb03d6a59c1f6c889c59
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
----
Expand Down

0 comments on commit 8e28b03

Please sign in to comment.