From 86db4340cb3fdee93f6538abfa0eb7bda30c4ee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Onur=20=C3=9Clgen?= Date: Wed, 15 Nov 2023 15:27:09 +0000 Subject: [PATCH] Add multi-timepoint support for MeasureTest #92 --- niftyreg_build_version.txt | 2 +- reg-test/reg_test_regr_measure.cpp | 41 ++++++++++++++++-------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/niftyreg_build_version.txt b/niftyreg_build_version.txt index e5db9a27..8c0a1869 100644 --- a/niftyreg_build_version.txt +++ b/niftyreg_build_version.txt @@ -1 +1 @@ -362 +363 diff --git a/reg-test/reg_test_regr_measure.cpp b/reg-test/reg_test_regr_measure.cpp index 81c150e8..2c26a8d1 100644 --- a/reg-test/reg_test_regr_measure.cpp +++ b/reg-test/reg_test_regr_measure.cpp @@ -28,14 +28,15 @@ class MeasureTest { // Create 2D reference, floating, control point grid and local weight similarity images constexpr NiftiImage::dim_t size = 16; - vector dim{ size, size }; + constexpr NiftiImage::dim_t timePoints = 1; + vector dim{ size, size, 1, timePoints }; NiftiImage reference2d(dim, NIFTI_TYPE_FLOAT32); NiftiImage floating2d(dim, NIFTI_TYPE_FLOAT32); NiftiImage controlPointGrid2d(CreateControlPointGrid(reference2d)); NiftiImage localWeightSim2d(dim, NIFTI_TYPE_FLOAT32); // Create 3D reference, floating, control point grid and local weight similarity images - dim.push_back(size); + dim[2] = size; NiftiImage reference3d(dim, NIFTI_TYPE_FLOAT32); NiftiImage floating3d(dim, NIFTI_TYPE_FLOAT32); NiftiImage controlPointGrid3d(CreateControlPointGrid(reference3d)); @@ -63,7 +64,7 @@ class MeasureTest { // Create the data container for the regression test const std::string measureNames[]{ "NMI"s, "SSD"s, "DTI"s, "LNCC"s, "KLD"s, "MIND"s, "MINDSSC"s }; - const MeasureType testMeasures[]{ MeasureType::Nmi, MeasureType::Ssd }; + constexpr MeasureType testMeasures[]{ MeasureType::Nmi, MeasureType::Ssd }; vector testData; for (auto&& measure : testMeasures) { for (int sym = 0; sym < 2; ++sym) { @@ -137,9 +138,9 @@ class MeasureTest { unique_ptr measureCuda{ measureCreatorCuda->Create(measureType) }; // Initialise the measures - for (int i = 0; i < referenceCpu->nt; ++i) { - measureCpu->SetTimePointWeight(i, 1.0); - measureCuda->SetTimePointWeight(i, 1.0); + for (int t = 0; t < referenceCpu->nt; t++) { + measureCpu->SetTimePointWeight(t, 1.0); + measureCuda->SetTimePointWeight(t, 1.0); } measureCreatorCpu->Initialise(*measureCpu, *contentCpu, contentCpuBw.get()); measureCreatorCuda->Initialise(*measureCuda, *contentCuda, contentCudaBw.get()); @@ -162,24 +163,26 @@ class MeasureTest { } const double simMeasureCuda = measureCuda->GetSimilarityMeasureValue(); - // Compute the similarity measure gradient for CPU - constexpr int timepoint = 0; + // Compute the similarity measure gradients contentCpu->ZeroVoxelBasedMeasureGradient(); - computeCpu->GetImageGradient(1, std::numeric_limits::quiet_NaN(), timepoint); - if (isSymmetric) { - contentCpuBw->ZeroVoxelBasedMeasureGradient(); - computeCpuBw->GetImageGradient(1, std::numeric_limits::quiet_NaN(), timepoint); - } - measureCpu->GetVoxelBasedSimilarityMeasureGradient(timepoint); - - // Compute the similarity measure gradient for CUDA contentCuda->ZeroVoxelBasedMeasureGradient(); - computeCuda->GetImageGradient(1, std::numeric_limits::quiet_NaN(), timepoint); if (isSymmetric) { + contentCpuBw->ZeroVoxelBasedMeasureGradient(); contentCudaBw->ZeroVoxelBasedMeasureGradient(); - computeCudaBw->GetImageGradient(1, std::numeric_limits::quiet_NaN(), timepoint); } - measureCuda->GetVoxelBasedSimilarityMeasureGradient(timepoint); + for (int t = 0; t < referenceCpu->nt; t++) { + // Compute the similarity measure gradient for CPU + computeCpu->GetImageGradient(1, std::numeric_limits::quiet_NaN(), t); + if (isSymmetric) + computeCpuBw->GetImageGradient(1, std::numeric_limits::quiet_NaN(), t); + measureCpu->GetVoxelBasedSimilarityMeasureGradient(t); + + // Compute the similarity measure gradient for CUDA + computeCuda->GetImageGradient(1, std::numeric_limits::quiet_NaN(), t); + if (isSymmetric) + computeCudaBw->GetImageGradient(1, std::numeric_limits::quiet_NaN(), t); + measureCuda->GetVoxelBasedSimilarityMeasureGradient(t); + } // Get the voxel-based similarity measure gradients NiftiImage voxelBasedGradCpu(contentCpu->GetVoxelBasedMeasureGradient(), NiftiImage::Copy::Image);