Skip to content

Commit

Permalink
ENH: Add a 3D regression test for FillholeImageFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
dzenanz committed Nov 30, 2023
1 parent 65075f0 commit 3d54107
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bafkreiedqykigqcan7723ddeqti6k7ax64nm6vhb6y274kbkkoqvwk7tsu
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bafkreibhouw5b6l7p5pjfhvqpjkykha4gjftpllyzzqkh6ocq6s37udw64
26 changes: 26 additions & 0 deletions Modules/Filtering/LabelMap/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,32 @@ itk_add_test(
${ITK_TEST_OUTPUT_DIR}/itkBinaryFillholeImageFilterTest1.png
1
255)
itk_add_test(
NAME
itkBinaryFillholeImageFilterTest3D_0
COMMAND
ITKLabelMapTestDriver
--compare
DATA{Baseline/fillhole_test_3D_0.nrrd}
${ITK_TEST_OUTPUT_DIR}/itkBinaryFillholeImageFilterTest3D_0.nrrd
itkBinaryFillholeImageFilterTest1
DATA{Input/fillhole_test_3D.nrrd}
${ITK_TEST_OUTPUT_DIR}/itkBinaryFillholeImageFilterTest3D_0.nrrd
0
1)
itk_add_test(
NAME
itkBinaryFillholeImageFilterTest3D_1
COMMAND
ITKLabelMapTestDriver
--compare
DATA{Baseline/fillhole_test_3D_1.nrrd}
${ITK_TEST_OUTPUT_DIR}/itkBinaryFillholeImageFilterTest3D_1.nrrd
itkBinaryFillholeImageFilterTest1
DATA{Input/fillhole_test_3D.nrrd}
${ITK_TEST_OUTPUT_DIR}/itkBinaryFillholeImageFilterTest3D_1.nrrd
1
1)
itk_add_test(
NAME
itkBinaryGrindPeakImageFilterTest1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bafkreieiivjbu4msrzxudc4radedqkrt6k6d2uiptvnd4q72jxhnwonrdu
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,12 @@
#include "itkBinaryFillholeImageFilter.h"
#include "itkTestingMacros.h"


namespace // Anonymous namespace avoids name collisions
{
template <unsigned Dimension>
int
itkBinaryFillholeImageFilterTest1(int argc, char * argv[])
DoIt(char * argv[])
{

if (argc != 5)
{
std::cerr << "Missing Parameters." << std::endl;
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv)
<< " inputFileName outputFileName fullyConnected foregroundValue" << std::endl;
return EXIT_FAILURE;
}

constexpr unsigned int Dimension = 2;

using PixelType = unsigned char;

using ImageType = itk::Image<PixelType, Dimension>;
Expand Down Expand Up @@ -76,3 +67,34 @@ itkBinaryFillholeImageFilterTest1(int argc, char * argv[])
std::cout << "Test finished." << std::endl;
return EXIT_SUCCESS;
}
} // namespace

int
itkBinaryFillholeImageFilterTest1(int argc, char * argv[])
{
if (argc != 5)
{
std::cerr << "Missing Parameters." << std::endl;
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv)
<< " inputFileName outputFileName fullyConnected foregroundValue" << std::endl;
return EXIT_FAILURE;
}

using ImageType = itk::Image<short>;
using ReaderType = itk::ImageFileReader<ImageType>;
auto reader = ReaderType::New();
reader->SetFileName(argv[1]);
ITK_TRY_EXPECT_NO_EXCEPTION(reader->UpdateOutputInformation());

unsigned dim = reader->GetImageIO()->GetNumberOfDimensions();
switch (dim)
{
case 2:
return DoIt<2>(argv);
case 3:
return DoIt<3>(argv);
default:
itkGenericExceptionMacro("Only image dimensions 2 and 3 are supported, but " << argv[1]
<< " has dimension: " << dim);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# ==========================================================================
#
# Copyright NumFOCUS
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ==========================================================================*/

import itk
from sys import argv, stderr, exit

itk.auto_progress(2)

if len(argv) < 5:
print(
(
"Missing Parameters \n Usage: BinaryFillholeImageFilterTest.py inputImageFile "
"outputImageFile fullyConnected foregroundValue"
),
file=stderr,
)
exit(1)


mask = itk.imread(argv[1])
fully_connected = (int(argv[3]) > 0)
foreground_value = int(argv[4])

mask_filled = itk.binary_fillhole_image_filter(
mask, fully_connected=fully_connected, foreground_value=foreground_value)
itk.imwrite(mask_filled, argv[2])
56 changes: 56 additions & 0 deletions Modules/Filtering/LabelMap/wrapping/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
set(test_input_dir ${itk-module_SOURCE_DIR}/test/Input)
set(test_baseline_dir ${itk-module_SOURCE_DIR}/test/Baseline)

# let's make sure 3D uchar images are wrapped
list(
FIND
ITK_WRAP_IMAGE_DIMS
3
wrap_3_index)
if(ITK_WRAP_PYTHON
AND ITK_WRAP_unsigned_char
AND wrap_3_index GREATER -1)

itk_python_add_test(
NAME
BinaryFillholeImageFilterTestPython2D
TEST_DRIVER_ARGS
--compare
DATA{${test_baseline_dir}/itkBinaryFillholeImageFilterTest1.png}
${ITK_TEST_OUTPUT_DIR}/itkBinaryFillholeImageFilterTest2D.png
COMMAND
${CMAKE_CURRENT_SOURCE_DIR}/BinaryFillholeImageFilterTest.py
DATA{${ITK_DATA_ROOT}/Input/Spots.png}
${ITK_TEST_OUTPUT_DIR}/itkBinaryFillholeImageFilterTest2D.png
1
255)

itk_python_add_test(
NAME
BinaryFillholeImageFilterTestPython0
TEST_DRIVER_ARGS
--compare
DATA{${test_baseline_dir}/fillhole_test_3D_0.nrrd}
${ITK_TEST_OUTPUT_DIR}/itkBinaryFillholeImageFilterTest3D_0.nrrd
COMMAND
${CMAKE_CURRENT_SOURCE_DIR}/BinaryFillholeImageFilterTest.py
DATA{${test_input_dir}/fillhole_test_3D.nrrd}
${ITK_TEST_OUTPUT_DIR}/itkBinaryFillholeImageFilterTest3D_0.nrrd
0
1)

itk_python_add_test(
NAME
BinaryFillholeImageFilterTestPython1
TEST_DRIVER_ARGS
--compare
DATA{${test_baseline_dir}/fillhole_test_3D_1.nrrd}
${ITK_TEST_OUTPUT_DIR}/itkBinaryFillholeImageFilterTest3D_1.nrrd
COMMAND
${CMAKE_CURRENT_SOURCE_DIR}/BinaryFillholeImageFilterTest.py
DATA{${test_input_dir}/fillhole_test_3D.nrrd}
${ITK_TEST_OUTPUT_DIR}/itkBinaryFillholeImageFilterTest3D_1.nrrd
1
1)

endif()

0 comments on commit 3d54107

Please sign in to comment.