Cant read a special type of DICOM by VTK

I write code using VTK (c++) which its can read dicom file, and its work prefect and tested for CT, and MRI…but I got error when I try to view dicom file which its an Video, and in normal viewer in VTK return

Segmentation fault (core dumped)

And if I test it in actual program its open this dicom as a video.
To resolve this issue I try to convert this dicom file to avi video, but the output video is rabsh image with 0:0 duration.

int main (int argc, char *argv[])
{
  std::string folder     = argv[1];

  // One File in Directory and its dicom which is play as a video
  vtkSmartPointer<vtkDICOMImageReader> reader =
  vtkSmartPointer<vtkDICOMImageReader>::New();
  reader->SetDirectoryName(folder.c_str());
  reader->Update();

  vtkSmartPointer<vtkFFMPEGWriter> writer =
      vtkSmartPointer<vtkFFMPEGWriter>::New();
  writer->SetInputConnection(reader->GetOutputPort());
  writer->SetFileName("test.avi");
  writer->Start();
  writer->Write();
  writer->End();

  return EXIT_SUCCESS;
}

Which is best practice to resolve this issue or to make video work truth?
(Dicom file is used for cerebral angiographies)

What is the SOPClassUID and the TransferSyntaxUID for your file? If the TransferSyntaxUID indicates that it is compressed video, then your only option is to extract the encapsulated video stream and put it into a standard container format. If it is just an uncompressed multi-frame file, then reading it with VTK might be possible.

1 Like

Thank you @dgobbi, Really nice information which its let me search and read about Transfer Syntax and SOPClassUID…

Now I got:
1.2.840.10008.1.2.1 for TransferSyntaxUID, but I dont know how to got SOPClassUID value if you can let me know which VTK class can be use I will be thanks.

Dependence of your comment the TransferSyntaxUID refer to Explicit VR Little Endian, isset mean this is uncompressed multi-frame file? and convert it to video like our code in sample will not work?

Thanks for help.

I need to know the SOPClassUID in order to properly help you. Can you install a DICOM viewer like OsiriX or Weasis Medical Viewer that allows you to view the meta data? Or if you are comfortable using the command line, you can use dcmtk, gdcm, or my own dicomtools to get the meta data.

With that TransferSyntaxUID, chances are good that you have an uncompressed multi-frame file. The vtkDICOMImageReader cannot read these files, but I have written my own vtkDICOMReader that can read them.

Dealing with these files is never easy, though. Sometimes the entire “movie” is stored in a single multi-frame file, and sometimes it is split across several files. Sometimes there are multiple views. For subtraction images (DSA), sometimes the DICOM series has one single-frame file for the background and another multi-frame file with contrast.

To make things even more complicated, sometimes the radiologists will save their favorite frames as secondary capture images, which have a different SOPClassUID than the original images and often have to be dealt with in a different manner.

1 Like

WOW, You give me a lot of information about DICOM, and how I can thinking to work with these files, thanks a lot.

I use your tool, and its very nice, and I got SOPClassUID:
(0008,0016) UI "SOPClassUID" : [1.2.840.10008.5.1.4.1.1.12.1] {X-Ray Angiographic Image Storage} (28 bytes)

So that, I think I will be work now on vtkDICOMReader to handling this case :smiley:

It is good to know that it is using the standard SOP class for X-ray angiography.

By default, the reader will read each frame into a different slice, producing a volume where the Z dimension is actually the time dimension.

The vtkDICOMReader also has a method reader->TimeAsVectorOn() that will cause all the frames to be read into a single image, so that each pixel in the image is actually a time vector (i.e. if there are 14 frames, each pixel of the image data will have 14 components). This is the way that I prefer to work with time in VTK. When I want to visualize the data, I use filters that allow me to select the component (i.e. time) that I want to display.

For example, vtkImageMapToColors has a SetActiveComponent(i) method. And of course vtkImageExtractComponents has a SetComponents(i) method.

You’ll have to decide for yourself how to deal with time in your application. VTK is really just 3D, there isn’t a standard way of dealing with a ‘time’ dimension in VTK. To work with time, you need to be a bit creative.

1 Like

Perfect!, Thank you!