Search code examples
pythonc++vtkdicompoint-cloud-library

Cant identify slice id/ series id using VTK (vtkDICOMImageReader)


I have two flavors of DICOM data, the first works with my existing code (what I built it on), but I can not import the second.

First style has a bottom level folder with all the slices from one scan in that folder (in ordered ".dcm" files). I simply point vtk to the directory using this code:

vtkSmartPointer<vtkDICOMImageReader> reader = vtkSmartPointer<vtkDICOMImageReader>::New();
reader->SetDirectoryName(dicomDirectory.c_str());
reader->Update();
vtkSmartPointer<vtkImageData> sliceData = reader->GetOutput();
double tempIntensity = sliceData->GetScalarComponentAsDouble(x, y, z, 0);

This is not the direct source (I check dimensions and set up iterating through and such). But in short, it works... I have pulled in several different dicom volumes through this method. (and have inspected and manipulated the resulting volume clouds)


This depends on VTK interpreting the directory though. It is stated here: that there are some particulars about what VTK is capable of managing (under detailed description, warning) in terms of DICOM data. (I am not sure my current data violates this spec)

The second style of DICOM has a directory structure where the bottom level of folders is named as A-Z and each one contains 25 files (with no suffix) which are named (in each folder) Z01-Z25. I can open the files individually using:

reader->SetFileName(tempFile.c_str());

Instead of specifying the directory. If I read all of the 25 in one of the bottom folders, it is a mix of different ordered chunks from different scans. I was prepared to set up a function to skim all folders and files in the directory to find and assemble all slices associated with one scan, but so far I have been unable to find/appropriately implement a function within vtkDICOMImageReader to:

A: detect which unique series set of slices I am in (series label)

nor

B: detect my current slice number in series as well as the total series count (slice count/ series slice total)


I can post more source as necesary, but basically have tried monitoring all parameters in "reader" and "sliceData" while loading slices from different series and as of yet have not gotten anything to provide me with the above data. I am assuming that either I am not appropriately updating in between slice loads and or am not looking at the right object parameters.

Any information on what I am doing wrong in terms of code or even my poor understanding of DICOM structure would be greatly appreciated!

ps: I am working in c++, but am fairly certain the usage is similar in Python


Solution

  • As I have posted in the comments, in this case, the vtk-dicom is more suitable for your needs. Here are some useful links: