Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: BinaryMathematicalMorphology baseline testing #219

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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];
}
else
{
image = ImageType::New();
CreateImage(image);
}

std::cout << "Radius: " << radius << std::endl;
using StructuringElementType = itk::BinaryBallStructuringElement<ImageType::PixelType, ImageType::ImageDimension>;
StructuringElementType structuringElement;
Expand Down Expand Up @@ -87,14 +89,16 @@ main(int argc, char * argv[])
viewer.AddImage(diff->GetOutput(), true, desc3.str());
viewer.Visualize();
#endif

itk::WriteImage(closingFilter->GetOutput(), outputFilename);
return EXIT_SUCCESS;
}


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;
Expand All @@ -106,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++)
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
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];
}
else
{
image = ImageType::New();
CreateImage(image);
}

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 All @@ -106,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++)
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 >= 4)
{
image = ImageType::New();
CreateImage(image.GetPointer());
image = itk::ReadImage<ImageType>(argv[1]);

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

outputFilename = argv[3];
}
else
{
image = itk::ReadImage<ImageType>(argv[1]);
std::stringstream ssIteration(argv[2]);
image = ImageType::New();
CreateImage(image.GetPointer());
}

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 All @@ -79,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++)
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
4 changes: 2 additions & 2 deletions src/Filtering/BinaryMathematicalMorphology/ThinImage/Code.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImageType, ImageType>;
Expand All @@ -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
4 changes: 2 additions & 2 deletions src/Filtering/BinaryMathematicalMorphology/ThinImage/Code.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@
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)

# Rescale the image so that it can be seen (the output is 0 and 1, we want 0 and 255)
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")
Original file line number Diff line number Diff line change
Expand Up @@ -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
----
Expand Down