loli / medpy

Medical image processing in Python
http://loli.github.io/medpy/
GNU General Public License v3.0
571 stars 138 forks source link

dicom data cannot be read #3

Closed amastm closed 10 years ago

amastm commented 10 years ago

/share/data_bert1/mwilms/Projects/RTUKE/Patient01/4DCT$ medpy_join_xd_to_xplus1d.py ~/combined.nii.gz 01.dcm 02.dcm 03.dcm 04.dcm 05.dcm 06.dcm 07.dcm 08.dcm 09.dcm 10.dcm -s0.2 -v 26.03.2014 13:48:48 [INFO ] Loading image 01.dcm... 26.03.2014 13:48:50 [INFO ] Loading image 02.dcm... 26.03.2014 13:48:50 [INFO ] Loading image 03.dcm... 26.03.2014 13:48:51 [INFO ] Loading image 04.dcm... 26.03.2014 13:48:52 [INFO ] Loading image 05.dcm... 26.03.2014 13:48:52 [INFO ] Loading image 06.dcm... 26.03.2014 13:48:53 [INFO ] Loading image 07.dcm... 26.03.2014 13:48:54 [INFO ] Loading image 08.dcm... 26.03.2014 13:48:54 [INFO ] Loading image 09.dcm... 26.03.2014 13:48:55 [INFO ] Loading image 10.dcm... Traceback (most recent call last): File "/usr/local/bin/medpy_join_xd_to_xplus1d.py", line 7, in execfile(file) File "/data_kruemel1/mastmeyer/medpy/bin/medpy_join_xd_to_xplus1d.py", line 126, in main() File "/data_kruemel1/mastmeyer/medpy/bin/medpy_join_xd_to_xplus1d.py", line 100, in main update_header_from_array_nibabel(example_header, output_data) File "/data_kruemel1/mastmeyer/medpy/medpy/io/header.py", line 305, in __update_header_from_array_nibabel hdr.get_header().set_data_shape(arr.shape) File "/usr/lib/python2.7/dist-packages/dicom/dataset.py", line 253, in __getattr raise AttributeError, "Dataset does not have attribute '%s'." % name AttributeError: Dataset does not have attribute 'get_header'.

loli commented 10 years ago

This bug stems of using DICOM images as inputs. Both PyDidcom and the ITK Wrapper do not support adding an additional dimension to an header or creating a new header form a numpy ndarray.

I modified the script to include a warning of this in the description and to throw an error when using dicom images as input.

For now I suggest avoiding the -s parameter and instead set the voxel spacing manually afterwards using medpy_set_voxel_spacing.py.

Best, loli

loli commented 10 years ago

Another workaround Convert your first image to NIfTI format

medpy_convert.py 01.dcm 01.nii.gz

then call the script again with just the first image switched

medpy_join_xd_to_xplus1d.py ~/combined.nii.gz 01.nii.gz 02.dcm 03.dcm 04.dcm 05.dcm 06.dcm 07.dcm 08.dcm 09.dcm 10.dcm -s0.2 -v

which will (magically :P) work.