Why is the number of voxels different from the number of matrices?

Hello everybody

I am working on making the volume data of the segmentation nrrd extension an Array List.

I have solved the method of creating an Array, but there is one question.

The size of the image I use is 501x501x500 and the total number of voxels is 125,500,500.

However, the total number of voxels produced by Array is about twice the output.

I wonder why.

I attached the code I used.


import numpy as np
volumeNode = getNode('Segmentation-label_1')
volumeArray = slicer.util.arrayFromVolume(volumeNode)
a = volumeArray

You retrieve the numpy array content correctly but then you write it out to file incorrectly (you write it as a byte array, and since each voxel is stored as int16, you get two numbers for each voxel). Writing out a 3D array as text file should be avoided (it takes about 100x more time to read and write, takes much more space than necessary, not clear how to interpret the data, no other software in the world would expect input data in that format, etc.). But if you really must do it then you need to flatten the array first and then write it out:

np.savetxt('C:\\tmp\\label8.txt', a.flatten(), fmt="%d")

But again, don’t do it. Instead, save the labelmap volume directly from the volume, in a standard file format, such as nrrd:

slicer.util.saveNode(volumeNode, "c:/tmp/labels.nrrd")

I have previously saved the volumeNode as an nrrd file, as you said. And I ran the above code.

Anyway I saved file using your method.

slicer.util.saveNode(volumeNode, "c:/tmp/labels.nrrd")

but if i using thins method i cannot get color method.

My ultimate goal is to:

I have two nrrd files, one nrrd file contains medical imaging information,
Another nrrd file contains only information from the Labelmap.
The first method combines the two nrrd files, the second method takes the coordinates of the Labelmap and tries to color the coordinates to another nrrd file.
For the second method, I have stored the labelmap as text and see if it is accessible.
Is there a way to combine two nrrd files in 3D Slicer?

You can save the input scalar image and the segmentation as two separate nrrd files. What software are you going to use to read/process these images?

I want to make Convolution Neural Network using nrrd file.

That’s why I want to combine the Segmentation File and the Original data File.

Do you mean you would like to mix the input image and ground truth segmentation into one image? This should not be necessary.

Umm… I don’t understand why not necessary.

I want to auto annotation software using deep learning. So i labeling in image’s some part.
if i make a deep learning model that time input file is patient’s nrrd file. reasult is annotation on image.
So i think to combine two files works necessary