0

I'm reading a dicom image and accessing its pixel array. After that saving that array again into dicom format using sitk.Write but there is different between original image that is going to be read and same image after being written. How can I get the same image display. I'm using Radiant Viewer for visualization of Dicom images. I want same output as of input. Code along with input and out image is given below:

# Reading a dicom image
Image = pydicom.dcmread('Input.dcm')
output = Image.pixel_array

#Saving the image into another folder
img = sitk.GetImageFromArray(output)
sitk.WriteImage(img, 'output.dcm' )

Size of dicom image is greater so sending the screenshots of input1 and output2 image

Amit Joshi
  • 15,448
  • 21
  • 77
  • 141
  • It looks like you're going through a numpy array to do the conversion. In the process you would lose any meta data associated with the DICOM image. – Dave Chen Sep 02 '20 at 18:22
  • This looks like the image is in MONOCHROME1, e.g. inverted. Generally, if you want to see the same image, you have to apply the LUT from the DICOM values, see for example [this answer](https://stackoverflow.com/a/62843353/12480730). – MrBean Bremen Sep 02 '20 at 19:11
  • after applying LUT as in https://stackoverflow.com/a/62843353/12480730, getting error Traceback (most recent call last): sitk.WriteImage(img, os.path.join(path ,image_names[i] + '.dcm' )) itk::ERROR: GDCMImageIO(000001CF226F6BA0): A Floating point buffer was passed but the stored pixel type was not specified.This is currently not supported – Hachughtai97 Sep 03 '20 at 12:27
  • It can't write a Float32 DICOM. You need to convert it to Int16 or some other supported pixel format. Use sitk.Cast to cast it to another pixel type. – Dave Chen Sep 03 '20 at 12:36
  • Thank you for giving time. i've done "dataset.pixel_array.astype('Int16')"and Int8 and Int64 but getting same error. code is : dataset = pydicom.dcmread(file_path) output = dataset.pixel_array.astype('Int64') output = apply_modality_lut(output, dataset) output = apply_voi_lut(output, dataset, index=0) – Hachughtai97 Sep 03 '20 at 12:44

1 Answers1

0

I'm gonna answer my own question here. So, the Photometric Interpretation of my original image was MONOCHROME1. But after converting the image into pixel arrays and then saving again with .dcm format, its some details were changed one of which was Photometric Interpretation that changed from MONOCHROME1 to MONOCHROME2. I changed this of the saved image and then saved again as follows.

elem = image[0x0028, 0x0004]
elem.value = 'MONOCHROME1'
image.save_as('P1_L_CC.dcm',write_like_original=False)