questions > RE: Using dcm2niix on subfolders with an archive
Jul 13, 2019  12:07 PM | Chris Rorden
RE: Using dcm2niix on subfolders with an archive
No, dcm2niix does not handle DICOMs archived in compressed zip files. You can use your favorite scripting language here. Below is my Matlab script for tgz archives which can easily be modified for zip files:


----------------------------
function tgz2dcm1
%matlab script to convert DICOM images saved in compressed .tgz archives
tgzDir = '/Volumes/TbStick/DIOCM';
outDir = '/Volumes/TbStick/nifti';
dcm2niix = '/usr/local/bin/dcm2niix';
if ~exist(dcm2niix,'file'), error('Unable to find %s',dcm2niix); end;
d = dir(fullfile(tgzDir,'*.tgz'));
if isempty(tgzDir), error('No tgz files in %s', tgzDir); end
nams ={d.name};
nams =sort(nams);
for i = numel(nams): -1 : 1 %173numel(nams)
nam = nams{i};
[~, n] = fileparts(nam);
fprintf('%d/%d >> %s\n', i, numel(nams), n);
nam2 = fullfile(tgzDir,nam);
outDir2 = fullfile(outDir,n);
if exist(outDir2,'dir'), continue; end;
mkdir(outDir2);
outDir3 = fullfile(outDir2,n);
mkdir(outDir3);
untar(nam2, outDir3);
%convert DICOM -> Json
cmd = sprintf('%s -9 -b y -ba n -z y -i y -f %%t_%%s_%%p %s', dcm2niix, outDir2);
fprintf('Running \n %s\n', cmd);
system(cmd,'-echo');
rmdir(outDir3, 's')
end

Threaded View

TitleAuthorDate
Ari Kahn Jul 12, 2019
RE: Using dcm2niix on subfolders with an archive
Chris Rorden Jul 13, 2019