<p>I couldn't find a way of doing that using the arguments in the mri_convert, so I decided to do it programatically in bash. This answer will only work in Linux (or in any bash). It's an one-line command to iterativelly run the convertion on all files in the same directory.</p>

<pre><code>for f in *.img; do mri_convert $f $f.mgz; done
</code></pre>

<p>There is one aspect that I did not get right, that is FS actually handles img files, however these files do not have directionality information, thus using them is not recommended. </p>

<p>One can simply feed the recon-all command with the img file and the command will take care of the conversion.</p>

CC BY-SA 3.0
2015-12-18T21:14:41.107Z
2015-12-24T00:22:46.383Z
2015-12-24T00:22:46.383Z
lf_araujo
<p>I have a series of .img files from a previous analysis in SPM that Freesurfer (FS) cannot directly handle. </p>

<p>FS comes with a conversion tool, the mri_convert command, but I am not able to make it run iteratively over all the files in the same directory. I found a mention about the --sdcmlist argument <a href="https://mail.nmr.mgh.harvard.edu/pipermail/freesurfer/2009-May/010526.html" rel="nofollow">online</a>, however I am not figuring out the proper syntax for it.</p>

<p>When I run:</p>

<pre><code>mri_convert --sdcmlist 000123_1_4.img 000123_1_4.mgz
</code></pre>

<p>I get:</p>

<pre><code>mri_convert: missing output volume name
</code></pre>

<p>Would anyone suggest a way of going about these conversions?</p>

<neuroimaging>
Batch converting .img files to .mgz in FreeSurfer
lf_araujo
# Batch converting .img files to .mgz in FreeSurfer

(Asked by: username_0 on 2015-12-18)

I have a series of .img files from a previous analysis in SPM that Freesurfer (FS) cannot directly handle. 
FS comes with a conversion tool, the mri_convert command, but I am not able to make it run iteratively over all the files in the same directory. I found a mention about the --sdcmlist argument online, however I am not figuring out the proper syntax for it.
When I run:
mri_convert --sdcmlist 000123_1_4.img 000123_1_4.mgz

I get:
mri_convert: missing output volume name

Would anyone suggest a way of going about these conversions?

**Tags:** neuroimaging


---

## 1 answers

### Answer by username_0 on 2015-12-18. Score: 1 | Accepted answer

I couldn't find a way of doing that using the arguments in the mri_convert, so I decided to do it programatically in bash. This answer will only work in Linux (or in any bash). It's an one-line command to iterativelly run the convertion on all files in the same directory.
for f in *.img; do mri_convert $f $f.mgz; done

There is one aspect that I did not get right, that is FS actually handles img files, however these files do not have directionality information, thus using them is not recommended. 
One can simply feed the recon-all command with the img file and the command will take care of the conversion.


---

