Resampling
Closed this issue · 3 comments
I realized that the downsample_vectorfield
filter is really stupid. The caller can provide a scale but the downsampling actually only uses 8 voxels to compute the new vector in all cases.
float3 v = field(px, py, pz);
v = v + field.at(px+1, py, pz, stk::Border_Replicate);
v = v + field.at(px, py+1, pz, stk::Border_Replicate);
v = v + field.at(px, py, pz+1, stk::Border_Replicate);
v = v + field.at(px+1, py+1, pz, stk::Border_Replicate);
v = v + field.at(px+1, py, pz+1, stk::Border_Replicate);
v = v + field.at(px, py+1, pz+1, stk::Border_Replicate);
v = v + field.at(px+1, py+1, pz+1, stk::Border_Replicate);
This will of course break as soon as you use a scale != 0.5.
The question is, should we keep it like this and rename it to something like "downsample_by_2" or should we make a generic function that works for all scales. Handling the resampling of vector fields feels really messy at the moment due to all special cases.
Fixed in fac8d8c
I noticed that the old version seemed to have some bias compared to the new version.
This is a slice of the original displacement field (as RGB):
This is the version downsampled by the old method (mentioned in the OP):
This is the result of the new method (gaussian + shrinking):
The last one seems like the correct one, but will need some testing to confirm. This change will probably change the outcome of the registrations for cases were we use an initial displacement.
I will leave this issue open and do some proper tests before merging the GPU branch.
Great job, thanks!
I am actually using an initial displacement in some experiments right now, but with no multi-resolution (only one level) so, if I am not missing anything, this bug should not affect them...
Exactly, so the resampling is only performed when going up and down in the pyramid so you should be in the clear. I used this in my brain evaluations so I will probably run them again and see if the new resampling have any effect on the results.