Extracting 2d array from numpy.pixel_array dicom image

  • Context: Python 
  • Thread starter Thread starter ProPatto16
  • Start date Start date
  • Tags Tags
    2d Array Image
Click For Summary
SUMMARY

The discussion focuses on extracting 2D arrays from a DICOM image using the Python libraries `dicom` and `numpy`. The pixel data is accessed through `numpy.pixel_array`, resulting in an array of shape [2, 1024, 1024], where the first dimension represents two images from different detector heads. Users can separate these images into individual 1024x1024 arrays by indexing: `1stArray = array[0]` and `2ndArray = array[1]`. This method allows for further manipulation of pixel data, such as removing artifacts and plotting histograms.

PREREQUISITES
  • Familiarity with Python programming
  • Understanding of DICOM file format and its structure
  • Knowledge of the `numpy` library for array manipulation
  • Basic experience with image processing techniques
NEXT STEPS
  • Explore advanced `numpy` slicing techniques for multidimensional arrays
  • Learn about DICOM file handling with the `pydicom` library
  • Investigate methods for histogram plotting using `matplotlib`
  • Research artifact removal techniques in medical imaging
USEFUL FOR

This discussion is beneficial for data scientists, medical imaging professionals, and Python developers working with DICOM images and seeking to manipulate pixel data effectively.

ProPatto16
Messages
323
Reaction score
0
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 doesn't separate them into their own arrays.

This should be quite elementary i would of thought

Thanks
 
Technology news on Phys.org
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
 
ProPatto16 said:
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]
..
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.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
4K
Replies
22
Views
7K
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
Replies
4
Views
5K
  • · Replies 41 ·
2
Replies
41
Views
6K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 7 ·
Replies
7
Views
6K
  • · Replies 2 ·
Replies
2
Views
7K