# Visualize tracked ultrasound in 3D with PNG images and pose matrices

**URL:** <https://discourse.slicer.org/t/visualize-tracked-ultrasound-in-3d-with-png-images-and-pose-matrices/33096>\
**Category:** Support\
**Tags:** sequences, ultrasound, slicerigt\
**Created:** [November 28, 2023, 7:42pm UTC](https://discourse.slicer.org/t/visualize-tracked-ultrasound-in-3d-with-png-images-and-pose-matrices/33096 "2023-11-28T19:42:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ziri](https://avatars.discourse-cdn.com/v4/letter/z/54ee81/32.png) [@ziri](https://discourse.slicer.org/u/ziri)\
**Post date:** [November 28, 2023, 7:42pm UTC](https://discourse.slicer.org/t/visualize-tracked-ultrasound-in-3d-with-png-images-and-pose-matrices/33096/1 "2023-11-28T19:42:16Z")

</div>

Hi, I’m trying to create a sequence file from a folder of ultrasound images in png format with poses stored in a csv file and then visualize in 3D.  
I successfully created the .mhd header file containing the pose information and the poses can be visualized in Slicer. The file “Scan1.seq.mhd” looks like below:

> ObjectType = Image  
> NDims = 3  
> AnatomicalOrientation = RAI  
> BinaryData = True  
> BinaryDataByteOrderMSB = False  
> CenterOfRotation = 0 0 0  
> CompressedData = False  
> ElementSpacing = 1 1 1  
> Offset = 0 0 0  
> TransformMatrix = 1 0 0 0 1 0 0 0 1  
> UltrasoundImageOrientation = MFA  
> UltrasoundImageType = BRIGHTNESS  
> Seq\_Frame0000\_ImageToReferenceTransform = 0.25880223 -0.96586309 0.01139754 99.35319738 -0.00294990 0.01100917 0.99993505 19.23409344 -0.96592583 -0.25881905 0.00000000 4.28620653 0.00000000 0.00000000 0.00000000 1.00000000  
> Seq\_Frame0000\_ImageToReferenceTransformStatus = OK  
> Seq\_Frame0000\_Timestamp = 0.000  
> Seq\_Frame0000\_ImageStatus = OK  
> Seq\_Frame0001\_ImageToReferenceTransform = 0.25868718 -0.96543371 0.03191713 99.30936271 -0.00826076 0.03082958 0.99949052 18.11578949 -0.96592583 -0.25881905 0.00000000 4.28620653 0.00000000 0.00000000 0.00000000 1.00000000  
> Seq\_Frame0001\_ImageToReferenceTransformStatus = OK  
> Seq\_Frame0001\_Timestamp = 0.300  
> Seq\_Frame0001\_ImageStatus = OK  
> Seq\_Frame0002\_ImageToReferenceTransform = 0.25844698 -0.96453726 0.05360077 99.21784580 -0.01387290 0.05177437 0.99856245 16.90844963 -0.96592583 -0.25881905 -0.00000000 4.28620653 0.00000000 0.00000000 0.00000000 1.00000000  
> Seq\_Frame0002\_ImageToReferenceTransformStatus = OK  
> Seq\_Frame0002\_Timestamp = 0.600  
> Seq\_Frame0002\_ImageStatus = OK  
> Seq\_Frame0003\_ImageToReferenceTransform = 0.25810672 -0.96326738 0.07414098 99.08820620 -0.01918910 0.07161468 0.99724777 15.78648773 -0.96592583 -0.25881905 -0.00000000 4.28620653 0.00000000 0.00000000 0.00000000 1.00000000  
> Seq\_Frame0003\_ImageToReferenceTransformStatus = OK  
> Seq\_Frame0003\_Timestamp = 0.900  
> Seq\_Frame0003\_ImageStatus = OK  
> …  
> ElementDataFile = Scan1.seq.nrrd

However, when I load this file into slicer as Sequence Metafile, it cannot pull the image data into the Slicer even though the Scan1.seq.nrrd file is under same directory as the .mhd metafile. I created the “Scan1.seq.nrrd” by opening the folder containing png images in slicer as volume, and save it as .nrrd file. I wonder if I should convert the png images into raw data file in a different way?

Also I wonder if I should set the ultrasound image spacing parameter in .mhd file? E.g., if my pixel spacing is 0.27mm, should I change the ElementSpacing = 0.27 0.27 0.27?

I appreciate any help!

---

<div class="post-metadata">

**Author:** ![ziri](https://avatars.discourse-cdn.com/v4/letter/z/54ee81/32.png) [@ziri](https://discourse.slicer.org/u/ziri)\
**Post date:** [November 29, 2023, 3:39am UTC](https://discourse.slicer.org/t/visualize-tracked-ultrasound-in-3d-with-png-images-and-pose-matrices/33096/2 "2023-11-29T03:39:55Z")

</div>

Update: I’m still struggling on creating the sequence file correctly, but here is what I have tried so far

**Attempt 1: Using the MultiVolume Importer**  
I tried to use the MultiVolume Importer to open the folder containing my png ultrasound images, and save the MultiVolume node as an nrrd file. Then I load the file in Slicer as Sequence, the result looks good (as shown below).

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/3/4/347ca644958d32922db5cc5ecab0419ef4f4d86e.png)

However, if I tried to load the [nrrd file](https://www.dropbox.com/scl/fi/9mlukkkel6d5hfd0676tz/Scan1.seq.nrrd?rlkey=j4fd3rxueam21z95jfr4nwhza&dl=0) (contains all my images) with my custom [mhd file](https://www.dropbox.com/scl/fi/35cnf9fdtpbn5vtoc5ir6/Scan1.seq.mhd?rlkey=6qlu189ofmgont9b14tk5ygdr&dl=0), it will not show the data at all. I’m attaching both files in the links.  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/a/fa20db6079c61c1b25f1a65e774e7a1e4a2b7960.png)

If I open up the nrrd file in text editor, I see it actually contains a header saying the dimension is 4, which violates the [Sequence file rule](http://perk-software.cs.queensu.ca/plus/doc/nightly/user/FileSequenceFile.html) of NDims=3.  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/e/4eeb48537a207f2a49e8a9e2ad0299168c4cbc0a.png)

**Attempt 2: Creating binary file using numpy array**  
So I tried to read every image into python and generate the numpy array (dtype=uint8) with size 660 x 616 x 417 (width x height x frames), then save the array into binary file and try to load it with the mhd file again. This time it shows noisy data which looks confusing.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/9/b9d2f3ca0622e209d2c14ab19092138684c1e54c.png)

Can I get any advice on creating a custom sequence file from stored images? Thank you in advance!
