A comprehensive .NET Standard library for reading, writing, and manipulating NIfTI (Neuroimaging Informatics Technology Initiative) medical imaging files with full NIfTI-1 specification compliance and validation.
Note: If you're looking for the TensorFlow CNN platform, try NiftyNet instead.
NIfTI format is the standard for storing neuroimaging data including MRI, fMRI, DTI, and other medical imaging modalities. This library enables .NET applications to seamlessly integrate with medical imaging workflows.
graph TB
A[Medical Scanner] --> B[Raw DICOM Data]
B --> C[Image Processing]
C --> D[NIfTI Format]
D --> E[Nifti.NET Library]
E --> F[.NET Applications]
F --> G[Research Analysis]
F --> H[Clinical Tools]
F --> I[Visualization]
style A fill:#ffffff,stroke:#000000,stroke-width:2px,color:#000000
style B fill:#ffffff,stroke:#000000,stroke-width:2px,color:#000000
style C fill:#ffffff,stroke:#000000,stroke-width:2px,color:#000000
style D fill:#e3f2fd,stroke:#000000,stroke-width:2px,color:#000000
style E fill:#bbdefb,stroke:#000000,stroke-width:3px,color:#000000
style F fill:#ffffff,stroke:#000000,stroke-width:2px,color:#000000
style G fill:#ffffff,stroke:#000000,stroke-width:2px,color:#000000
style H fill:#ffffff,stroke:#000000,stroke-width:2px,color:#000000
style I fill:#ffffff,stroke:#000000,stroke-width:2px,color:#000000
- Full NIfTI-1 Specification Compliance - Complete support for NIfTI-1 format with validation
- File Format Support - Read/write
.nii,.hdr/.img, and gzipped variants (.nii.gz,.hdr.gz/.img.gz) - Type-Safe API - Strongly-typed access to neuroimaging data with compile-time safety
- 4D Time Series - Full support for fMRI time series and multi-dimensional datasets
- Comprehensive Validation - 75+ conformance tests ensuring specification compliance
- Performance Optimized - Efficient memory management for large medical imaging datasets
- Cross-Platform - .NET Standard 2.0 compatible (Windows, macOS, Linux)
Install-Package Nifti.NETdotnet add package Nifti.NET<PackageReferenceInclude="Nifti.NET"Version="1.2.0" />usingNifti.NET;// Read a NIfTI filevarnifti=NiftiFile.Read("brain_scan.nii");// Access header informationConsole.WriteLine($"Dimensions: {nifti.Header.dim[1]}×{nifti.Header.dim[2]}×{nifti.Header.dim[3]}");Console.WriteLine($"Voxel size: {nifti.Header.pixdim[1]}×{nifti.Header.pixdim[2]}×{nifti.Header.pixdim[3]}mm");Console.WriteLine($"Data type: {nifti.Header.datatype}");// Access voxel datafloatvoxelValue=nifti[64,64,32];// Voxel at coordinates (64,64,32)// Create a 3D brain volumevarvolumeData=newfloat[256*256*180];// Your imaging datavardimensions=newint[]{256,256,180};varpixelDimensions=newfloat[]{1.0f,1.0f,1.0f};// 1×1×1mm isotropic voxelsvarnifti=Nifti.CreateFromData(volumeData,dimensions,pixelDimensions,"T1 Brain Volume");NiftiFile.Write(nifti,"t1_brain.nii.gz");// Create 4D fMRI time series: 64×64×32 voxels × 200 time pointsvartimeSeriesData=newfloat[64*64*32*200];vardimensions=newint[]{64,64,32,200};varpixelDimensions=newfloat[]{3.0f,3.0f,3.0f,2.0f};// TR = 2 secondsvarfmriNifti=Nifti.CreateFromData(timeSeriesData,dimensions,pixelDimensions,"BOLD fMRI");// Extract time series from specific voxelvarvoxelTimeSeries=newfloat[200];for(intt=0;t<200;t++){voxelTimeSeries[t]=fmriNifti[32,32,16,t];// ROI voxel time series}// Create strongly-typed NIfTI objectsvarfloatNifti=Nifti.CreateFromData<float>(floatData,dimensions);varshortNifti=Nifti.CreateFromData<short>(shortData,dimensions);varbyteNifti=Nifti.CreateFromData<byte>(byteData,dimensions);// Type-safe data accessfloat[]voxelData=floatNifti.Data;shortmaxValue=shortNifti.Data.Max();classDiagram
class NiftiFile {
+Read(string path) NiftiObject
+Write(NiftiObject nifti, string path)
+Validate(string path) ValidationResult
}
class NiftiObject {
+Header: NiftiHeader
+Data: Array
+this[x,y,z]: T
+GetSlice(int slice): Array
}
class NiftiHeader {
+dim: int[]
+pixdim: float[]
+datatype: DataType
+description: string
+Validate(): ValidationResult
}
class Nifti {
+CreateFromData<T>(data, dims): NiftiObject
+CreateFromData<T>(data, dims, pixdims): NiftiObject
+CreateFromData<T>(data, dims, pixdims, desc): NiftiObject
}
NiftiFile --> NiftiObject
NiftiObject --> NiftiHeader
Nifti --> NiftiObject
classDef default fill:#ffffff,stroke:#000000,stroke-width:2px,color:#000000
classDef primary fill:#e3f2fd,stroke:#000000,stroke-width:3px,color:#000000
class NiftiFile primary
class NiftiObject primary
| NIfTI Data Type | .NET Type | Description |
|---|---|---|
DT_UINT8 | byte | Unsigned 8-bit integer |
DT_INT16 | short | Signed 16-bit integer |
DT_INT32 | int | Signed 32-bit integer |
DT_FLOAT32 | float | 32-bit floating point |
DT_COMPLEX64 | Complex | 64-bit complex |
DT_FLOAT64 | double | 64-bit floating point |
DT_RGB24 | RGB24 | RGB color triplet |
// Comprehensive validationvarvalidator=newNiftiValidator();varresult=validator.ValidateFile("brain_scan.nii");if(result.IsValid){Console.WriteLine("✅ File passes all NIfTI-1 conformance tests");}else{foreach(varerrorinresult.Errors){Console.WriteLine($"❌ {error.Message}");}}- 75+ Conformance Tests - Comprehensive NIfTI-1 specification validation
- Header Validation - Ensures proper header structure and values
- Data Integrity - Validates data array consistency with header information
- File Format - Checks proper file structure and encoding
flowchart LR
A[MRI Scanner] --> B[DICOM Files]
B --> C[dcm2niix Conversion]
C --> D[NIfTI Files]
D --> E[Nifti.NET Processing]
E --> F[Analysis Results]
E --> G[Brain Segmentation]
E --> H[Statistical Analysis]
E --> I[Visualization]
style A fill:#ffffff,stroke:#000000,stroke-width:2px,color:#000000
style B fill:#ffffff,stroke:#000000,stroke-width:2px,color:#000000
style C fill:#ffffff,stroke:#000000,stroke-width:2px,color:#000000
style D fill:#ffffff,stroke:#000000,stroke-width:2px,color:#000000
style E fill:#bbdefb,stroke:#000000,stroke-width:3px,color:#000000
style F fill:#ffffff,stroke:#000000,stroke-width:2px,color:#000000
style G fill:#ffffff,stroke:#000000,stroke-width:2px,color:#000000
style H fill:#ffffff,stroke:#000000,stroke-width:2px,color:#000000
style I fill:#ffffff,stroke:#000000,stroke-width:2px,color:#000000
// Hospital PACS integration examplepublicclassMedicalImagingService{publicasyncTask<ProcessingResult>ProcessBrainScan(stringniftiPath){varnifti=NiftiFile.Read(niftiPath);// Validate medical imaging dataif(!ValidateMedicalImage(nifti))thrownewInvalidDataException("Invalid medical image format");// Extract clinical metricsvarvolume=CalculateBrainVolume(nifti);varregions=SegmentBrainRegions(nifti);returnnewProcessingResult{Volume=volume,Regions=regions,QualityScore=CalculateImageQuality(nifti)};}}- Memory Efficient - Lazy loading for large datasets
- Fast I/O - Optimized file reading/writing operations
- Scalable - Handles datasets from small volumes to large 4D time series
We welcome contributions from the medical imaging and .NET communities!
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Add tests for your changes
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- NIfTI-1 Specification - Neuroimaging Informatics Technology Initiative
- Medical Imaging Community - For feedback and real-world usage insights
- Contributors - Thank you to all who have contributed to this project
- 13.8K+ NuGet Downloads - Active usage across healthcare and research
- 12 GitHub Stars - Community recognition
- 8 Forks - Active development contributions
- MIT Licensed - Open source and industry-friendly
Built for the medical imaging community • Trusted by researchers worldwide • Production-ready