question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implement `NrrdReader` for `nrrd` and `seg.nrrd` files

See original GitHub issue

Is your feature request related to a problem? Please describe. For one project we are working with seg.nrrd files to create pixelwise segmentations. However, when trying to load these files with LoadImaged I get the following error:

TemplateTypeError: itk.Image is not wrapped for input type `itk.Vector[itk.SS,3], int`.

To limit the size of the package, only a limited number of
types are available in ITK Python. To print the supported
types, run the following command in your python environment:

    itk.Image.GetTypes()

Possible solutions:
* If you are an application user:
** Convert your input image into a supported format (see below).
** Contact developer to report the issue.
* If you are an application developer, force input images to be
loaded in a supported pixel type.

    e.g.: instance = itk.Image[itk.RGBPixel[itk.UC], int].New(my_input)

* (Advanced) If you are an application developer, build ITK Python yourself and
turned to `ON` the corresponding CMake option to wrap the pixel type or image
dimension you need. When configuring ITK with CMake, you can set
`ITK_WRAP_${type}` (replace ${type} with appropriate pixel type such as
`double`). If you need to support images with 4 or 5 dimensions, you can add
these dimensions to the list of dimensions in the CMake variable
`ITK_WRAP_IMAGE_DIMS`.

Describe the solution you’d like When reading seg.nrrd files with pynrrd the files are handled correctly. I would thus propose to implement a NrrdReader based on pynrrd. I have already written the NrrdReader for private use and would be happy to make a PR.

Describe alternatives you’ve considered I have iterated through all supported pixel types, but this either raises an error or leads to incorrect import of the images. For example, some images have format [4, H, W, 1]. When forcing pixel type to itk.Image[itk.RGBPixel[itk.UC], int], the image is read as [3, H, W, 1], thus omitting a layer. This is a problem, as the number of layers in the different seg.nrrd files varies.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
lassoancommented, May 13, 2022

The main advantage of using standard coded entries for describing what is in a segment because then you don’t need to hardcode across your data set that label value 2 means liver and label value 3 means tumor. These label values can only be used in a single data set because these arbitrary label values are chosen differently in each project. In contrast, if you specify that there is a (SCT, 10200004, 'Liver') and a (SCT, 4147007, 'Mass') segment in the segmentation then this information is remains valid forever, in every context. This is the same way how DICOM specifies what is in a segmentation.

DICOM recommends using SNOMED Clinical Terms (and you are granted free license to use all the terms that are part of the DICOM standard). You can find a list of codes that the DCMQI project assembled here: https://github.com/QIICR/dcmqi/blob/ac7d0fea3a4458a2e14bae0bac886813051b6ad4/doc/segContexts/SegmentationCategoryTypeModifier-SlicerGeneralAnatomy.json#L903-L918

You can find more details in this paper: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5675033/

1reaction
wylicommented, May 11, 2022

I see, I think an NrrdReader might be useful here, please send a pull request…

CC @lassoan @thewtex in case they have better ideas about pixel_type in itk.imread in this case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Interpreting segmentation nrrd files - 3D Slicer Community
I am segmenting prostates with Slicer and now I want to post-process my segmentations. So I read the nrrd segmentation files with my...
Read more >
Definition of NRRD File Format - Teem - SourceForge
This document defines the NRRD file format. It has been updated to reflect the latest version of the format, supported by Teem version...
Read more >
NRRD Format File Reader - File Exchange - MATLAB Central
Read volumetric data from the NRRD (.nrrd) medical imagery file format. This function returns the image volume and all of the metadata stored...
Read more >
pynrrd - PyPI
pynrrd. pynrrd is a pure-Python module for reading and writing NRRD files into and from numpy arrays. Requirements. numpy. nptyping. typing_extensions.
Read more >
Writing a nrrd segmentation file in SimpleITK - Engineering - ITK
Then you just load this image and overlay onto the original (I usually use ITK-SNAP for quick visualizations as it loads faster than...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found