I'm trying to write pixel_array data and patientID from multiple Dicom files to a CSV.
The pixel arrays, which are np arrays get saved like this;
[[0 0 0 ... 0 0 0]\n [0 0 0 ... 0 0 0]\n [0 0 0 ... 0 0 0]\n ...\n [0 0 0 ... 0 0 0]\n [0 0 0 ... 0 0 0]\n [0 0 0 ... 0 0 0]]
how do I get back the original np array?
if you could pls give me some advice on writing these properly to CSV so the np arrays are preserved as they are? Below is the loop
def tryer(a, b):
if b == 'pixel_array':
return(a.pixel_array)
else:
try:
return(getattr(a, b))
except AttributeError:
return('No')
tryer is as defined above;
a_list = ['PatientID', 'pixel_array']
with open('imgs_n_patied_train1.csv', 'w', newline = '') as f:
thewriter = writer(f)
thewriter.writerow(['PatientID', 'pixel_array\n'])
for i in imgs:
#iterating through each file and writing all the metadata to a csv row-wise
a = dicom.read_file(r'pathto\stage_2_train_images' + '\\' + i, force = True)
app = []
for j in a_list:
app.append(tryy.tryer(a, j))
thewriter.writerow(app)