Skip to content

Fix off-by-one error in computing XYZ2RCS transform#25

Open
Lestropie wants to merge 1 commit into
Washington-University:masterfrom
Lestropie:fix_xyz2rcs_transform
Open

Fix off-by-one error in computing XYZ2RCS transform#25
Lestropie wants to merge 1 commit into
Washington-University:masterfrom
Lestropie:fix_xyz2rcs_transform

Conversation

@Lestropie

Copy link
Copy Markdown

Bug in field estimation that dates back to at least 275b888 (I've not bothered to test before that).

Construction of the transformation between voxelspace and realspace has an off-by-one error in its interaction with numpy.linspace(), compressing the whole field estimate toward the point [-fovmin, -fovmin, -fovmin].

I have not tested the correspondence between correction with this software and the vendor-applied correction.

Experiment: 1mm isotropic image containing unit deformation field (each voxel contains its own realspace position); apply correction; convert deformation field to displacement field. Repeat for different lattice densities. Ideally an increased lattice resolution should yield a higher resolution estimation of the field, not result in the field moving in space.

Before fix:

before_small

After fix:

after_small

@coalsont

Copy link
Copy Markdown
Member

This looks like a good catch, though the logistics of existing data will raise some difficult questions. The maximum error should be 1 voxel in each dimension, so for isotropic, 1.732 voxels in the worst corner (where there isn't any tissue anyway). Maybe 1.5 voxels worst case in tissue?

If this is only in the coordinates that are used for evaluating spherical harmonics (and not for, say, deformation convention conversion), then this error would get multiplied by the (very small) gradient of the nonlinearity error, resulting in much less than a voxel of difference in displacement. What is the actual magnitude of the effect on the warpfields?

@Lestropie

Lestropie commented Jul 16, 2026

Copy link
Copy Markdown
Author

I don't think there's a clean upper bound on the maximum error in displacement per voxel. The maximum sampling offset is the lattice spacing (10mm default); the maximal displacement error depends on how much the field can change along that distance based on the gradient coefficients.

The following is for default estimation: lattice [-300, 300]mm with 60 points. Unnamed vendor & scanner. 1mm voxel grids centred around isocentre of different sizes. Norms of differences in deformation fields pre & post correction.

│ Full FoV width │ mean |Δ| (mm) │ max |Δ| (mm) │
| -------------- | ------------- | ------------ |  
│          96 mm │      0.023974 │     0.104641 │
│         128 mm │      0.042724 │     0.229327 │
│         160 mm │      0.069557 │     0.532708 │
│         192 mm │      0.110071 │     1.134180 │
│         224 mm │      0.174065 │     2.235542 │
│         256 mm │      0.275325 │     4.133250 │

Numbers would likely be worse for HCP data due to tolerance of greater nonlinearities during hardware design and not centering the brain at scanner isocentre.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants