Hey guys, in this video I want to go over how to convert from DICOMs into a BIDS folder
set.
BIDS stands for Brain Imaging Data Structure.
It's basically a standardized folder structure and also file format and naming structure
used in neuroimaging analysis.
I believe this comes from a lab from Stanford that has been pushing a lot in the last 2
or 3 years a standardized pipeline for neuroimaging preprocessing.
I was looking into this because I was interested trying out fMRIPrep, which is a fMRI preprocessing
pipeline that you can customize but it's basically like freely available online for different
labs to use.
The idea basically that you input this data folder that has a standardized naming structure
for the subfolders and also a specific kind of files with a specific kind of naming structure
as well.
In this video, I'm really just going to go over how you convert from DICOMs into the
file structure that BIDS uses.
I'll put a link to all of the stuff that I'm looking at online in the description box below.
If you go to the official BIDS website, they have a freely available paper that first talks
about how BIDS came about and basically what the structure is, if you want more information.
I'm specifically just going to be talking about the DICOM conversion, like already said.
In the paper, it mentions two different ways to convert the DICOMs to the files that BIDS
uses.
BIDS uses NIFTIs, specifically compressed NIFTI--I think it uses NIFTIs or compressed
NIFTIs but we just going to get, in this case, compressed NIFTIs.
And for anyone who know about neuroimaging, you know that when you're converting from
DICOMs to NIFTIs, DICOMS have header information that sometimes is lost when you're converting
to a NIFTI.
If you're doing a preprocessing needs this header information, which you probably are,
basically the BIDS solution to that is you're going to have what's called JSON sidecar.
Every NIFTI, or most NIFTIs, will have a--you'll have the NIFTI file in the folder, and then
alongside that you'll have a JSON file alongside that with the same name as the NIFTI.
You see you have subject 1, the compressed NIFTIs, and then diffusion weighted, and then
you'll have the JSON file.
And I'll show you what the JSON file is, it's a type of javascript file extension and if
you open it up, it has just a bunch of metadata on it, so it has a bunch of the header information
that you lose when you convert to a NIFTI that you can still use with the NIFTI by reading
the JSON file.
And the paper mentions two ways to convert from DICOMs to NIFTIs to produce the NIFTI
and the JSON sidecare.
You can use the freely available dcm2niix, I guess I'll pronounce it.
It has an X at the end.
This is an updated version of dcm2nii.
And you can also use a very similarly worded function dicm2nii.
This is through MATLAB.
But it's also a free program that you can download and either--actually, both of them
are free.
Let me show you both ways to convert them.
If you use dcm2niix, you can either use that through the command line or through the GUI.
If you download MRIcroGL, or however you pronounce that, it will have the command line dcm2niix
that you can use, or you can DICOMs to NIFTIs just by opening the actual program itself.
I already have that on my computer here and this will open up this window.
Then from here, if you go to Import > Convert DICOM to NIFTIs, that will open this window.
This window gives you a couple options.
You can edit how you want the output files to be named.
You need to specify the output folder.
And so I already have some DICOMs that I'm going to convert.
Let me create a sample output folder that's empty and that's where I'm going to write
all my files.
Let me just specify that.
And then you have this box for a checkmark.
I think this is a little bit bugged because the BIDS flag here, the -b, that's actually
what writes to BIDS, so I checked this earlier today and if you check it or not, it will
actually still print in BIDS format, I think this is a bug in the code because actually
what it's changing is verbose.
Hold on, here let me see.
Yeah this code is like a little bit bugged but anyway.
This is--this will change whether it's compressed or not, supposedly, but then--I don't know.
Either way if you check that or not, it will actually automatically--for now--it will automatically
output in BIDS format, so it will give you the compressed NIFTIs and as wells the JSON
sidecar because what it's actually looking at is this -b flag and if it's at yes, then
it will do it in BIDS format.
Once you have your parameters all set up, then you're going to go up here to the file
again and select DICOM to NIFTIs.
Then just find the folder that has your DICOMs.
In my case, I have this sample folder.
And this will take about a minute or two.
The computer kind of--my computer is freezing when it does it but it will go away in like
a minute when it's done.
Okay so that took about a minute and then when that's done, let's check the output in
the output folder.
And that now has NIFTIs and it also has JSON sidecars.
Let me just open up a sample JSON sidecar so you can see that it has a bunch of metadata.
Some of that tags in the header folder, or in the header from the DICOMs, you won't need
when you're preprocessing but some of them you will.
It just keeps all that information in those JSON files in case you do need some of the
information.
And now let me show you the other way you can do it using MATLAB.
I already downloaded whatever program folder you needed and I set it in my path already.
If you haven't done that, you do need to add it to your path so that MATLAB can recognize
the function.
And then after that, the function is called dicm2nii.
If you click enter after you type that into the command line, it will open up this GUI.
I'm going to do the same thing.
Let me erase my old output folder and create a new empty one.
And so this is the input folder that has the DICOMs.
This will be my output folder.
Compress will either give you a compressed NIFTI or not.
I'm going to leave that checked.
And then, here is the option to save JSON files.
If you save the JSON files, then that will be in BIDS format or if not, you can uncheck
it.
And then you click Start Conversion.
This one doesn't freeze my computer like the other one did.
And this will tell you--and also the command line will tell you when it's done.
But this says 'Conversion in progress'.
It will change when it's done.
Once that's done, I'm going to check the output again.
And again you have the compressed NIFTIs with a JSON sidecar.
And from there, I would just manually create the folder structure and the naming structure.
It does want the subjects to be labeled like this, like sub-01, 02, etc.
These folder structures, there's something--there's like another program called like DICOM to
BIDS that will do all of these steps automatically, including the creation of the folder structure,
but I was looking at it and you need to setup a configuration file or something before you
run it and so I feel like that takes about as much work as just setting up the folders
manually.
From there, I think it's kind of like straightforward to create the exact folder structure and naming
structure.
That was--the DICOM conversion was like the main thing I wanted to go over in this video.
So yeah, that's it for this video and thank you for watching!
*chiptune music*