Convert NRRD to DICOM using itk.js

I am trying to make NRRD files viewable in OHIF’s Local Viewer.

So far, I have used itk.js’s readImageFile method to take NRRD files as input. Now I’d like to output the given file as a DICOM file, which will then be supplied to the OHIF Viewer. But I am not sure how to convert the NRRD file to DICOM using itk.js

Thanks for any advice you can offer

I’m not positive that itk.js has DICOM writers enabled currently. I will let @thewtex comment on this.

You can create part10 dcm files with dcmjs. See examples GitHub - dcmjs-org/dcmjs-examples: Examples for learning dcmjs and this code:

1 Like

Hi Steve,

Thanks for the response. I tried implementing your suggestion, but I don’t believe I have the data required to implement it. this is the data from the NRRD file I receive after read the image using ITK:

{
image:
  data: Float32Array(10944512) [...]
  direction: {...}
  imageType: {...}
  name: "Image"
  origin: (3) [...]
  size: (3) [...]
  spacing: (3) [...]
}

I’m having trouble seeing how I am supposed to use this data with the code you linked.

Thanks for any advice you or others can offer.

Right, if you start with NRRD format data you typically don’t have the information to make a full dicom file. Maybe the information was there originally but was thrown away when converting to NRRD. In this case you can either try to find the data from some other source or you can leave it out (or put in placeholders). A lot depends on how you want to use the dicom version. If you just need it to have the right geometry and pixel values you can work with just the NRRD data. If you need it to be valid dicom and match up with other data in a PACS or navigation system then you need to find things like StudyUID and PatientID.

That makes sense. In my case, I am attempting to upload a nrrd file to orthanc, and as far as I know it needs to be a DICOM file in order to do that

I have been taking your advice and using dcmjs to create a DICOM file and putting in placeholders for where I am missing information.

I wanted to ask you if you happened to know the DICOM tag which I should place my
data: Float32Array(10944512) [...] inside of.

Thank you for any information you may be able to offer.

Unfortunately the dicom standard doesn’t allow floating point data in any of the standard modality types. You need to use a parametric map for that if you really need floating point. Not many systems support parametric maps though, so even if that is technically correct it’s not very interoperable.

If you goal is to have dicom files that display in other systems then you are better off casting to 16 bit (or 12) and if needed using the RescaleSlope and RescaleIntercept to provide a linear mapping back to the original floating point values.