[vtkusers] How to Run Dicom2raw.py

blue ustungozde at gmail.com
Mon Jul 2 16:35:47 EDT 2018


Hello;
I found this code in github :
import dicom
import os
import numpy
import sys

dicomPath = "./../nn/"
lstFilesDCM = []  # create an empty list
for dirName, subdirList, fileList in os.walk(dicomPath): # file name should
be ordered correctly
    allInOne = ""

    for filename in fileList:
        if "".join(filename).endswith((".dcm", ".DCM")): # check whether the
file's DICOM
            path = dicomPath + "".join(filename)
            dataset = dicom.read_file(path)

            for n,val in enumerate(dataset.pixel_array.flat): 
                dataset.pixel_array.flat[n] = val / 60
                if val < 0:
                    dataset.pixel_array.flat[n] = 0
                    
            dataset.PixelData = numpy.uint8(dataset.pixel_array).tostring()
# convert int16 to int8
            allInOne += dataset.PixelData
            print "slice " + "".join(filename) + " done"

    newFile = open("./all_in_one.raw", "wb")
    newFile.write(allInOne)
    newFile.close()

    print "RAW file generated"

But I can not run this code How it is work 



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html


More information about the vtkusers mailing list