Saved dicom to nii with saveNode, changes range of intensities and image volume

Hi,
I load a dicom series and save it as nrrd like this:

img_node = DiskSimulator.load_image(img_dcm_dir, iid)
slicer.util.saveNode(img_node, os.path.join(self.imgs_nii_dir, iid, f"{iid}.nii.gz"))

where load_image method is defined as bellow:

def load_image(img_dicom_path, img_node_name):
      originalDicomPlugins = slicer.modules.dicomPlugins
      slicer.modules.dicomPlugins = {'DICOMScalarVolumePlugin': originalDicomPlugins['DICOMScalarVolumePlugin']}
      loadedNodeIDs = []
      with DICOMUtils.TemporaryDICOMDatabase() as db:
          DICOMUtils.importDicom(img_dicom_path, db)
          patientUIDs = db.patients()
          for patientUID in patientUIDs:
              loadedNodeIDs.extend(DICOMUtils.loadPatientByUID(patientUID))
      volumeNode = slicer.mrmlScene.GetNodeByID(loadedNodeIDs[0])
      volumeNode.SetName(img_node_name)
      slicer.modules.dicomPlugins = originalDicomPlugins
      slicer.app.applicationLogic().GetInteractionNode().SetCurrentInteractionMode(slicer.vtkMRMLInteractionNode.AdjustWindowLevel)
      return volumeNode

but when I open dicom image and nii image I see the intensity ranges and volume has some differences.

Here I attach a more detailed statistics of the two images loaded in MevisLab:

I was wondering where the difference comes from? and how can I make them the same.

  • I see the nii image is saved as integer data while dicom serie has been unsigned integer data
  • Especially in the side by side view it seems like even they are not registered, as they show different views in the same slice

Best regards,
Saeed

You have only saved the first loaded node (loadedNodeIDs[0]) of the first patient in the database. Probably it was a different image than what you loaded manually. You can save all the loaded nodes (instead of just the first one) and then you’ll probably find the corresponding volumes.

Thanks Andras, I believe that’s not the case, since I printed the length of loadedNodeIDs, it just has one element in it, which is what I saved.
So I checked with exporting the loaded DICOM node in slicer UI by right clicking and “export to DICOM”.

when I check the exported DICOM serie with the input DICOM serie, the image data is different. I think the reason should lie in “export type” (above screenshot)? that’s the only place I see can make difference.

these are statistics of loaded DICOM serie and exported DICOM serie. I’m wondering what’s makes the difference? how can I avoid it?

You created a new topic for this, so let’s stop the discussion here and continue it there: