Nifti.NET 1.2.0

dotnet add package Nifti.NET --version 1.2.0
                    
NuGet\Install-Package Nifti.NET -Version 1.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Nifti.NET" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Nifti.NET" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="Nifti.NET" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Nifti.NET --version 1.2.0
                    
#r "nuget: Nifti.NET, 1.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Nifti.NET@1.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Nifti.NET&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=Nifti.NET&version=1.2.0
                    
Install as a Cake Tool

Nifti.NET

A basic library for reading, writing and manipulating NIfTI files.

(If you're looking for the TensorFlow CNN platform, try NiftyNet (https://niftynet.io/))

Features

  • Read and write NIfTI files (.nii, .hdr/.img)
  • Support for gzipped files (.nii.gz, .hdr.gz/.img.gz)
  • Create NIfTI objects from data arrays
  • Type-safe access to neuroimaging data
  • Support for all standard NIfTI data types

Usage

Reading NIfTI Files

using Nifti.NET;

// Read a NIfTI file
var nifti = NiftiFile.Read("brain_scan.nii");

// Access header information
Console.WriteLine($"Dimensions: {nifti.Header.dim[1]}x{nifti.Header.dim[2]}x{nifti.Header.dim[3]}");
Console.WriteLine($"Data type: {nifti.Header.datatype}");

// Access voxel data
float voxelValue = nifti[64, 64, 32]; // Access voxel at coordinates (64,64,32)

Creating NIfTI Objects from Data

// Create a 3D volume from a float array
var data = new float[64 * 64 * 32]; // Your data here
var dimensions = new int[] { 64, 64, 32 };
var pixelDimensions = new float[] { 1.0f, 1.0f, 2.0f }; // 1x1x2mm voxels

var nifti = Nifti.CreateFromData(data, dimensions, pixelDimensions, "My volume");

// Save to file
NiftiFile.Write(nifti, "my_volume.nii");

Type-Safe Access

// Create strongly-typed NIfTI object
var typedNifti = Nifti.CreateFromData<float>(data, dimensions);

// Type-safe data access
float[] voxelData = typedNifti.Data;
float voxelValue = typedNifti[x, y, z];

Working with Different Data Types

// Byte data (8-bit)
var byteData = new byte[256 * 256];
var byteNifti = Nifti.CreateFromData(byteData, new int[] { 256, 256 });

// Integer data (32-bit)
var intData = new int[128 * 128 * 64];
var intNifti = Nifti.CreateFromData(intData, new int[] { 128, 128, 64 });

// Double precision data (64-bit)
var doubleData = new double[64 * 64 * 32];
var doubleNifti = Nifti.CreateFromData(doubleData, new int[] { 64, 64, 32 });

4D Time Series Data

// Create 4D fMRI time series: 64x64x32 voxels x 200 time points
var timeSeriesData = new float[64 * 64 * 32 * 200];
var dimensions = new int[] { 64, 64, 32, 200 };
var pixelDimensions = new float[] { 2.0f, 2.0f, 3.0f, 2.0f }; // TR = 2 seconds

var fmriNifti = Nifti.CreateFromData(timeSeriesData, dimensions, pixelDimensions, "fMRI time series");

// Access time series at specific voxel
float valueAtTime10 = fmriNifti[32, 32, 16, 10];
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0 304 6/15/2025
1.1.4 10,927 7/16/2021
1.1.3 647 2/22/2021
1.1.2 487 2/2/2021
1.1.1 719 6/26/2019
1.1.0 670 6/17/2019
1.0.1 691 6/4/2019
1.0.0 717 5/20/2019

Major update: Added CreateFromData factory methods for programmatic NIfTI creation, comprehensive NIfTI-1 specification conformance testing with 75+ validation tests, advanced header validation, NiftiValidator utility class, and command-line conformance checker tool. Enhanced error handling and robustness.