Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Python Extracting 2d array from numpy.pixel_array dicom image

  1. Aug 22, 2016 #1
    Hi guys,

    I have a dicom image from a QC spect acquisition.
    reading the file in with dicom.read_file and pulling pixel data using numpy.pixel_array gives array of shape [2, 1024, 1024]

    The 2 represents two images, one from each detector head on the spect scanner and the 1024x1024 are the arrays i want to separate and pull out individually, i.e. so i can manipulate the pixel data, remove buffering 0's, plot histograms of the pixel values etc etc. i have artifacts in one detector head so i need to be able to separate the two slices

    looking at numpy package there are ways to "slice" my array but the orientations are confusing and it doesnt seperate them into their own arrays.

    This should be quite elementary i would of thought

  2. jcsd
  3. Aug 22, 2016 #2
    so it looks like its this easy..

    'array' is my array of shape [2,1024,1024]

    to get the two 1024x1024 arrays out is simply

    1stArray = array[0] and 2ndArray = array[1]
    ill know for sure when i map them
  4. Aug 23, 2016 #3
    Yes, it is correct though it doesn't look intuitive. :smile:
    In C++, I would probably use i.e a tuple then tie its values to declared variables. Other than that I might use a struct of e.g 3 elements to store the returned values. You can do the same to make more sense of your current approach.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted