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: Add a 3D regression test for FillholeImageFilter #4330

Merged
merged 1 commit into from
Nov 30, 2023
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
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()