Segmentation image size

When I generate a binary mask, using the 3D slicer segmentation tool, and I save it as a .nrrd file, the dimensions of the created image (mask) is not similar to the original image.
How could I generate a binary mask with the same dimension as the original image?

From my experience, the way segmentations are saved is with the minimum bounding area around the actual binary mask itself. This is because you can save many many segmentations and saves image space when writing out. If you have an image thats size 512x512x400 and then save those files out that takes up a lot of memory.

The .seg.nrrd file that is created has a reference called Segment_Extent, that contains the bounding Indices for the region where the segmented/masked location is.

To create the mask images themselves, I read this .seg.nrrd file into MATLAB, as well as the initial image. You can save the header data from the .seg.nrrd file to a matrix/table and then find that Segment_Extent variable, and then use the starting indices to insert the smaller image into one of proper size.

You could also do the same thing using c++ and ITK instead of matlab

example
Segment1_Extent:=73 208 25 173 29 122
this formatting for the variable is in XYZ in pairs, so the location of the segmentation in reference is
xmin/xmax = {73,208}
ymin/ymax = {25,173}
zmin/zmax = {29,122}

  1. read in image and .seg.nrrd file
  2. create image the size of the original of all zeros
  3. find Segment_extent indices
  4. loop through segmentation image, and insert those values into the image starting at the Segment_Extent Indices
  5. write out that final matrix/table as a .nrrd file

I know its inefficient, but just looping through the segmentation and inserting their values starting at the index of an image that was already the size of the original is what worked for me.

If you use Export/import models and labelmaps it saves the binary labelmap as nrrd. In my experience it has the same size as the master volume (tested with v4.10.2)

1 Like

When you export to labelmap in Segmentations module, you can specify a reference volume (in Advanced section). The labelmap will have the same size, resolution, etc. as the reference volume. By default the reference volume is the volume that was used to initialize the segmentation geometry

@Sunderlandkyl Since in Slicer-4.11 we don’t store each segment in a separate volume, the overhead of saving empty areas should not be a significant in most cases. What do you think about adding an option to switch between using the reference geometry extent / minimum necessary extent (by default use reference geometry extent) to the segmentation storage node?

Makes sense to me. Should this option be added to the save dialog as well?

Exposing this on the GUI is probably not essential, but it would be nice (and since these options are not shown by default, it would not make the GUI look more complicated).