Skip to content

Commit b917bc0

Browse files
author
Marc Modat
committed
#148 fix mask size for 4D images
1 parent cd5440f commit b917bc0

3 files changed

Lines changed: 36 additions & 2 deletions

File tree

reg-lib/_reg_aladin.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ void reg_aladin<T>::InitialiseRegistration() {
9393

9494
this->Print();
9595

96+
if (this->inputReference->nt > 1 || this->inputReference->nu > 1)
97+
NR_WARN("The reference image contains more than one volume - only the first volume is used for the optimisation");
98+
if (this->inputFloating->nt > 1 || this->inputFloating->nu > 1)
99+
NR_WARN("The floating image contains more than one volume - only the first volume is used for the optimisation");
100+
96101
// CREATE THE PYRAMID IMAGES
97102
this->referencePyramid = vector<NiftiImage>(this->levelsToPerform);
98103
this->floatingPyramid = vector<NiftiImage>(this->levelsToPerform);

reg-lib/cuda/CudaAladinContent.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ CudaAladinContent::CudaAladinContent(NiftiImage& referenceIn,
2222
/* *************************************************************** */
2323
void CudaAladinContent::AllocateMask() {
2424
if (!referenceMask) return;
25+
// The host mask buffer is allocated per volume
26+
const size_t voxelNumber = reference.nVoxelsPerVolume();
2527
int *mask;
26-
Cuda::Allocate(&mask, reference->nvox);
28+
Cuda::Allocate(&mask, voxelNumber);
2729
maskCuda.reset(mask);
28-
Cuda::TransferNiftiToDevice(maskCuda.get(), referenceMask, reference->nvox);
30+
Cuda::TransferNiftiToDevice(maskCuda.get(), referenceMask, voxelNumber);
2931
}
3032
/* *************************************************************** */
3133
void CudaAladinContent::AllocateReferenceMat() {

reg-test/reg_test_blockMatching.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,35 @@ class BMTest {
111111
contentResampling3d->GetWarped(),
112112
mask3d.get()
113113
));
114+
115+
// Create 4D variants of the 3D reference and warped images: volume 0 holds the same data,
116+
// while the extra volumes are filled with values that must not influence the matching.
117+
// The mask stays allocated per volume, mirroring the backward content of a symmetric
118+
// registration with a 4D floating image
119+
vector<NiftiImage::dim_t> dim4d{ size, size, size, 3 };
120+
NiftiImage reference4d(dim4d, NIFTI_TYPE_FLOAT32);
121+
NiftiImage warped4d(dim4d, NIFTI_TYPE_FLOAT32);
122+
const size_t volumeSize = reference3d.nVoxels();
123+
const auto warped3dPtr = contentResampling3d->GetWarped().data();
124+
auto ref4dPtr = reference4d.data();
125+
auto warped4dPtr = warped4d.data();
126+
for (size_t i = 0; i < volumeSize; ++i) {
127+
ref4dPtr[i] = static_cast<float>(ref3dPtr[i]);
128+
warped4dPtr[i] = static_cast<float>(warped3dPtr[i]);
129+
}
130+
for (size_t i = volumeSize; i < reference4d.nVoxels(); ++i) {
131+
ref4dPtr[i] = 1000.f * distr(gen);
132+
warped4dPtr[i] = 1000.f * distr(gen);
133+
}
114134
contentResampling3d.release();
115135

136+
testData.emplace_back(TestData(
137+
"BlockMatching 4D",
138+
std::move(reference4d),
139+
std::move(warped4d),
140+
mask3d.get()
141+
));
142+
116143
for (auto&& data : testData) {
117144
// Get the test data
118145
auto&& [testName, reference, warped, mask] = data;

0 commit comments

Comments
 (0)