questions > dcm2niix and SPM12
Showing 1-3 of 3 posts
Display:
Results per page:
Feb 5, 2019  03:02 AM | cchassain - CHU Clermont-Ferrand
dcm2niix and SPM12
Dear Chris Roden,

I have used your dcm2niix.exe code (version V1.0.20181125) to convert enhanced DICOM data (EPI fMRI serie acquired from a Siemens VIDA with XVA11-A software).
Files generated are :
- a .JSON file with header information and suitably the slice timing parameters;
- a .nii.gz file (EPI serie).
After unzip the file (7zip), one file .nii is obtained (in this file there are all EPI volumes).

With SPM12, we need to specify each volume separatly.

Have you a suggestion to obtain one file for each volume?

Help would be truly appreciated !

Thanks in advance

Carine
Feb 5, 2019  05:02 AM | Chris Rorden
RE: dcm2niix and SPM12
Hello-
dcm2niix will save your 4D time series as a single file. While most processing pipelines expect 4D files, SPM12 can use either 3D or 4D files. With SPM12's graphical interface you can select to open the volumes of a 4D byt typing "1:9999" into the edit field (see image). With scripts you specify the volume number (e.g. 3) as follows: "img.nii,3". Personally, I prefer using 4D files as they cause less clutter than 3D and allow me to use other tools that expect 4D images. If you really want to convert a 4D file into 3D files you can use the tool 'fslsplit' or a simple Matlab script (see below);


function nii_4dto3d(fnm)
%convert a 4D NIfTI image to3D volumes
% fnm : (optional) filename of 4D image to segment
%Example
% nii_segment4d('img.nii');

if ~exist('fnm','var') %no files specified
fnm = spm_select(1,'image','Select 4D volume');
end
[pth,nam,ext] = spm_fileparts(fnm);
image = fullfile(pth,[nam,ext]); %'img.nii,1' -> 'img.nii'
hdr = spm_vol(image);
img = spm_read_vols(hdr);
nvol = numel(hdr);
hdr = hdr(1);
for vol=1: nvol
hdr.fname = fullfile(pth, [nam, '_', num2str(vol,'%04d'), ext]);
spm_write_vol(hdr,img(:, :, :, vol));
end
%end nii_4dto3d()
Attachment: spmSelect.png
Feb 5, 2019  05:02 AM | cchassain - CHU Clermont-Ferrand
RE: dcm2niix and SPM12
Hi Chris,

Thank for your answer.

Best regards,

carine

Originally posted by Chris Rorden:
Hello-
dcm2niix will save your 4D time series as a single file. While most processing pipelines expect 4D files, SPM12 can use either 3D or 4D files. With SPM12's graphical interface you can select to open the volumes of a 4D byt typing "1:9999" into the edit field (see image). With scripts you specify the volume number (e.g. 3) as follows: "img.nii,3". Personally, I prefer using 4D files as they cause less clutter than 3D and allow me to use other tools that expect 4D images. If you really want to convert a 4D file into 3D files you can use the tool 'fslsplit' or a simple Matlab script (see below);


function nii_4dto3d(fnm)
%convert a 4D NIfTI image to3D volumes
% fnm : (optional) filename of 4D image to segment
%Example
% nii_segment4d('img.nii');

if ~exist('fnm','var') %no files specified
fnm = spm_select(1,'image','Select 4D volume');
end
[pth,nam,ext] = spm_fileparts(fnm);
image = fullfile(pth,[nam,ext]); %'img.nii,1' -> 'img.nii'
hdr = spm_vol(image);
img = spm_read_vols(hdr);
nvol = numel(hdr);
hdr = hdr(1);
for vol=1: nvol
hdr.fname = fullfile(pth, [nam, '_', num2str(vol,'%04d'), ext]);
spm_write_vol(hdr,img(:, :, :, vol));
end
%end nii_4dto3d()