The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

PDL::IO::Nifti -- Module to access imaging data using Nifti-1 standard

SYNOPSIS

#!/usr/bin/perl

use strict; use 5.10.0; use PDL; use PDL::IO::Nifti; use PDL::NiceSlice;

my $name=shift; my $file; say "testing write_nii()"; open $file,'>testnii.nii' or die "Cannot open file to write\n"; my $nii=PDL::IO::Nifti->new; # Creates the object $nii->img(rvals(64,32)); # Assigns data

# The following lines illustrate how to access PDLs $nii*=3000; $nii(0,).=0; say avg $nii; say $nii->info;

# Now we write out the data $nii->write_nii($file); close $file;

#Now we read a file open my $file,$name or die "Failed to read $name\n"; my $ni2=$nii->new; $ni2->read_nii($file); say $ni2->info; $ni2->(,,0)->squeeze->wpic('nii.png');

DESCRIPTION

Provides methods to read and write Nifti files, read, write and manipulate the header based on PDL.

my $nii=PDL::IO::Nifti->new($pdl); $nii->write_nii($file);

is all you need to do to save your data.

METHODS

new

Initialize the object. Calls img if passed an argument.

img

This method should be called whenever you want to explicitly access your piddle only. The first argument will replace your piddle with whatever it holds. It returns the piddle. This should be used if you want to also update the essential metadata like dimensions and datatype in the Nifti header.

read_nii

Loads an existing .nii file. If you have an analyze image/hdr pair, please convert to nifti first. All elements are loaded and are accessible via the get_field and set_field methods.

write_nii

Writes out the PDL, sets datatype and dimensions automatically, overwriting your own values, take care!

set_field

$nii->set_field(<name>,<value>,[pos]); Sets field <name> to <value>. If the field is an array, <value> is interpreted as an array reference, unless pos is supplied.

get_field

$par=$nii->get_field(<name>,[pos]); returns header values, same rules regarding arrays as in set_field applay.

write_hdr, read_hdr

so far only used/tested internally, but may be useful. They pack and write or retrieve and unpack the header, respectively.

BUGS/TODO

At the moment, read_nii and write_nii have only been tested for native PDL datatypes.

In case you get failures from read_nii/write_nii, try passing either a reference to an open filehandle or a filename. It tries to guess what argument has been given, but I'm not sure if it covers all cases.

Tests are still rudimentary, for the moment, noly reading is tested for.

SEE ALSO

http://nifti.nimh.nih.gov/nifti-1 - the Nifti standard on which this module is based.

AUTHOR

Albrecht Ingo Schmid