Here is what I am trying to accomplish in Python (please keep in mind that I'm relatively new to Python):
- Convert a DICOM image into a list of xyz coordinates along with their respective pixel values and export the list to a .csv file.
- Regenerate the same image from the list of xyz coordinates and pixel values generated in the previous task.
So far, I have been able to read in the dicom images and convert them into an array through the use of pydicom and numpy. I've also been able to extract pixel and coordinate values through several for loops and export that list as a .csv. But there has to be a better way of doing this to maintain some sort of quality control, because when I try to regenerate the images (through the use of another set of for loops), I don't get the original image.
I need both functions to run separately in different python scripts.
This is what I have so far:
#Raster through all pixels and copy each value and coordinates to arrays
rc_cntr = 0
for r in range(0,img_rows):
for c in range(0,img_cols):
pixel = dcmarray[r, c]
rArray[rc_cntr] = r
cArray[rc_cntr] = c
zArray[rc_cntr] = z_cntr
imgArray[rc_cntr] = dcmarray[r,c]
rc_cntr = rc_cntr + 1;
#Combine arrays into one file
XYZV = numpy.column_stack([rArray,cArray,zArray, imgArray])
numpy.savetxt(output_path,XYZV,'%0i','\t') #Save XYZV files for each image
Any help on this matter would be greatly appreciated.
Cheers AFH