RuntimeError: The following handlers are available to decode the pixel data however they are missing required dependencies: GDCM (req. GDCM)

Viewed 4278

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
1 Answers

!conda install -c conda-forge gdcm -y

import gdcm

Related