# 3D to 4D

**URL:** https://community.mrtrix.org/t/3d-to-4d/3095
**Category:** Uncategorized
**Created:** [December 5, 2019, 7:00am UTC](https://community.mrtrix.org/t/3d-to-4d/3095 "2019-12-05T07:00:28Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Omid33](https://community.mrtrix.org/letter_avatar_proxy/v4/letter/o/d9b06d/32.png) [@Omid33](https://community.mrtrix.org/u/Omid33)
#### Post date: [December 5, 2019, 7:00am UTC](https://community.mrtrix.org/t/3d-to-4d/3095/1 "2019-12-05T07:00:28Z")

</div>

Hi Mrtrix team,

What’s the best method to make 4D images out of 3D .nii files.  
I have DICOM files. I tried to make 4D .nii by mrcron/fsl but it failed.

Thanks,

---

<div class="post-metadata">

### Author: ![Antonin\_Skoch](https://community.mrtrix.org/user_avatar/community.mrtrix.org/antonin_skoch/32/358_2.png) [@Antonin\_Skoch](https://community.mrtrix.org/u/Antonin_Skoch)
#### Post date: [December 5, 2019, 1:38pm UTC](https://community.mrtrix.org/t/3d-to-4d/3095/2 "2019-12-05T13:38:17Z")

</div>

Hi, @omid33,

to concatenate several 3D `.nii` files to one, you can use command

`mrcat image1 image2 image3 output_image.nii`

To convert DICOM to `.nii` using Mrtrix3 tools, you can use  
`mrconvert your_dicom_directory output.nii`

Nevertheless, if you work with diffusion data, you have to handle bvecs/bvals also. In that case it is best option to use `.mif` or `.mif.gz` (compressed) format, which has bvecs/bvals table embedded into header. I.e. to use  
`mrconvert your_dicom_directory output.mif.gz`

Antonin

---

<div class="post-metadata">

### Author: ![mindmap2](https://community.mrtrix.org/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mindmap2](https://community.mrtrix.org/u/mindmap2)
#### Post date: [August 3, 2020, 9:08am UTC](https://community.mrtrix.org/t/3d-to-4d/3095/3 "2020-08-03T09:08:37Z")

</div>

Hi Antonin,  
I have the same problem as Omid.Are the commands that you mentioned in MATLAB?

Thanks,

---

<div class="post-metadata">

### Author: ![jdtournier](https://community.mrtrix.org/user_avatar/community.mrtrix.org/jdtournier/32/2594_2.png) [@jdtournier](https://community.mrtrix.org/u/jdtournier)
#### Post date: [August 3, 2020, 9:25am UTC](https://community.mrtrix.org/t/3d-to-4d/3095/4 "2020-08-03T09:25:25Z")

</div>

Hello,

If you’re converting from DICOM, and all the data were acquired as part of the same DICOM _series_, then [mrconvert](https://mrtrix.readthedocs.io/en/latest/reference/commands/mrconvert.html) should produce a single image file (whether in NIfTI or MRtrix format), using a command like:

```auto
mrconvert DICOM_folder/ output.mif

```

This is a _shell_ command, not in MatLab.

For details of DICOM handling, see [here](https://mrtrix.readthedocs.io/en/latest/getting_started/image_data.html#dicom-folder-or-dcm) and [here](https://mrtrix.readthedocs.io/en/latest/tips_and_tricks/dicom_handling.html) in the docs.

As @Antonin_Skoch mentions, if you have multiple image files, you can concatenate using [mrcat](https://mrtrix.readthedocs.io/en/latest/reference/commands/mrcat.html). Alternatively, if your images are numbered sequentially, you can use a command like this instead:

```auto
mrconvert input-[].nii output.nii

```

where the `[]` square brackets take the place of the numbers in your filenames (this uses the [numbered image](https://mrtrix.readthedocs.io/en/latest/getting_started/image_data.html#multi-file-numbered-image-support) feature in the _MRtrix_ backend).

You might need to do this if you acquired your DWI data in different DICOM series (e.g. one per _b_-value shell). However, in this case, you’d probably be advised to instead use the new [dwicat](https://mrtrix.readthedocs.io/en/latest/reference/commands/dwicat.html) command, since this will additionally handle any scaling inconsistencies that can occur between the different images sets when acquired separately.

Finally, and as @Antonin_Skoch also mentioned: if these are DWI data, you will need to take care of how you deal with the DW encoding information. I recommend you read up on how these issues are handled in _MRtrix_, starting with [this page in the documentation](https://mrtrix.readthedocs.io/en/latest/concepts/dw_scheme.html). Consistent handling of the DW encoding is one of the main reasons we strongly recommend you use the MRtrix `.mif` format rather than NIfTI, unless it is critical that you convert the data to `.nii`, e.g. to interoperate with other software packages.
