Embedding specimen metadata into the 3D volume

Dear all,

As part of a project we will be converting large number of 3D high-resolution scans of biological specimens into volumetric format. Currently most of them are in DICOM or some sort of a image sequence, and we want to use something like NRRD to facilitate easier data exchange and increase usability of these data with 3D Slicer.

However, we also need to make sure we can trace the provenance of the dataset (museum specimen/accession number is the absolute minimum, and possibly few other tags, for example species designation or sex). I am hoping to have a better and more robust method than simply naming the volume with this number and keeping the metadata external. One idea was to use NRRD with a detached text header and keep some of this information as comments. But I am not sure what would happen to them if the user accidentally checkmarks the save option. Would this be retained? Are there other formats more suitable for our use case?

I appreciate any feedback.

NRRD0004
content: Skull CT
# Specimen No: 627546 
# Institution: USNM
# Genus: Homo
# Species: sapiens
# Specimen DOI/URL: where data is stored
dimension: 3
type: short
space: RAS
space directions: (0.5, 0, 0) (0, 0.5, 0) (0, 0, 1)
sizes: 512 512 256
data file: ./USNM627546_Skull_CT.raw.gz
encoding: gzip

Currently, you can only save custom metadata for a segment and not for the entire segmentation:

segmentationNode=slicer.mrmlScene.GetFirstNodeByClass('vtkMRMLSegmentationNode')
segmentationNode.GetSegmentation().GetNthSegment(0).SetTag("SomeCustomAttribute","This is a value")

It would be useful and should be quite easy to add custom tags/attributes in the segmentation object itself. @cpinter what do you think? Was there any particular reason why we did not implement this?

Thank Andras,
So would this this work only with Segment editor? Just to be clear, I am looking into something that I can embed in the volume file, and that these tags are read into Slicer when they are loaded into scene.

You can embed custom metadata in nrrd files, but you would need to write custom importer and exporter for that. We could implement reading/writing of all or some custom metadata fields into volume nodes, but in general metadata is not saved into volume files. Instead, these two approaches are often used:

Hi @muratmaga, can I ask what you ended up doing?

I am getting tired of working with 3 zillions dcm files from DICOM, but I don’t want to lose any metadata. The dream, I know.

I have explored, just a bit, storing the dicom metadata into nrrd files, with custom metadata fields, and it’s ok’eish. But I am curious about your experience after all this time. Thanks for any time you can spare!

I agree this is an issue for research imaging format. There is really no one-size fits all solution.

As explained by @lassoan custom NRRD headers, works only if you have custom reader/writers (e.g., if you open the NRRD with custom headers in other software and resave it for any reason, those fields are likely to disappear).

There are emerging formats there are more metadata rich, such aS ome-zarr, that will probably fill the gap between NRRD and DICOM, but their support is somewhat sketchy.

If this is for your own data archiving needs, and if you are using Slicer, probably a NRRD + CSV type of metadata of solution might be simplest for the time being. That way you won’t have the risk of loosing embded custom metadata, and csv’s are readily imported into Slicer as tables (you can even turn them into MRB as @lassoan suggested).

But it would be good to hear from others too.

1 Like

If you really don’t want to lose any DICOM metadata then the only option I can think of is to store the DICOM instance UIDs in the NRRD file and look up the required metadata from the original DICOM files as needed. DICOM files store a database of complex, hierarchical, interlinked data objects. Even if you save some attributes of some objects somewhere, there is no way you can preserve all data stored in this complex database. Even ome-zarr will not preserve all DICOM metadata. There is an emerging DICOM standard for lossless storage of instances in JSON format, but that is an extremely complex and unfriendly data structure that would be almost as hard to use as binary DICOM (e.g., you cannot simply use json objects to store attributes, because order of attributes matters in DICOM and json objects don’t support attribute ordering).

If you just want to store some custom metadata fields in your files for convenience (which you know you need for a specific analysis), you could store them as custom metadata fields in the NRRD file. However, as @muratmaga warned you, you’ll have to be careful with what tools you use to process these NRRD files, as custom fields may not preserved when you load, modify, and save an image. I’m not sure if we preserve all custom metadata fields for NRRD files in Slicer now. It would not be hard to implement, if it is not implemented already.

1 Like