# Troubleshooting Image Corruption in NRRD Files When Concatenating Multiple Raw Files into a Single Volume

**URL:** https://discourse.slicer.org/t/troubleshooting-image-corruption-in-nrrd-files-when-concatenating-multiple-raw-files-into-a-single-volume/34532
**Category:** Support
**Created:** [February 25, 2024, 8:07pm UTC](https://discourse.slicer.org/t/troubleshooting-image-corruption-in-nrrd-files-when-concatenating-multiple-raw-files-into-a-single-volume/34532 "2024-02-25T20:07:10Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![rcapozza](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rcapozza/32/11682_2.png) [@rcapozza](https://discourse.slicer.org/u/rcapozza)
#### Post date: [February 25, 2024, 8:07pm UTC](https://discourse.slicer.org/t/troubleshooting-image-corruption-in-nrrd-files-when-concatenating-multiple-raw-files-into-a-single-volume/34532/1 "2024-02-25T20:07:10Z")

</div>

I am using NDDR files to load a volume, each file references a consecutively numbered raw file type from 1 to 10; my idea to avoid having to create ten NDDR files is to concatenate all the files into a single one named data.raw and read it with a single NDDR file. I believe this is possible, but when I try it, the image gets corrupted.  
The content of each file is as follows:  
NRRD0004

# Complete NRRD file format specification at:

# [Teem: nrrd: Definition of NRRD File Format](http://teem.sourceforge.net/nrrd/format.html)

type: short  
dimension: 3  
space: left-posterior-superior  
sizes: 271 271 1  
space directions: (0.59, 0.0, 0.0) (0.0, 0.59, 0.0) (0.0, 0.0, 2.5)  
kinds: domain domain domain  
endian: little  
encoding: raw  
space origin: (0.0, 0.0, 0.0)  
byte skip: 1609  
data file: I0024241.M0X

where .M0X ranges from .M01 to .M10

and what I want to implement with the single file is:  
NRRD0004

# Complete NRRD file format specification at:

# [Teem: nrrd: Definition of NRRD File Format](http://teem.sourceforge.net/nrrd/format.html)

type: short  
dimension: 3  
space: left-posterior-superior  
sizes: 271 271 10  
space directions: (0.59, 0.0, 0.0) (0.0, 0.59, 0.0) (0.0, 0.0, 2.5)  
kinds: domain domain domain  
endian: little  
encoding: raw  
space origin: (0.0, 0.0, 0.0)  
byte skip: 1609  
data file: data.raw

data.raw contains the concatenated files I0024241.M01 to I0024241.M10

Thank you in advance for any help you can provide.

---

<div class="post-metadata">

### Author: ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)
#### Post date: [February 25, 2024, 11:52pm UTC](https://discourse.slicer.org/t/troubleshooting-image-corruption-in-nrrd-files-when-concatenating-multiple-raw-files-into-a-single-volume/34532/2 "2024-02-25T23:52:26Z")

</div>

There’s a lot of useful debugging advice here:

[https://teem.sourceforge.net/nrrd/format.html](https://teem.sourceforge.net/nrrd/format.html)

---

<div class="post-metadata">

### Author: ![rcapozza](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rcapozza/32/11682_2.png) [@rcapozza](https://discourse.slicer.org/u/rcapozza)
#### Post date: [February 26, 2024, 12:15am UTC](https://discourse.slicer.org/t/troubleshooting-image-corruption-in-nrrd-files-when-concatenating-multiple-raw-files-into-a-single-volume/34532/3 "2024-02-26T00:15:01Z")

</div>

Thank you, pieper, I have based my work on that documentation to generate the NRRD file. I believe my problem lies in how to merge the image files into a single one. Should I only keep the portion corresponding to the image data, or can the complete files be concatenated with their headers? That is, is the “byte skip” command used on each of the slices stored in the file, or only at the beginning of its reading?

---

<div class="post-metadata">

### Author: ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)
#### Post date: [February 26, 2024, 12:28am UTC](https://discourse.slicer.org/t/troubleshooting-image-corruption-in-nrrd-files-when-concatenating-multiple-raw-files-into-a-single-volume/34532/4 "2024-02-26T00:28:02Z")

</div>

As I recall byte skip only refers to the start of a single file and I don’t think there’s a way to skip the headers of each of the files in a data file list, but I could be wrong about that. As I recall there’s also an option to give a -1 for byte skip so that it figures out from the file size and expected image size how big the header is. If you want to merge all the files into a single raw file you almost certainly need to concatenate only the image parts (uncompressed). Also if you are working with named files be sure to check the option of giving a printf-style string to create the filenames from the number pattern.

I pointed to the nrrd documentation also so you would have a look at unu and the rest of the nrrd utility set. There are lots of ways to create and manipulate nrrd files and with some experiments you can pretty much do anything.
