Skip to content
Beta.nii@modelscript/nifti 10 diagnostic rules
Parser WASM GLR
Diagnostics 10 rules
DAE Arena Lowering
Simulation Co-sim / Export
Projections NIfTI, DICOM-RT
Live ExampleBrainT1wMNI152.nii.json

NIfTI-1 Neuroimaging Volume & RAS+ Affine Registration

3D T1-weighted MRI header manifest defining isotropic 1 mm voxel geometry and qform/sform affine world coordinate matrices.

Playground
Source (13 lines)
1{
2  "sizeof_hdr": 348,
3  "magic": "n+1",
4  "datatype": "FLOAT32",
5  "dim": [3, 192, 256, 256, 1, 1, 1, 1],
6  "pixdim": [1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0],
7  "xyzt_units": ["mm", "sec"],
8  "qform_code": 1,
9  "sform_code": 4,
10  "srow_x": [-1.0, 0.0, 0.0, 96.0],
11  "srow_y": [0.0, 1.0, 0.0, -128.0],
12  "srow_z": [0.0, 0.0, 1.0, -128.0]
13}
NIfTI Voxel Grid to RAS+ World Coordinate Transform
A * [i,j,k,1]^T spatial registration «nifti-1 float32» Voxel Grid (i,j,k) «parameters» dim = 192 x 256 x 256 pixdim = 1.0 mm iso «sform_code = 4» sform Affine «model» MNI152 stereotactic det(A) = -1.0 mm^3 «neuroimaging space» RAS+ World (x,y,z) «verification» Right-Anterior-Superior FOV = 192x256x256 mm
Drag to pan · Click % to reset

NIfTI & NRRD Volumetric Medical Imaging (.nii, .nrrd, .nhdr) ​

@modelscript/nifti (languages/nifti) provides native WebAssembly parsing, 4×4 qform quaternion and sform affine Right-Anterior-Superior (RAS) coordinate transformation validation, anatomical segmentation labelmap volume calculation, Marching Tetrahedra 3D iso-surface mesh extraction, DAEBuilder lowering, and ISO 10303-21 STEP / OpenSCAD projections for NIfTI-1 / NIfTI-2 and NRRD (Nearly Raw Raster Data) medical imaging volumes.


Supported Extensions & Standards ​

ExtensionFormatDescription
.niiNIfTI-1 / NIfTI-2Neuroimaging & clinical volumetric format encoding 3D/4D voxel grids, pixdim spacings, and qform/sform RAS affines
.nrrd, .nhdrTeem / 3D Slicer NRRDNearly Raw Raster Data header/volume with space directions, space origin, and anatomical segmentation labelmaps

Key Capabilities ​

1. Voxel-to-RAS Affine Geometry & Orientation Auditing ​

  • Parses voxel dimensions (Nx,Ny,Nz,Nt), millimeter spacings (Δx,Δy,Δz), unit quaternion parameters (b,c,d) with qfac ∈{−1,+1}, and 4×4 sform homogeneous transformation matrices Tvoxel→RAS.
  • Detects singular affine matrices (det(M3×3)=0), left-right radiological/neurological handedness mismatches between qform and sform, and anisotropic slice gaps.

2. Segmentation Labelmaps & Marching Tetrahedra Iso-Surfacing ​

  • Extracts organ and tumor volumes (mm3 / cm3), bounding boxes, and centroids for segmented ROIs, and triangulates watertight 3D surface meshes (extractIsoSurfaceMesh).

3. CAD Reconstruction (STEP AP242 & OpenSCAD) ​

  • Projects extracted anatomical iso-surfaces directly into ISO 10303-21 STEP B-Rep shells (niftiToStep) and OpenSCAD polyhedron(...) CSG modules (niftiToScad) for patient-specific implant and surgical guide design.

Pre-Flight Diagnostics ​

10 rules8 error2 warning

CodeRuleSeverityMessage
M9501nifti-invalid-dimensionserrorInvalid NIfTI/NRRD volume dimensions: dim[0]='<ndim>', spatial size=(<nx>, <ny>, <nz>).
M9502nifti-non-positive-voxel-spacingerrorNon-positive voxel spacing pixdim=(<dx>, <dy>, <dz>) mm (all spatial spacings must be > 0).
M9503nifti-singular-affine-transformerror4x4 sform affine transformation matrix is singular or degenerate with det(A) = '<detA>'.
M9504nifti-invalid-quaternion-normerrorInvalid qform quaternion parameters (<b>, <c>, <d>): b^2 + c^2 + d^2 = '<normSq>' exceeds 1.0.
M9505nifti-qform-sform-handedness-mismatcherrorCoordinate handedness mismatch between active qform (qfac sign '<qfacSign>') and sform (det sign '<sformDetSign>').
M9506nifti-zero-intensity-scale-slopeerrorIntensity scaling has scl_slope='<sclSlope>' with active scaling (scl_inter='<sclInter>'), zeroing all voxel intensities.
M9507nifti-unsupported-datatypeerrorUnsupported or invalid NIfTI/NRRD voxel datatype '<datatypeName>' (code='<datatypeCode>').
M9508nifti-voxel-data-size-mismatcherrorVoxel payload count '<actualCount>' does not match expected '<expectedCount>' for dimensions <dimsDesc>.
M9509nifti-empty-segmentation-maskwarningSegmentation labelmap '<title>' contains zero foreground voxels across all anatomical labels.
M9510nifti-anisotropic-slice-gap-warningwarningSlice thickness dz='<dz>' mm exceeds in-plane resolution '<minInPlane>' mm by '<ratio>x' (> 5x threshold), risking severe 3D stair-step artifacts.

Generated from languages/nifti/src/lints/rules.ts. All languages →


CLI Usage ​

bash
# Inspect NIfTI/NRRD dimensions, voxel spacings, and RAS affine transforms
msx nifti inspect BrainAtlas.nii

# Validate qform/sform affine non-singularity and handedness consistency
msx nifti validate BrainAtlas.nii

# Extract 3D iso-surface mesh and ROI volumes from segmentation volume
msx nifti mesh BrainAtlas.nii

# Export reconstructed anatomical geometry to ISO 10303-21 STEP or OpenSCAD
msx nifti to-step BrainAtlas.nii > BrainAtlas.stp
msx nifti to-scad BrainAtlas.nii > BrainAtlas.scad

Open-Core under the GNU AGPL v3 License; Enterprise Edition (ee/) under the ModelScript Enterprise License. • Pricing • Trademark Policy