Is there a way to loop through multiple sub-folders with dcm2niix + create BIDS structure?

Hi community,

Does someone have a work-flow that lets dcm2niix loop through all subject subfolders in a parentDir, thus converting dcm per subject, and then reorganising them into BIDSstructure in the outputNifti folder, also per subject? I feel like this has to be possible otherwise it’d be quite tedious work, but somehow I can’t find anything on this topic. Maybe it’s too easy to write about =D?

Thanks in advance!
(And excuses if I missed another thread where this has already been answered.)

I suggest you look at the dcm2niix Links section which list several wrappers for dcm2niix to generate the BIDS structure.

dcm2niix converts DICOM images to BIDS compatible NIfTI images with and JSON sidecar. DICOM has been interpreted differently by different manufacturers, and due to changes like enhanced DICOM it is a moving target. It is impossible to infer the users intention based solely on DICOM data. dcm2niix is written in C, providing very high performance. However, languages like Python are much better for allowing users to describe their intention for specific sequences.

1 Like

thank you for your answer.
I’m using dcm2niix and currently trying to get bidskit to work.
I’ve followed the tutorials online, but they only seem to describe how to do it for one subject at a time.
I’d like to iterate through my folders instead of doing it one by one.
I understand that it’s hard to standardise across users/projects, but was wondering if there is a starting script/guide one could use or which would at least give an idea how such a python/unix/matlab script could look like for those of us who are still learning?
thank you!

I think others are better placed than me to respond. I think the best tool depends on your background with scripting languages. Some of the popular and well documented solutions for archival data include

Hi Chris,
nothing worked but bidskit which now runs flawlessly and over multiple subjects. Thank you for being so responsive, you’re really a treasure in this community =).
Have a nice day!

1 Like

I am facing exactly the same problem but i cannot understand how bidskit works and can solve this issue. Could you kindly explain me how did you manage to figure it out?
Best regards

any of the solutions for archival data Chris mentioned should do the job for you. Bidskit for example will create the BIDS folder structure for you at first pass, convert the dcm to nifti in a second pass (using dcm2niix), and anonymize your data and put it in the corresponding folders at third pass. You’ll have to specify your protocol_translator.json after the first pass. Make sure to have bidsvalidator installed, too, to ensure your structure and namings are bids valid.
At least this is how I understand it and what worked for me, I’m still new though so maybe others have a better answer.

Hi all, dcm2bids might help you here. It at least takes care of running dcm2niix and bidsifying. Then all you have to do is nest the dcm2bids command in a for-loop, for example, and loop over subject IDs. The program has good documentation/tutorials to get started. Make sure you have the most recent dcm2niix installed before getting started.

I recently tried to improve the list of BIDS converters that are out there :Brain Imaging Data Structure

I am starting to try some of them to give better advises and descriptions of the pros and cons of each.