User Tools

Site Tools


processing_stream_-_image_file_conversion

Image file conversion

Motivation

It is very often the case that the data provided by the scanning facility is not in the format you require to perform the actual data processing and analysis. This page tries to cover the diverse format conversions that might be necessary for you to analyze your data.

Requirements

There are different scenarios, which each in comes with different prerequisites:

DICOM to Analyze/NIftI

  • a working installation of SPM5 or SPM8
  • if additional scripting is desired, NeuroElf can be used

BrainVoyager import

  • a working installation of BrainVoyager QX

Usage

SPM's interface for DICOM import

NeuroElf's scripting

To ensure that the sorted list of filenames to be imported are in a correct temporal order, the use of the renamedicom function is highly recommended (unless you can confirm that the files you have already are properly named).

This functionality is not yet available as a compound function, but can be easily achieved by using the following code for SPM5 (adapted to your specific situation, of course; wherever necessary and SPM8 instructions require, this is marked!):

% load the DICOM import job file
jobs = neuroelf_file('p', 'spm5_dicomimport_job');
% for SPM8 it's 'spm8_dicomimport_job' of course!
jobs = jobs.jobs;
 
% use SPM's defaults
spm_defaults;
% for SPM8 use spm('defaults', 'FMRI');
 
% ** IF YOU WISH TO USE THE SINGLE-FILE NIFTI FORMAT, SAY
% jobs{1}.util{1}.dicom.convopts.format = 'nii'; % for SPM5 or
% jobs{1}.spm.util.dicom.convopts.format = 'nii'; % for SPM8 !
% ** OTHERWISE THE TWO-FILE HDR+IMG FORMAT IS USED! **
 
% change into your study's folder
cd /Volumes/CHIP_project/Imaging/Subjects
 
% find all folders that contain DICOM import files (sessions)
importdirs = findfiles([pwd '/CHIP*/raw'], '*r*', 'dirs=1', 'depth=1');
 
% remove subjects that have already been imported
donedirs = findfiles([pwd '/CHIP*/func'], 'r*', 'dirs=1', 'depth=1');
for dc = 1:numel(donedirs)
 
    % take out those which match the CHIP* part
    [study, chip] = fileparts(fileparts(fileparts(donedirs{dc})));
    importdirs(~isemptycell(regexp(importdirs, chip))) = [];
end
 
% for all remaining session
for dc = 1:numel(importdirs)
 
    % find dicom files
    dcmfiles = findfiles(importdirs{dc}, '*.dcm', 'depth=1');
 
    % no files, continue
    if isempty(dcmfiles)
        continue;
    end
 
    % figure out the target folder
    [study, target] = fileparts(fileparts(dcmfiles{1}));
 
    % re-vamp the target folder name (which for us is NUMVOLr_NUMSCAN)
    target_particles = regexp(target, '^(\d+)r_(\d+)$', 'tokens');
    if isempty(target_particles) || ...
        numel(target_particles{1}) ~= 2
        continue;
    end
    target = sprintf('r%02d_%03d', ...
        str2double(target_particles{1}{2}), ...
        str2double(target_particles{1}{1}));
 
    % create target folder
    target = [fileparts(study) '/func/' target];
    mkadir(target);
 
    % put settings into job
    jobs{1}.util{1}.dicom.data = dcmfiles;
    jobs{1}.util{1}.dicom.outdir{1} = target;
    % for SPM8, these two lines must be
    % jobs{1}.spm.util.dicom.data = dcmfiles;
    % jobs{1}.spm.util.dicom.outdir{1} = target;
 
    % run import job
    spm_jobman('run', jobs);
end
 
% Done.
processing_stream_-_image_file_conversion.txt · Last modified: 2010/05/30 03:36 by jochen