How to Run Dicom2raw.py

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How to Run Dicom2raw.py

blue
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
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers