7

I want to convert the dcm file into a png file. However, the following error occurred: RuntimeError: The following handlers are available to decode the pixel data however they are missing required dependencies: GDCM (req. GDCM)

import cv2
import os
import pydicom

inputdir = 'C:\\data1\\'
outdir = 'C:\\data\\'
#os.mkdir(outdir)

test_list = [ f for f in  os.listdir(inputdir)]

for f in test_list:   # remove "[:10]" to convert all images
    ds = pydicom.read_file(inputdir + f) # read dicom image
    img = ds.pixel_array # get image array
    cv2.imwrite(outdir + f.replace('.dcm','.png'),img) # write png image
dayday
  • 65
  • 2
  • 7
  • Possible duplicate of [PyDICOM can't read pixel data and needs GDCM or Pillow](https://stackoverflow.com/questions/54657768/pydicom-cant-read-pixel-data-and-needs-gdcm-or-pillow) – Georgy Jul 01 '19 at 10:53

1 Answers1

0

!conda install -c conda-forge gdcm -y

import gdcm