NIfTI-1 voxel access and world-coordinate-preserving transformations in MoonBit
| 能力 | 0.1.0 边界 |
|---|---|
| 读取 | NIfTI-1 n+1 单文件、3D/4D、大小端 |
| 数据类型 | uint8 / int8 / uint16 / int16 / uint32 / int32 / float32 / float64 |
| 访问 | x 最快存储序,原始值与缩放值分离,时间帧选择,数据轴切片 |
| 几何 | 独立 qform/sform、qfac、仿射组合/求逆、显式空间选择 |
| 统计 | 有限值最小/最大/均值;NaN、+Inf、-Inf 独立计数 |
| 网格比较 | 尺寸、坐标系代码、已知长度单位换算、空间位置误差 |
| 变换 | 整数 ROI、全部 48 种轴排列与翻转;不插值、不重采样 |
| 写出 | 原始样本字节和缩放保留;两套坐标独立更新;元数据损失报告 |
| CLI | inspect / dump / slice / world / grid / crop / reorient,受限 gzip,禁止覆盖已有输出 |
git clone https://github.com/wangjiale6036-dotcom/moonnifti.git
cd moonnifti
moon update
moon build --target js --release
node _build/js/release/build/cmd/moonnifti/moonnifti.js --helppython -m pip install numpy==2.3.5 nibabel==5.3.2
python scripts/scenarios.py work/demonode CLI inspect input.nii.gz
node CLI slice input.nii.gz 2 10 0
node CLI world input.nii.gz 10 20 30 qform
node CLI grid image.nii.gz labels.nii.gz 0.001
node CLI crop input.nii.gz roi.nii.gz 10 20 5 32 32 16
node CLI reorient roi.nii.gz arranged.nii 2 0 1 1 0 0import { "wangjiale6036-dotcom/moonnifti" @nifti }fn process(bytes : Bytes) -> Bytes raise @nifti.NiftiError {
let image = @nifti.read(bytes)
let value = image.voxel(1, 2, 3, t=0)
let xyz = image.world(1, 2, 3, space=QForm)
ignore(value)
ignore(xyz)
let roi = image.crop([0, 0, 0], [2, 3, 4])
// Inspect roi.warnings before downstream use.
roi.image.to_bytes()
}moon check --target js --deny-warn
moon fmt --check
moon info
node scripts/check-api.mjs
moon test --target js --deny-warn
moon test --target wasm-gc --deny-warn
moon test --target native --deny-warn
moon build --target js --release --deny-warn
node tests/cli.mjs
python scripts/oracle.py --report work/oracle-report.json
python scripts/scenarios.py work/scenarios
moon packagepub struct Affine {
// private fields
}fn Affine::transform(self : Affine, x : Double, y : Double, z : Double) -> Array[Double] raise NiftiErrorpub(all) struct GridComparison {
compatible : Bool
reason : String
maximum_corner_error_mm : Double?
}pub struct Image {
// private fields
}fn Image::compare_grid(self : Image, other : Image, tolerance_mm? : Double, space? : Space) -> GridComparison raise NiftiErrorfn Image::crop(self : Image, start : Array[Int], size : Array[Int], drop_extensions? : Bool) -> TransformResult raise NiftiErrorfn Image::reorient(self : Image, axes : Array[Int], flips : Array[Bool], drop_extensions? : Bool) -> TransformResult raise NiftiErrorfn Image::slice(self : Image, axis : Int, index : Int, t? : Int, scaled? : Bool) -> Slice raise NiftiErrorfn Image::voxel(self : Image, x : Int, y : Int, z : Int, t? : Int, scaled? : Bool) -> Double raise NiftiErrorpub(all) struct Statistics {
finite_count : Int
nan_count : Int
positive_infinity_count : Int
negative_infinity_count : Int
minimum : Double?
maximum : Double?
mean : Double?
}Install
Download zipNIfTI-1 voxel access and world-coordinate-preserving transformations in MoonBit