Hi everyone, I am VTK user and recently I needed to start visualizing some DICOM in the 3D space. The idea is to shows some stl from segmentation together with some relative DICOM.
Essentially, I follow the vtkDICOMImageReader example (https://vtk.org/Wiki/VTK/Examples/Cxx/IO/ReadDICOM) which works fine except for the quality of the images I get. Attached you may find an example: on the left the result I get with VTK, on the right the same DICOM read with MicroDicom.
Here’s a way to render the image with a bit more clarity. Wrote the code in Python and used matplotlib to get a nice colormap but this could be translated to C++:
Note that rendering images like this can be quite cumbersome and if you’re new to VTK, I’d recommend using Python for rapid prototyping. Also, check out vtki. I’ll add a DICOM reader to vtki soon but you could get a similar rendering with a bit more intuitve controls using vtki:
import vtk
import vtki
filename = 'DICOM_test.dcm'
# read using vtk
reader = vtk.vtkDICOMImageReader()
reader.SetFileName(filename)
reader.Update()
data = vtki.wrap(reader.GetOutput())
# OR when I add the DICOM reader to `vtki`:
# data = vtki.read(filename)
# and plot it with a bone colormap
data.plot(cmap='bone', cpos='xy')
thank you for your help. First of all, there is no problem to use this data for an example.
Coming to your suggestion, if I understood correctly you built a color map outside VTK and than pass it to the vtkDataSetMapper to forcing the right visualizaiton. I have not yet tested your solution since I am coding in c++ and at the moment I have not the time to switch to pyton. However I should be able to do the same using Matlab and C++. I will keep you updated on the results.
However, what it is not clear to me is why the DICOMReader does behave this way. I had the same results with all the DICOM I tested, coming from very different MR scanners. So it seems that the DICOMReader actually has problem in reading standard DICOM format. Do you know if DICOMReader needs a specified data format? Has said, data from the example are in .img.
Yes, you should be able to copy most of that code and switch a few syntax things. You could also try simply number of colors and scalar range instead of making a colormap (I do this below).
I’m not sure there is anything wrong with the DICOM reader as the data values being read in seem correct, it’s just a bit tricky to get the rendering/color mapping to properly display those values (as is the case with any data). To check, when I read in that DICOM file, it sees a single vtkShortArray of data values (i.e. int16). These values range at (0, 6930) for the specific file you shared with me. Are those results not expected?
I think the reader is behaving correctly, you’re just experiencing trouble with your mapper. Perhaps this code works best for you to avoid building a colormap (this is pure VTK so it can be translated to C++ easily):
Here is another way to improve the output of the first vtk example. This is a rough method to additionally set the color level and window. For now, I don’t know if it is the usual way.
Thank you all for the help and support. Actually, the solution proposed by Kenichiro Yoshimi works fine with the minimum amount of additional code so I will go for that.