# Multi-raw image loading using RawImageGuess extension

**URL:** <https://discourse.slicer.org/t/multi-raw-image-loading-using-rawimageguess-extension/26126>\
**Category:** Support\
**Created:** [November 8, 2022, 2:58am UTC](https://discourse.slicer.org/t/multi-raw-image-loading-using-rawimageguess-extension/26126 "2022-11-08T02:58:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![seyang](https://avatars.discourse-cdn.com/v4/letter/s/b38774/32.png) [@seyang](https://discourse.slicer.org/u/seyang)\
**Post date:** [November 8, 2022, 2:58am UTC](https://discourse.slicer.org/t/multi-raw-image-loading-using-rawimageguess-extension/26126/1 "2022-11-08T02:58:19Z")

</div>

Can someone help us to import multi-raw images?  
Our system is remaining each slice image.  
Ex) 240 Slice = Slice0001,0002,0003, 0004…

As I confirm the RawImageGuess extension module, only supports one raw image.  
We really need this function. please help us.

Thanks to the 3D Slicer development team.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [November 8, 2022, 6:06am UTC](https://discourse.slicer.org/t/multi-raw-image-loading-using-rawimageguess-extension/26126/2 "2022-11-08T06:06:10Z")

</div>

You mean, you have a sequence of raw images? If you know the xyz dimensions and voxel spacing, and data type (char, int, short etc), you can write a simple NRRD header to describe the data. I think something like this probably work. You need to replace the type and sizes with correct value.

```auto

NRRD0004
type: uchar 
dimension: 3
sizes: 1024 1024 240
encoding: raw
datafile: ./Slice0001
./Slice0002
./Slice0003

```

…

---

<div class="post-metadata">

**Author:** ![seyang](https://avatars.discourse-cdn.com/v4/letter/s/b38774/32.png) [@seyang](https://discourse.slicer.org/u/seyang)\
**Post date:** [November 11, 2022, 8:25am UTC](https://discourse.slicer.org/t/multi-raw-image-loading-using-rawimageguess-extension/26126/3 "2022-11-11T08:25:07Z")

</div>

Thanks muratmaga,

Yes it mean, i have a sequence of raw images.  
I know xyz dimensions and voxel spacing. but how to create the NRRD header?  
Could you please let me know?

I really need this method.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [November 11, 2022, 3:43pm UTC](https://discourse.slicer.org/t/multi-raw-image-loading-using-rawimageguess-extension/26126/4 "2022-11-11T15:43:39Z")

</div>

It is a simple text file that gets written. You can see the specification here. [https://teem.sourceforge.net/nrrd/format.html](https://teem.sourceforge.net/nrrd/format.html)

See the section specifically **3. Detached Headers with “data file:”**

---

<div class="post-metadata">

**Author:** ![seyang](https://avatars.discourse-cdn.com/v4/letter/s/b38774/32.png) [@seyang](https://discourse.slicer.org/u/seyang)\
**Post date:** [November 14, 2022, 12:47am UTC](https://discourse.slicer.org/t/multi-raw-image-loading-using-rawimageguess-extension/26126/5 "2022-11-14T00:47:20Z")

</div>

Hi Muratmaga.

Really thanks for your quick reply.  
I tried to make nrrd to refer your reply.  
But when i load the nrrd file, following error occurs.

Error: Loading D:/2022.09.29 CT/slice.nrrd - Failed to read node slice\_2 (vtkMRMLSequenceNode1) from filename=‘D:/2022.09.29 CT/slice.nrrd’

^ vtkMRMLVolumeArchetypeStorageNode::ReadDataInternal: Cannot read file as a volume of type Volume [fullName = D:/2022.09.29 CT/slice.nrrd]: FileFormatError. Number of files listed in the node = 0. File reader says it was able to read 1 files. File reader used the archetype file name of D:/2022.09.29 CT/slice.nrrd [reader 0th file name = D:/2022.09.29 CT/slice.nrrd].

[NRRD Format]  
NRRD0004  
type: uchar  
dimension: 3  
sizes: 1024 1024 240  
encoding: raw  
datafile: ./slice0000  
./slice0001  
./slice0002

Nrrd file is included in the same raw sequence folder.  
File name : slice0000 , slice0001 , slice0002 ,slice0003 ,slice0004

Is it have way to correct importing nrrd file?  
If this code is wrong, please make sample code for me?

I really helpful for your advice.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [November 14, 2022, 5:30pm UTC](https://discourse.slicer.org/t/multi-raw-image-loading-using-rawimageguess-extension/26126/6 "2022-11-14T17:30:58Z")

</div>

To be perfectly honest, I never tried building a nrrd header from sequence of images, but I know it is doable. Looking at the description of detached header more carefully, you may have to use the keyword LIST or define a filename formatting (min, max, increase). Try adding `LIST` right after data file or type

`datafile: "Slice%04d 0 max_number_slices 1 `

## 3. Detached Headers with “data file:”

Detached headers allow data stored in one or more separate files, with or without headers of another format, to be accessed by a NRRD header, leaving the original file(s) intact. The line skip and byte skip fields are especially useful for these cases. Detached headers are also very useful in situations where very large amounts of data are to be read or written with direct IO, a very fast method of IO in which the device driver transfers data directly between blocks on disk and user-space memory ([**nrrd**](https://teem.sourceforge.net/nrrd/index.html) currently supports direct IO on SGIs, via the [**air**](https://teem.sourceforge.net/air/index.html) library). Direct IO requires special alignment between the data segment beginning and the block boundaries on disk, which makes using attached headers rather inconvenient. Detached headers are also the simplest way to deal with NRRD readers which do not support the optional compressed encodings, since a stand-alone program (such as “gzip/gunzip” or “bzip2/bunzip2”) will be able to process the separate data file.

There is one new field specification which is required in detached headers, using the “data file” identifier. This field specification can take one of three possible forms (the second and third were copied from the MetaImage format).

> 1. data file: \<_filename_\>
> 2. data file: \<_format_\> \<_min_\> \<_max_\> \<_step_\> [\<_subdim_\>]
> 3. data file: LIST [\<_subdim_\>]

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 14, 2022, 8:37pm UTC](https://discourse.slicer.org/t/multi-raw-image-loading-using-rawimageguess-extension/26126/7 "2022-11-14T20:37:37Z")

</div>

@muratmaga what you described works well - see

> [@Import NRRD format](https://discourse.slicer.org/t/import-nrrd-format/26217/3):
>
> I’ve just tried this and it works flawlessly. I’ve used this MRHead.nhdr file: NRRD0004 # Complete NRRD file format specification at: # http://teem.sourceforge.net/nrrd/format.html type: unsigned short dimension: 3 space: left-posterior-superior sizes: 256 256 130 space directions: (0,1,0) (0,0,-1) (-1.2999954223632812,0,0) kinds: domain domain domain endian: little encoding: raw space origin: (86.644897460937486,-133.92860412597656,116.78569793701172) data file: MRHead%04d.raw 0 129 1 with f…

---

<div class="post-metadata">

**Author:** ![seyang](https://avatars.discourse-cdn.com/v4/letter/s/b38774/32.png) [@seyang](https://discourse.slicer.org/u/seyang)\
**Post date:** [November 15, 2022, 1:09am UTC](https://discourse.slicer.org/t/multi-raw-image-loading-using-rawimageguess-extension/26126/8 "2022-11-15T01:09:17Z")

</div>

Really Thanks for your support.
