Skip to content

Conversation

@N-Dekker
Copy link
Contributor

@github-actions github-actions bot added type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Segmentation Issues affecting the Segmentation module labels Nov 11, 2025
Copy link
Member

@dzenanz dzenanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good on a glance.

@N-Dekker
Copy link
Contributor Author

@N-Dekker N-Dekker force-pushed the Replace-vnl_sample-in-Segmentation-tests branch from 18ae855 to 3324070 Compare November 12, 2025 14:17
@N-Dekker N-Dekker changed the title Replace "vnl_sample.h" with <random> in Segmentation tests WIP: Replace "vnl_sample.h" with <random> in ConnectedComponent tests Nov 12, 2025
@N-Dekker
Copy link
Contributor Author

There appeared test failures at https://open.cdash.org/viewTest.php?onlyfailed&buildid=10817138 on the following four tests:

  1. itkConnectedComponentImageFilterTest
  2. itkConnectedComponentImageFilterTest2
  3. itkConnectedComponentImageFilterTest3
  4. itkConnectedComponentImageFilterTestRGB

I'm sorry, I don't really know how to fix them, but I guess we would have to change the ground truth images (somewhere in ${ITK_DATA_ROOT}, in order to make this work. For example, for itkConnectedComponentImageFilterTestRGB:

itk_add_test(
NAME itkConnectedComponentImageFilterTestRGB
COMMAND
ITKConnectedComponentsTestDriver
--compare
DATA{${ITK_DATA_ROOT}/Baseline/BasicFilters/ConnectedComponentImageFilterTest.png,:}
${ITK_TEST_OUTPUT_DIR}/ConnectedComponentImageFilterTestRGB.png
itkConnectedComponentImageFilterTestRGB
DATA{${ITK_DATA_ROOT}/Input/cthead1.png}
${ITK_TEST_OUTPUT_DIR}/ConnectedComponentImageFilterTestRGB.png
130
145

Does anyone have suggestion?

using RGBComponentType = RGBPixelType::ComponentType;
constexpr auto maxRGBComponentValue = std::numeric_limits<RGBComponentType>::max();

std::mt19937 randomNumberEngine{};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@N-Dekker does {} initialize the seed to a constant value?

I think

constexpr auto random_seed = 1031571;
std::mt19937 randomNumberEngine{random_seed};

would make this easier to interpret.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default constructor of std::mt19937 always uses the same seed: default_seed = 5489. That's different from 1031571, obviously. So we'll see if using 1031571 will make the CI happy...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's great to know, but not obvious. I would have guessed the default was to use an unknown changing seed unless explicitly specified. I do think that setting the seed explicitly (with what ever value you want, even 5489) would be more meaningful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the C++ standard specifies that the default-constructor of std::mt19937 always uses the same seed, default_seed, I think we should be allowed to just trust the C++ standard.

We could make it explicit:

std::mt19937 randomNumberEngine(std::mt19937::default_seed);

And then add to our unit tests:

static_assert(std::mt19937::default_seed == 5489, "Check on any platform!");

But that all seems overdone to me. If we want to have non-deterministic random numbers, we should use std::random_device.

@N-Dekker N-Dekker force-pushed the Replace-vnl_sample-in-Segmentation-tests branch from 3324070 to 3dec7c3 Compare November 12, 2025 15:49
Follow-up to pull request InsightSoftwareConsortium#5611
commit f7daf24
"ENH: Replace "vnl/vnl_sample.h" with `<random>`, in Core tests"
@N-Dekker N-Dekker force-pushed the Replace-vnl_sample-in-Segmentation-tests branch from 3dec7c3 to d993427 Compare November 12, 2025 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Segmentation Issues affecting the Segmentation module type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants