danishm / mritopng

A simple python module to make it easy to batch convert DICOM files to PNG images.
MIT License
137 stars 48 forks source link

mritopng command line won't convert #17

Open phrozendice opened 6 years ago

phrozendice commented 6 years ago

Hi There,

Tried to convert a .dcm file to png, using the command line on Mac OS X with Python 2.7.12 here is the output:

mritopng ~/file1.dcm ~/file1.png Traceback (most recent call last): File "/usr/local/bin/mritopng", line 11, in load_entry_point('mritopng==2.1', 'console_scripts', 'mritopng')() File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mritopng-2.1-py2.7.egg/mritopng/main.py", line 19, in main convert_file(args.dicom_path, args.png_path) File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mritopng-2.1-py2.7.egg/mritopng/init.py", line 50, in convert_file mri_to_png(mri_file, png_file) File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mritopng-2.1-py2.7.egg/mritopng/init.py", line 28, in mri_to_png w.write(png_file, image_2d_scaled) File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/png.py", line 655, in write nrows = self.write_passes(outfile, rows) File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/png.py", line 804, in write_passes extend(row) File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/png.py", line 801, in return lambda sl: f(map(int, sl)) TypeError: only size-1 arrays can be converted to Python scalars

Any ideas?

danishm commented 6 years ago

@phrozendice Would you be able to provide the file that causes this error?

phrozendice commented 6 years ago

@danishm thank you for your prompt response, unfortunately I can’t provide the source file as it contains personal identifiable information. If there is anything else I can do to help you reproduce please let me know.

danishm commented 6 years ago

@phrozendice That makes total sense! Yes, patient privacy is important. I've been developing on a cases by case basis using publicly available samples mostly. I have a few in this folder for testing in the project. Here is how you can help

Possible ways to help

  1. If you can figure out what's different between the sample files I have and the ones you have, that would help.
  2. If you're handy with jumping into python code, when you're processing your files, what does the variable image_2d_scaled look like on this line of code. I'm more interested in the shape rather than the data i.e. is it in fact a 2d array with some data inside it and what's it shape is.
Binb1 commented 4 years ago

@phrozendice Any news on this issue ? I'm running in the same problem and I'm having a hard time figuring why because this tool always worked for me with my previous DICOM files (thanks @danishm!)

Binb1 commented 4 years ago

@danishm Here is what I have when i print the image_2d_scaled variable:

`mritopng IVA0\ (1) output.png Arguments: %s Namespace(auto_contrast=False, dicom_path='IVA0 (1)', folder=False, png_path='output.png') Removing existing output file output.png [[[ 0. 0. 0. ] [ 0. 0. 0. ] [ 0. 0. 0. ] ... [ 0. 0. 0. ] [ 0. 0. 0. ] [ 0. 0. 0. ]]

[[ 0. 0. 0. ] [ 0. 0. 0. ] [ 0. 0. 0. ] ... [ 0. 0. 0. ] [ 0. 0. 0. ] [ 0. 0. 0. ]]

[[ 0. 0. 0. ] [ 0. 0. 0. ] [ 0. 0. 0. ] ... [ 0. 0. 0. ] [ 0. 0. 0. ] [ 0. 0. 0. ]]

...

[[ 0. 0. 0. ] [ 0. 0. 0. ] [99.23076923 99.23076923 99.23076923] ... [ 0. 0. 0. ] [ 0. 0. 0. ] [ 0. 0. 0. ]]

[[ 0. 0. 0. ] [ 0. 0. 0. ] [ 0. 0. 0. ] ... [ 0. 0. 0. ] [ 0. 0. 0. ] [ 0. 0. 0. ]]

[[ 0. 0. 0. ] [ 0. 0. 0. ] [ 0. 0. 0. ] ... [ 0. 0. 0. ] [ 0. 0. 0. ] [ 0. 0. 0. ]]] Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/png.py", line 795, in write_passes extend(row) TypeError: only size-1 arrays can be converted to Python scalars

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.6/bin/mritopng", line 11, in load_entry_point('mritopng==2.2', 'console_scripts', 'mritopng')() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mritopng-2.2-py3.6.egg/mritopng/main.py", line 21, in main convert_file(args.dicom_path, args.png_path, args.auto_contrast) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mritopng-2.2-py3.6.egg/mritopng/init.py", line 60, in convert_file mri_to_png(mri_file, png_file, auto_contrast) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mritopng-2.2-py3.6.egg/mritopng/init.py", line 22, in mri_to_png w.write(png_file, image_2d.image) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/png.py", line 656, in write nrows = self.write_passes(outfile, rows) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/png.py", line 805, in write_passes extend(row) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/png.py", line 802, in return lambda sl: f(list(map(int, sl))) TypeError: only size-1 arrays can be converted to Python scalars`