Skip to content

Inconsistent/unused affine implementations #57

@effigies

Description

@effigies

Both nifti1.ts and nifti2.ts implement getQformMat along the lines of the nifti_clib reference implementation. However, only nifti1.ts implements the three affine methods, while nifti2.ts unconditionally loads the sform. Additionally, nifti1.ts implements the qform again, although inconsistently with the reference implementation, and it has no method to access the sform if the sform is not the determined method.

I would suggest:

  1. Load the sform into header.sform.

  2. Add a method, called at the end of readHeader (in both implementations) to set header.affine according to the three methods:

      #setAffine() {
        if (this.sform_code != 0) {
          this.affine = this.sform
        } else if (this.qform_code != 0) {
          this.affine = this.getQformMat()
        } else {
          // Default LAS matrix
        }
      }

The current implementation prefers the qform to the sform if sform_code < qform_code, but I haven't seen that logic elsewhere. The standard does not say to prefer one to the other, and the reference implementation's image structure contains both, leaving calling code to either use both or choose one to prefer, invalidating the other on changes.

The above logic matches the nibabel and FreeSurfer's load_nifti_hdr.m. The ANTs logic is convoluted, and I won't reproduce it here. I haven't looked into other implementations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions