help
help > RE: batching .voi to .nii
Jun 1, 2017 01:06 AM | Chris Rorden
RE: batching .voi to .nii
Scott-
It might help if you told me what oeprating system you use and language you prefer. In general, the simplest way to do this is to use the MRIcron menu item Draw/Convert/VOI->NII. However, since .voi files are simply gzipped .nii files you can easily batch this in any language you want. The only difference between a .voi file and a FSL-style .nii.gz file is the extension. I use a different extension so when the user selects Draw/Open they only see the binary voi files, and are not confronted with a plethora of images that are not binary drawings.
function voi2nii(files)
%convert MRIcron .VOI files to NIfTI .NII images
% files : voi image(s) to convert
if ~exist('files','var')
[files,pth] = uigetfile({'*.voi'},'Select VOI Image[s]', 'MultiSelect', 'on');
files = strcat(pth, files); %add path to all file names
end;
files = cellstr(files); %make cellstr
for f=1:numel(files)
ref = strvcat(deblank(files(f)));
[pth,nam,ext] = spm_fileparts(ref);
if (length(ext)==4) && min((ext=='.voi')==1)
unz = gunzip(ref);
[upth,unam,uext] = spm_fileparts(strvcat(unz)); %#ok
if isempty(uext) %if "file.voi" -> "file" then -> "file.nii"
uext = '.nii';
movefile(strvcat(unz),fullfile(upth, [unam uext])); %#ok
end;
end;
end
It might help if you told me what oeprating system you use and language you prefer. In general, the simplest way to do this is to use the MRIcron menu item Draw/Convert/VOI->NII. However, since .voi files are simply gzipped .nii files you can easily batch this in any language you want. The only difference between a .voi file and a FSL-style .nii.gz file is the extension. I use a different extension so when the user selects Draw/Open they only see the binary voi files, and are not confronted with a plethora of images that are not binary drawings.
function voi2nii(files)
%convert MRIcron .VOI files to NIfTI .NII images
% files : voi image(s) to convert
if ~exist('files','var')
[files,pth] = uigetfile({'*.voi'},'Select VOI Image[s]', 'MultiSelect', 'on');
files = strcat(pth, files); %add path to all file names
end;
files = cellstr(files); %make cellstr
for f=1:numel(files)
ref = strvcat(deblank(files(f)));
[pth,nam,ext] = spm_fileparts(ref);
if (length(ext)==4) && min((ext=='.voi')==1)
unz = gunzip(ref);
[upth,unam,uext] = spm_fileparts(strvcat(unz)); %#ok
if isempty(uext) %if "file.voi" -> "file" then -> "file.nii"
uext = '.nii';
movefile(strvcat(unz),fullfile(upth, [unam uext])); %#ok
end;
end;
end
Threaded View
Title | Author | Date |
---|---|---|
Scott Love | Nov 17, 2016 | |
Chris Rorden | Jun 1, 2017 | |