Can PsychoPy import DICOMM images?

The documentation indicates that PsychoPy can import “most image formats”, but doesn’t specify which formats. Can PsychoPy import DICOMM images?

I think PsychoPy uses the Python Image Library (PIL) for importing images, and a list of the formats is here:
http://pillow.readthedocs.io/en/3.4.x/handbook/image-file-formats.html

DICOM is a bit too specialised for that, so you’d need to import another library especially for that purpose. Look into the nipy project http://nipype.readthedocs.io/en/latest/interfaces/generated/nipype.interfaces.dcm2nii.html or other libraries particularly for that purpose, e.g. pydicom http://pydicom.readthedocs.io/en/stable/getting_started.html

1 Like

Thanks for the links. pydicom looks like it might work.
Every answer, of course, raises two more questions!

  1. I’m having trouble getting PsychoPy to recognize the pydicom module. I installed pydicom and tested it out on my standard Python 2.7 environment. Then I added the path ([‘C:\Python27\Lib\site-packages\dicom’]) to PsychoPy Preferences/General/paths. But when I try to import it via PsychoPy, I get a “No module named dicom” error.What am I doing wrong here?

  2. Once I get the pydicom module to work, how to I get the pixel information into a psychopy.visual function? psychopy.visual.ImageStim assumes you are reading a file, but I’m going to read in the dicom image via dicom.read_file, then extract the pixel_array. Which psychopy.visual function takes pixel arrays?

Depending on the contents of the image and the fidelity requirements, you can pre-convert them using ImageMagick https://www.imagemagick.org/

Hello,

Once I get the pydicom module to work, how to I get the pixel information into a psychopy.visual function? psychopy.visual.ImageStim assumes you are reading a file, but I’m going to read in the dicom image via dicom.read_file, then extract the pixel_array. Which psychopy.visual function takes pixel arrays?

You can pass numpy arrays to ImageStim using the ‘image’ argument. It’s knows what to do based on the data type it receives.