numpy - Transform DICOM Image to a list of XYZ coordinates and their values - Python -


here trying accomplish in python (please keep in mind i'm relatively new python):

  1. convert dicom image list of xyz coordinates along respective pixel values , export list .csv file.
  2. regenerate same image list of xyz coordinates , pixel values generated in previous task.

so far, have been able read in dicom images , convert them array through use of pydicom , numpy. i've been able extract pixel , coordinate values through several loops , export list .csv. there has better way of doing maintain sort of quality control, because when try regenerate images (through use of set of loops), don't original image.

i need both functions run separately in different python scripts.

this have far:

    #raster through pixels , copy each value , coordinates arrays     rc_cntr = 0     r in range(0,img_rows):                 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 1 file             xyzv = numpy.column_stack([rarray,carray,zarray, imgarray])             numpy.savetxt(output_path,xyzv,'%0i','\t') #save xyzv files each image 

any on matter appreciated.

cheers afh

i not familiar dicom, looking @ pydicom docs think following should work:

import dicom import numpy np  ds = dicom.read_file('your_file.dcm') planes, rows, cols = ds.numberofframes, ds.columns, ds.rows image = ds.pixel_array # should have shape (planes, rows, cols)  # data , coords write csv image_data = image.ravel() z, y, x = np.meshgrid(np.arange(planes), np.arange(rows), np.arange(cols),                       indexing='ij').t  # write csv read image dicom file planes, rows, cols = np.ptp(z)+1, np.ptp(y)+1, np.ptp(x)+1 image = np.zeros((planes, rows, cols), dtype=image_data.dtype) image[z, y, x] = image_data  ds.numberofframes, ds.columns, ds.rows = planes, rows, cols ds.pixeldata = image.tostring() ds.save_as('another_file.dcm') 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -