Export segmentation as bin file

Hello everyone, I hope that you are doing fine in these hard times?

I have a question regarding segmentation export.
Is there any way to export segmentation or even whole study DICOM data without segmentation (CT or MR) as bin (binary) file that could be later on imported in Monte Carlo N Particle Transport Code (MCNP)?

Stay safe and receive my best regards,
Vjekoslav.

I believe we have a complete set of import/export tools for EGSnrc Monte Carlo engine. I’ve found Dosxyz NRC 3D dose file reader in SlicerRT extension but did not find others. @cpinter can you give more information on this?

Regardless of this, you can always export the segmentation to a labelmap volume then access voxels as numpy array (slicer.util.arrayFromVolume) and write it to any custom file format using a few lines of Python code.

Dear @lassoan,
Thank you for your reply. I have installed SlicerRT but can’t find the mentioned Dosxyz extension or manuals for the rest of the applications in Radiotherapy section.

Since I am no expert at python and coding, is there another approach to the problem (regarding to second part of your answer)?

In SlicerRT we indeed support a complete DOSXYZnrc workflow. For example, this is the call from python to the ctcreate utility that saves the CT data in a format that DOSXYZ can read. You don’t need to be an expert to understand this code, as a matter of fact, I don’t consider myself a python expert either, although I wrote much of this.

Probably the MCNP toolkit you use has different file formats. If you have the specification, then you should be able to figure out how to read/write the formats it uses. This is how we did it for DOSXYZnrc, although it has really good documentation.

Thank you for your reply @cpinter. Actually, I don’t know any of coding and since I am in medical filed, this whole thing is really new to me :). I’ll have to find someone who could help me with that.
As I have already made the whole model (stl file), combining two persons DICOM data, and is it possible to run this script on that model? I presume that I have to import it back in Slicer and run it from there?

Regarding specifications for binary file, my collegue imports it in software manually or copy/paste :smiley: (but for whole body it would be too much I think). I have example data that I open in note (it is classical bin data as I’ve been said, as seen in pic). I hope that I could get same thing when import my model in Slicer.

Best regards, Vjekoslav.

Reading in this file in Slicer would not be hard it seems. There are many examples for such a reader, like the one @lassoan referred to. If you check out the differences between the two file formats and modify the code according to the few differences, then it should be really easy to have a working reader in Slicer.
If either you or a colleague of yours takes on this challenge, we will be happy to help you. Or if you have funding, you can find paid services around here to do such things.

There are many things I don’t understand in your question. I am not familiar with the MCNP toolkit, its capabilities, or your workflow. If you describe your steps (and the input/output of each step) in detail, then we could give some pointers.

I segmented neck, thorax, abdomen and pelvis from one person, but didn’t have whole head… Then, I segmented head (brain, skull, eyes) of another person. In 3d modeling software i combined these two and made one whole model of head, neck, thorax, abdomen and pelvis. Is it possible to import that whole body model (stl file) to 3D slicer and then try to export it as binary file that would be then imported in Monte Carlo simulation?

I suggest against this heterogeneic approach. STL files do not explicitly contain information about the coordinate system, so depending on the method of saving the file in your chosen application, they may appear on top of each other. In either case (appear correctly vs need to manually align) you can convert the STL models easily into 3D volumes (i.e. labelmaps) in the Segmentations module (you can find lots of information about this in the documentation and this forum).

Once you have the labelmap you will need the exporter above so that you have the desired binary file format.

That is what I thought, import it as labelmap, that shouldn’t be a problem.
The exporter that you mention, is it DOSXYZ? This next steps are confusing to me and that is the main problem :confused:

The exporter I mean is for the MCNP toolkit you use and it does not exist yet, it needs to be created. The DOSXYZ exporter can be a good starting point and serve as a sample. It is a programming task to create this exporter, and it is not hard at all, just read the existing code, and change what is different. Here on this forum we do not offer free programming services, but can help you go along the way.

Hello guys, it’s me, again :frowning:
I need help, again.
So, I manage to import stl files of different organs in 3d slicer and when I try to save all of them as segmentation (.nrrd file) message pops up saying “Exception trown in event: Bad allocation”

Few days ago I manage to do same but only with few organ stl files and it worked just fine…
What could be the problem?


Operating system: Windows 10 Home, 64 bit
Intel core i7-7700 2.8GHz
16GB RAM
I am using 4.10.2 version od 3D slicer.

“Bad allocation” means you’ve run out of memory. Makes sense that it works for small data but not past a certain size. You should be able to either add real or virtual memory to your computer.

Also you could try the newer Slicer versions, but that may not help in this case.

As I thought so… Thank you.

3 posts were split to a new topic: Viewers do not appear in OpenStack

hmmm, when I import all desired organs in slicer 11 and want to save as nrrd file (segmentation) it succeeds, but when I want to perform same process with slicer 10, it says not enough memory (as earlier)… why is that happening when everything is the same regarding computing power?

Slicer-4.11 is hugely improved compared to Slicer-4.10, including optimized memory management for segmentations. In some cases (when you have hundreds of non-overlapping segments in a segmentation) then memory usage and computation times may be decreased by a factor of 10-100x in Slicer-4.11.

Thank you for your reply.
I just need to figure out why I can export 11 organ segmentation flawlessly into the third application, but when I have 24 organ segmentation in the same app it appears only as part of the body (part of the abdomen) and magnified.
Not sure, but could it be due to memory again? We should get access to more memory usage in that other computer and will know if that is a cause. :crossed_fingers: :crossed_fingers:

It may be because you run out of memory, or it may be due to one of those hundreds of small issues that have been fixed since Slicer-4.10.