You sir are a god. Thank you for showing me how to do this on the CLI. To anyone interested, convert to nifti using "nii" argument. The variable 'char(fout)' is the output path variable. spm_dicom_convert(hdr, 'all', 'flat', 'nii', char(fout));
Thanks. A tip if you don't want to have to unzip your FSL output: create a directory named ~/.fslconf containing the file fsl.sh. This should consist of the lines FSLOUTPUTTYPE=NIFTI export FSLOUTPUTTYPE This will override the system-wide default FSLOUTPUTTYPE, which is by default NIFTI_GZ (this is stored somewhere like /usr/local/{version}/etc/fslconf/fsl.sh). No more unzipping.
Hi Paula, There are a couple of ways to skin this cat: 1) Convert your raw FMRI data using a tool like MRIcron, which allows you to specify the output in NIFTI or ANALYZE (i.e., .hdr/.img); or 2) After generating the ANALYZE files, use AFNI's 3dcopy to convert to AFNI format, and then use the command 3dAFNItoNIFTI to output NIFTI files. I don't *think* converting this much should cause too many issues, but always double-check your output. Take care! -Andy
Thanks Andy, but I found an even easier way to do this - in my Matlab script I summoned up the spm_defaults.m, and by typing 'edit spm_defaults.m', I was able to change the 'File format specific' default.images.format to 'nii'. Hope that tip helps another newbie like myself, and thanks again for the tutorials Andy! -p.
thanks for this video but I have a problem while importing DICOM file using spm12 every time I try this message appears "does not seem to have positional information"
Hi there, These days, I prefer to use dcm2niix for converting DICOMs to NIFTI. It is part of the MRIcroGL suite, which can be downloaded here: www.nitrc.org/projects/mricrogl Best, -Andy
Hey Andrew ..great video. I have a doubt though. I have 4D image series for each patinet( multiple folders with multiple slices in each folder) and it takes the shape (of 250,250,18,10) for one patient. 18 slices and 10 folders. 250*250 is pixels. Numbers varies from patient to patient though. Do you know how to put one patinet's 4D series to one file:- nifti or dicom or numpy array? (I want to give it as an input for my neural network.). Thanks in advance
Hey Edwin, How many images are in each folder? If you are talking about just concatenating the images, then see fslmerge or AFNI's 3dbucket command. I haven't found a similar tool in SPM, but I also haven't explored it thoroughly. -Andy
Hi Andrew, thanks for this! Unfortunately, SPM8 doesn't have a dicom import setting menu to specify if files are converted to .nii or .hdr and .img files, and they are being automatically converted to the latter 2 formats. Do you have any suggestions for how I can specify my converted files to be in .nii? Thanks so much! :)
Hey Andrew, Thanks a lot for the great videos! I am currently running MatLab in the Windows environment and would be greatly interested in using FSL tools via MatLab. However, I do only have access to the program via a virtual machine. Do you have any idea how to access FSl via Matlab, if it is run using a virtual machine? Thanks a lot in advance! Martin
+Martin Hochheimer Hi Martin, I'm not positive about this; I would write to the FSL listserv to see if they have any ideas. Just to clarify, when you talk about using FSL tools, are you just trying to call FSL commands from the Matlab command line? If so, you could use the "!" symbol in front of any FSL commands as an escape character, if you have FSL in your path. Best, -Andy
+Andrew Jahn Basically, yes. I, for example, want to use the skull stripping tool, because I am currently having some problems with the corregistration in my prerpocessing. Basically the functional images after the coregistrastion are cut off almost down to the corpus callosum. I checked the crosshair in the anatomical images and the realignment. Both looked ok. So I want to check the crosshair inthe other modalities and then strip away the skull before preprocessing to see, if that will make it better.
+Andrew Jahn Thanks a lot! Basically, yes. I, for example, want to use the skull stripping tool, because I am currently having some problems with my SPM preprocessing corregistration. The functional images are cut off almost down to the corpus callosum. I have checked the crosshair on the anatomic image andthe realginment images. They looked ok. Now I will manually change the crosshair on the other imaging modalities and get rid of the skull to see, if that will make it better.
+sukeshj Hi sukeshj, It depends; does the coursera course have a link to any raw data you can work with? Else, you could try out some publicly available online datasets. -Andy
Hi Andrew!! Just a quick one here....What would be the ideal way to compress the nii files if you do not have fsl or if fsl is running on a virutal machine?? Much appreciated!!
Sorry for not being able to get my head around this... I am using MATLAB on windows and Linux on virtual machine..The way I am doing it at the moment is by copying all the nii files to Linux, merging them, gun zipping and copying back to windows to be run on spm... I know this is not the most effective way of doing so would greatly appreciate if you could advise me regarding the same... Also, tried installing MRIcron, but strangely, the download is not coming up atm...
Try this: Open up SPM, and select "Batch" from the GUI. After the Batch Editor menu opens, select "SPM" from the menubar at the top of the menu, go to "Util" and then "3D to 4D Conversion." The steps should be straightforward from there. Also, if you want to run the script over multiple runs, you can enter all your parameters in the "3D to 4D..." module and save it as a script. See my tutorials on running SPM from the command line for more information about how to do this. Best, -Andy
Hi Andrew, I am trying to convert my dicom files to nifti. I have tried this multiple times but I keep getting one nii file named "snone-0000-00001-000001.nii" in my export directory instead of multiple nii files as seen in your video. I am using MATLAB R2020a and SPM 12 (7771). Do you know why this could be happening, is this normal?
Hi Mitch, I used to have the same problems with SPM's Dicom import function, so I switched to dcm2niix (click on the first result that is returned by Google). It's quick and simple to use, and it should format all of the output correctly. Best, -Andy
I have a problem. Matlab gives me a error 'fslmerge' is not recognized as an internal or external command, operable program or batch file. How can I solve it?
Do you have fsl installed on your machine? If not, you'll have to go to the FSL website and download the program: fsl.fmrib.ox.ac.uk/fsl/fslwiki/FslInstallation Once you have that and have your paths pointing to the FSL commands, you can run any FSL command by beginning your commands with an exclamation mark (e.g., "!fslmerge") -Andy
If you've set the paths as in the installation tutorial, then escaping the command (i.e., a '!' before typing any command) will execute the command from the Matlab terminal.
@@AndrewJahn I have the same problem. I downloaded FSL but the The command !fslmerge throws me the same error in Matlab. I tried running this command in Matlab but it still didn't work. Here it is: setenv('C:\Users ubin\Downloads\FSLVm7_64'); % this to tell where FSL folder is setenv('FSLOUTPUTTYPE', 'NIFTI_GZ'); % this to tell what the output type would be Can you tell me what I am missing here?
You sir are a god. Thank you for showing me how to do this on the CLI. To anyone interested, convert to nifti using "nii" argument. The variable 'char(fout)' is the output path variable.
spm_dicom_convert(hdr, 'all', 'flat', 'nii', char(fout));
Thanks.
A tip if you don't want to have to unzip your FSL output: create a directory named ~/.fslconf containing the file fsl.sh. This should consist of the lines FSLOUTPUTTYPE=NIFTI
export FSLOUTPUTTYPE
This will override the system-wide default FSLOUTPUTTYPE, which is by default NIFTI_GZ (this is stored somewhere like /usr/local/{version}/etc/fslconf/fsl.sh). No more unzipping.
Hi Paula,
There are a couple of ways to skin this cat:
1) Convert your raw FMRI data using a tool like MRIcron, which allows you to specify the output in NIFTI or ANALYZE (i.e., .hdr/.img); or
2) After generating the ANALYZE files, use AFNI's 3dcopy to convert to AFNI format, and then use the command 3dAFNItoNIFTI to output NIFTI files. I don't *think* converting this much should cause too many issues, but always double-check your output.
Take care!
-Andy
Thanks Andy, but I found an even easier way to do this - in my Matlab script I summoned up the spm_defaults.m, and by typing 'edit spm_defaults.m', I was able to change the 'File format specific' default.images.format to 'nii'.
Hope that tip helps another newbie like myself, and thanks again for the tutorials Andy!
-p.
thanks for this video
but I have a problem while importing DICOM file using spm12
every time I try this message appears "does not seem to have positional information"
Hi there,
These days, I prefer to use dcm2niix for converting DICOMs to NIFTI. It is part of the MRIcroGL suite, which can be downloaded here: www.nitrc.org/projects/mricrogl
Best,
-Andy
Hey Andrew, how do I convert an MINC or .rawb data using SPM?
Hey Andrew ..great video. I have a doubt though. I have 4D image series for each patinet( multiple folders with multiple slices in each folder) and it takes the shape (of 250,250,18,10) for one patient. 18 slices and 10 folders. 250*250 is pixels. Numbers varies from patient to patient though. Do you know how to put one patinet's 4D series to one file:- nifti or dicom or numpy array? (I want to give it as an input for my neural network.). Thanks in advance
Hey Edwin,
How many images are in each folder? If you are talking about just concatenating the images, then see fslmerge or AFNI's 3dbucket command. I haven't found a similar tool in SPM, but I also haven't explored it thoroughly.
-Andy
Hi Andrew, thanks for this! Unfortunately, SPM8 doesn't have a dicom import setting menu to specify if files are converted to .nii or .hdr and .img files, and they are being automatically converted to the latter 2 formats. Do you have any suggestions for how I can specify my converted files to be in .nii? Thanks so much! :)
great wonderful video!!!!! u just save me & my patient
aftet 100 % complete it show error in job execution how can i solve it?
Hey Andrew,
Thanks a lot for the great videos!
I am currently running MatLab in the Windows environment and would be greatly interested in using FSL tools via MatLab.
However, I do only have access to the program via a virtual machine. Do you have any idea how to access FSl via Matlab, if it is run using a virtual machine?
Thanks a lot in advance!
Martin
+Martin Hochheimer Hi Martin, I'm not positive about this; I would write to the FSL listserv to see if they have any ideas.
Just to clarify, when you talk about using FSL tools, are you just trying to call FSL commands from the Matlab command line? If so, you could use the "!" symbol in front of any FSL commands as an escape character, if you have FSL in your path.
Best,
-Andy
+Andrew Jahn
Basically, yes. I, for example, want to use the skull stripping tool, because I am currently having some problems with the corregistration in my prerpocessing. Basically the functional images after the coregistrastion are cut off almost down to the corpus callosum. I checked the crosshair in the anatomical images and the realignment. Both looked ok. So I want to check the crosshair inthe other modalities and then strip away the skull before preprocessing to see, if that will make it better.
+Andrew Jahn
Thanks a lot! Basically, yes. I, for example, want to use the skull stripping tool, because I am currently having some problems with my SPM preprocessing corregistration. The functional images are cut off almost down to the corpus callosum. I have checked the crosshair on the anatomic image andthe realginment images. They looked ok. Now I will manually change the crosshair on the other imaging modalities and get rid of the skull to see, if that will make it better.
Hi Andrew I m interested in learning fmri data analysis. I m taking course from coursera. Plz tell me where I will get dicom filed
+sukeshj Hi sukeshj,
It depends; does the coursera course have a link to any raw data you can work with? Else, you could try out some publicly available online datasets.
-Andy
Hi Andrew!! Just a quick one here....What would be the ideal way to compress the nii files if you do not have fsl or if fsl is running on a virutal machine?? Much appreciated!!
Hey Safal,
Do you have the gzip command on your virtual machine? I would use that.
Best,
-Andy
Sorry for not being able to get my head around this... I am using MATLAB on windows and Linux on virtual machine..The way I am doing it at the moment is by copying all the nii files to Linux, merging them, gun zipping and copying back to windows to be run on spm... I know this is not the most effective way of doing so would greatly appreciate if you could advise me regarding the same... Also, tried installing MRIcron, but strangely, the download is not coming up atm...
Try this: Open up SPM, and select "Batch" from the GUI. After the Batch Editor menu opens, select "SPM" from the menubar at the top of the menu, go to "Util" and then "3D to 4D Conversion." The steps should be straightforward from there.
Also, if you want to run the script over multiple runs, you can enter all your parameters in the "3D to 4D..." module and save it as a script. See my tutorials on running SPM from the command line for more information about how to do this.
Best,
-Andy
Hi Andrew, I am trying to convert my dicom files to nifti. I have tried this multiple times but I keep getting one nii file named "snone-0000-00001-000001.nii" in my export directory instead of multiple nii files as seen in your video. I am using MATLAB R2020a and SPM 12 (7771). Do you know why this could be happening, is this normal?
Hi Mitch,
I used to have the same problems with SPM's Dicom import function, so I switched to dcm2niix (click on the first result that is returned by Google). It's quick and simple to use, and it should format all of the output correctly.
Best,
-Andy
@@AndrewJahn Thanks. However, if I choose output format 'SPM8 (3D NIFTI nii) on dcm2niigui will I be able to still use these images with SPM12?
@@mitchsammut2992 Yes, you will be able to use them with SPM12.
-Andy
I have a problem. Matlab gives me a error
'fslmerge' is not recognized as an internal or external command,
operable program or batch file.
How can I solve it?
Do you have fsl installed on your machine? If not, you'll have to go to the FSL website and download the program: fsl.fmrib.ox.ac.uk/fsl/fslwiki/FslInstallation
Once you have that and have your paths pointing to the FSL commands, you can run any FSL command by beginning your commands with an exclamation mark (e.g., "!fslmerge")
-Andy
ok I downlanded the program. But how will I add it to matlab.
If you've set the paths as in the installation tutorial, then escaping the command (i.e., a '!' before typing any command) will execute the command from the Matlab terminal.
@@AndrewJahn
I have the same problem. I downloaded FSL but the The command !fslmerge throws me the same error in Matlab.
I tried running this command in Matlab but it still didn't work. Here it is:
setenv('C:\Users
ubin\Downloads\FSLVm7_64'); % this to tell where FSL folder is
setenv('FSLOUTPUTTYPE', 'NIFTI_GZ'); % this to tell what the output type would be
Can you tell me what I am missing here?