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

reg_aladin interpolation #59

Open
rijobro opened this issue Nov 20, 2019 · 3 comments
Open

reg_aladin interpolation #59

rijobro opened this issue Nov 20, 2019 · 3 comments
Assignees

Comments

@rijobro
Copy link
Collaborator

rijobro commented Nov 20, 2019

I've noticed that when I set interpolation order of reg_aladin to nearest neighbour or trilinear, the output image which was initially non-negative, may contain negatives. To me, this implied that the interpolation was likely cubic.

I've created a small bash test to illustrate my point. It does the following:

  1. Downloads an example nifti from Slicer's BRAINSTools module
  2. Applies a translation of 10.5mm, to create the moved image
  3. The moved image is registered with reg_aladin with NN interpolation
  4. The transformation matrix from the registration is used with reg_resample for different types of interpolation.

Here is the output:

source min: 0.0
moved min: 0.0
registered NN min: -21.0
resampled NN min: 0.0
resampled LIN min: 0.0
resampled CUB min: -21.0

Have I misunderstood something or is this a bug?

The script is as follows:

source="source.nii.gz"
moved="moved.nii.gz"
registered="registered.nii.gz"
resampled_NN="resampled_NN.nii.gz"
resampled_LIN="resampled_LIN.nii.gz"
resampled_CUB="resampled_CUB.nii.gz"

url="https://github.com/pieper/Slicer3-shallow/raw/master/Applications/CLI/BRAINSTools/BRAINSCommonLib/TestData/test.nii.gz"
wget -nc -O source.nii.gz "$url"

function get_min {
	python3 -c "import sys, nibabel; exit(nibabel.load(sys.argv[1]).get_fdata().min())" $1 2>&1
}

# get min of source
min_source=$(get_min ${source})

# Create transformation matrix
echo "1 0 0 10.5
0 1 0 0
0 0 1 0
0 0 0 1" > tm.txt

# Move
reg_resample -ref ${source} -flo ${source} -res ${moved} -inter 0 -trans tm.txt
min_moved=$(get_min ${moved})

# Register
reg_aladin -ref ${source} -flo ${moved} -rigOnly -interp 0 -res ${registered} -aff tm_aladin.txt
min_registered_NN=$(get_min ${registered})

# Resample using registered tm
reg_resample -ref ${source} -flo ${moved} -res ${resampled_NN} -inter 0 -trans tm_aladin.txt
min_resampled_NN=$(get_min ${resampled_NN})
reg_resample -ref ${source} -flo ${moved} -res ${resampled_LIN} -inter 1 -trans tm_aladin.txt
min_resampled_LIN=$(get_min ${resampled_LIN})
reg_resample -ref ${source} -flo ${moved} -res ${resampled_CUB} -inter 3 -trans tm_aladin.txt
min_resampled_CUB=$(get_min ${resampled_CUB})

echo "source min: ${min_source}"
echo "moved min: ${min_moved}"
echo "registered NN min: ${min_registered_NN}"
echo "resampled NN min: ${min_resampled_NN}"
echo "resampled LIN min: ${min_resampled_LIN}"
echo "resampled CUB min: ${min_resampled_CUB}"
@fepegar
Copy link

fepegar commented Nov 20, 2019

+1. I also call reg_resample after registering because of this bug.

@rijobro
Copy link
Collaborator Author

rijobro commented Dec 18, 2019

any word on this one? I'm ok to try and figure it out with a bit of help...

@mmodat mmodat self-assigned this Jul 14, 2022
@XwK-P
Copy link

XwK-P commented Nov 9, 2023

For anyone who has the same question, I believe this is actually the intended behavior as mentioned in the help "Interpolation order to use internally to warp the floating image". Interp will only be used to do internal interpolation not to get the final warped image. You can make changes in https://github.com/KCL-BMEIS/niftyreg/blob/master/reg-lib/_reg_aladin.cpp#L663 to do whatever you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

4 participants