pepp3r
pepp3r

Reputation: 13

How can I convert MINC files to Nifti format recursively in bash using "mnc2nii"?

I need to convert image files with the MINC format (.mnc) to the NIfTI-1 format (.nii). I want to use the command "mnc2nii" of the minc-tools in Ubuntu bash.

"mnc2nii" requires an input (filename.mnc) and an output (filename.nii).

I have multiple folders and subfolders with MINC files in them.

I am trying to find a way to recursively convert all .mnc files to .nii so that they keep their name and folder structure.

Example:

file abc in /folder/abc.mnc converted to /folder/abc.nii

and

file xyz in /folder/subfolder/xyz.mnc converted to /folder/subfolder/xyz.nii.

Thank you

Upvotes: 1

Views: 1006

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207485

Untested because it's late here in the UK, so make a backup and test on a copy of a small subset of pictures.

First install GNU Parallel, then in terminal run:

find /path/to/mnc/files -type f -name \*.mnc -print0 |
   parallel --dry-run -0 mnc2nii {} {.}.nii

If you like the look, run it again without the --dry-run.

Being GNU Parallel it will do them very fast, in parallel :-)

Upvotes: 2

Related Questions