I use SPM’s dicom import function to convert DICOM files to Analyze files. But it’s quite inconvenient if I have 20 subjects. Below is a script to do this conversion automatically. You can call this function inside a loop.
function dicom2img(files) % function dicom2img(files) % % This function is to convert dicom files to Analyze image files using SPM % script % % files (optional): list of dicom files % % Xu Cui % if(nargin < 1) if findstr('SPM2',spm('ver')) files = spm_get('files', pwd, '*.dcm'); else files = spm_select('list', pwd, '\.dcm'); end end spm_defaults; hdr = spm_dicom_headers(files); spm_dicom_convert(hdr); display('done!') return;
Thanks for the code.I am using SPM5 and it does not have the function name spm_get.But I have replaced the function spm_get with spm_get_data.I have also passed the value of variable ‘files’.But still I am not getting the result.To access the files I have used following code:
owd=input(‘Enter the path of RAW images:\n’);
dirdata=dir(owd);
dirIndex=[dirdata.isdir];
files={dirdata(~dirIndex).name}’
Kindly provide me the code and help
Thanks
@Rohan
Does spm_select work?
I guess the spm_select works but the output in hdr is empty..
@Rohan
Then what is in ‘files’
The program runs and gives me error “Cant yet convert Phillips Intera DICOM”..This error is generated from spm_dicom_convert.m file.I do not understand why I am getting this message and how to remove it.
The above code worked with some changes.Now in my code i need to direct the analysis files to another directory.I need it to be done inside the code.Please help me with it.
Thanks
Dear Xu!
I am using spm8 and trying to batch the dicom import.
Do you know how I can search also the subdirectories of the DICOM folder?
So far,I cd to the DICOM folder and use
[files,dirs]=cfg_getfile(‘list’, pwd, ‘.’);
and get the subdirectories only.
Thank you! Dorothea
@Dorothea
Once you get the names of the subfolders, you can cd to those folders and run the above code.