eidelen / DicomToMesh

A command line tool to transform a DICOM volume into a 3d surface mesh (obj, stl or ply). Several mesh processing routines can be enabled, such as mesh reduction, smoothing or cleaning. Works on Linux, OSX and Windows.
MIT License
451 stars 93 forks source link

Ignore/skip/recover from files that can't be read by VTK #14

Closed virtualritz closed 5 years ago

virtualritz commented 5 years ago

I had my knee MRI'd the other day. This is the data, straight from the CD they gave me. Feel free to use it for testing your software. Running Dicom2mesh on this, I get below error – it bails on file 33. Maybe, for starters, files that can't be read could just be ignored. I suspect that in this case there is another issue though – that I may have to report upstream, to the VTK maintainers – as the CD is fine and no errors were reported then I copied the files.

$ dicom2mesh/dicom2mesh -i ../0000 -o knee.obj

Dicom2Mesh Settings
-------------------
Input directory: ../0000
Output file path: knee.obj
Surface segmentation: 400
Mesh reduction: disabled
Mesh polygon limitation: disabled
Mesh smoothing: disabled
Mesh centering: disabled
Mesh filtering: disabled
Volume cropping: disabled

Read DICOM images located under ../0000
Progress: 0.0%ERROR: In /tmp/vtk-20181122-71935-1oohxh5/VTK-8.1.2/IO/Image/vtkDICOMImageReader.cxx, line 333
vtkDICOMImageReader (0x7f9b44e04090): There was a problem retrieving data from: ../0000/0033

ERROR: In /tmp/vtk-20181122-71935-1oohxh5/VTK-8.1.2/Common/ExecutionModel/vtkExecutive.cxx, line 784
vtkCompositeDataPipeline (0x7f9b44e04230): Algorithm vtkDICOMImageReader(0x7f9b44e04090) returned failure for request: vtkInformation (0x7f9b44e050b0)
  Debug: Off
  Modified Time: 167
  Reference Count: 1
  Registered Events: (none)
  Request: REQUEST_DATA
  FORWARD_DIRECTION: 0
  ALGORITHM_AFTER_FORWARD: 1
  FROM_OUTPUT_PORT: 0

Progress: done

Create surface mesh with iso value = 400
Progress: done

No mesh could be created. Wrong DICOM or wrong iso value
eidelen commented 5 years ago

Hi Moritz, There are 7 DICOM series among your data. If you compile Dicom2Mesh with the compile option "USE_VTK_DICOM" enabled, you will see following output:

Read DICOM images located under knee/0000/
Nbr of patients = 1, Nbr of studies = 1, Nbr of series = 7
(0)  :  33 files, name = pd_tse-fs_sag_KNEE04.01
(1)  :  31 files, name = pd_tse-fs_cor_KNEE04.01
(2)  :  144 files, name = t2_de3d-we_sag_KNEE09.02
(3)  :  120 files, name = t2_de3d-we_sag_KNEE09.02_MPR_tra
(4)  :  120 files, name = t2_de3d-we_sag_KNEE09.02_MPR_cor
(5)  :  37 files, name = pd_tse-fs_tra_KNEE05.01
(6)  :  31 files, name = t1_tse_cor_KNEE06.03
Which DICOM series you wish to load? 2

However, when selecting (2) the biggest series, following error is generated by VTK:

ERROR: In /Users/eidelen/dev/libs/vtk-dicom/Source/vtkDICOMReader.cxx, line 1885
vtkDICOMReader (0x7f8749e00840): DICOM file is compressed, cannot read.

If you want still to use Dicom2Mesh, you need to uncompress the DICOM first. If you are open to use something else, I can recommend to you ITK-Snap for segmenting / viewing your DICOM.

Be aware that your DICOM dataset form medneo Diagnostikzentrum Berlin contains more than just the images. One can see your age, weight, size... and much more.

virtualritz commented 5 years ago

Maybe there could be an error message indicating this problem (that the DICOM needs to be uncompressed)? From the error I got I figured there was an error in the data since only image 33 was mentioned. It looked to me like 0..32 were read just fine by Dicom2mesh.

eidelen commented 5 years ago

Dicom2Mesh is able to work with either the standard VTK DICOM reader or with a more sophisticated version called VTK-DICOM, another open source library. The usage of VTK-DICOM needs to be enabled when you build Dicom2Mesh USE_VTK_DICOM = ON. I think, your Dicom2Mesh build uses the standard VTK DICOM reader, which is unable to handle a DICOM of multiple series. That's why it fails at slice 33, as it is the end of the first series. In case you enable the more advance DICOM reader, Dicom2Mesh can handle multiple series. However, it fails because the images are compressed. So, there are actually two different issues with your data. As the DICOM reader is not written by us, we can not solve this issue ourself. I am sorry about that.

eidelen commented 5 years ago

As described in the above issue "Compressed DICOM #161", the vtk-dicom library should be build with USE_GDCM option turned on. Like that, I could open your data.

virtualritz commented 5 years ago

Thank you, that worked. For reference of anyone reading this and wishing to build Dicom2mesh with the aforementioned options, this is what I did (on macOS, using Homebrew):

brew install gdcm

git clone https://github.com/dgobbi/vtk-dicom.git
cd vtk-dicom
mkdir build
cd build
cmake -DUSE_GDCM=ON ..
make -j4 install
cd ..

git clone https://github.com/AOT-AG/DicomToMesh.git
cd DicomToMesh
mkdir build
cd build
cmake -DUSE_VTK_DICOM=ON  ..
make -j4
eidelen commented 5 years ago

Thank you for the helpful build summary. I added a link to it in the readme.