`BSplineFieldTransform.to_field()` ignores the orientation of the reference grid

Aperta
#300 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@effigies ci sta già lavorando.

Dal 22/11/2026.

  • #304 di @effigies — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python

Direzione di ricerca

The bug is in grid_bspline_weights, which places target voxels in the control-point grid from voxel sizes and origin alone, ignoring direction cosines. Start with BSplineFieldTransform.to_field() and trace how it calls grid_bspline_weights, then run the two reproduction snippets from the issue. Done means both assertions pass for the flipped (diag -3, 3, 3) and the 30-degree rotated target grids, with the existing tests still green.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

grid_bspline_weights places the target voxels in the control-point grid using only the voxel sizes and the target origin. It ignores the direction cosines of both grids. When the reference is flipped, permuted or rotated relative to the coefficients, to_field() evaluates the spline at the wrong locations.

Reproduction

import nibabel as nb
import numpy as np
from nitransforms.base import ImageGrid
from nitransforms.nonlinear import BSplineFieldTransform


def centered_grid(linear, shape):
    """Affine for a grid of given shape, centered at the origin, with given linear part"""
    affine = nb.affines.from_matvec(linear, -linear @ (np.array(shape) - 1) / 2)
    return nb.Nifti1Image(np.zeros(shape), affine)


# A 10 mm lattice of 10 x 10 x 10 knots, centered at the origin
knots = ImageGrid(centered_grid(np.eye(3) * 10, (10, 10, 10)))
# Set coefficient to RAS position, which is linear and so exactly representable
coeffs = knots.ndcoords.reshape(10, 10, 10, 3).astype("float32")
xfm = BSplineFieldTransform(nb.Nifti1Image(coeffs, knots.affine))

# 30mm FoV is well within spline support, no extrapolation needed
las_target = centered_grid(np.diag([-3.0, 3, 3]), (11, 11, 11))
field = xfm.to_field(reference=las_target)

assert np.allclose(field._deltas.reshape(-1, 3), ImageGrid(las_target).ndcoords, atol=1e-3)

Same failure with a rotated grid:

COS, SIN = np.cos(np.pi / 6), np.sin(np.pi / 6)
oblique_target = centered_grid(np.array([[COS, -SIN, 0], [SIN, COS, 0], [0, 0, 1]]) * 3, (11, 11, 11))
field = xfm.to_field(reference=oblique_target)

assert np.allclose(field._deltas.reshape(-1, 3), ImageGrid(oblique_target).ndcoords, atol=1e-3)
Lingua principale
Python
Stelle
36
Fork
18
Merge medio
1h 24m
PR unite (30g)
1

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nipy/nitransforms

Tutte le issue di nipy/nitransforms

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.