3

I'm trying to read multi frame DICOM files using gdcm library.

But i can only read single frame dicom files data with this code :

gdcm::ImageReader reader;
reader.SetFileName(path); 
if(!reader.Read()) return false;

const gdcm::Pixmap &image = reader.GetPixmap();
int length = image.GetBufferLength();
char *buffer = new char[length];
image.GetBuffer(buffer);

How i can access to another frames ?

malat
  • 12,152
  • 13
  • 89
  • 158
masoud khanlo
  • 189
  • 1
  • 14
  • 2
    If you check the value of `length` you'll realize that the buffer is a C-style array containing all your frames in a single chunk. – malat Jul 20 '17 at 06:23
  • 2
    I did a quick check of the docs and it seems that there is no built in tool. As @malat says, you have access to the buffer, you will need to compute the frame sizes and then extract them yourself one by one. You might be able to use StreamImageReader, but examples are hard to find. – john elemans Jul 20 '17 at 17:25
  • @mahmoud-nezar-sarhan , malat was right , if you open a multi-frame dicom file then the image.GetBufferLength() will be as large as all frames size. – masoud khanlo Oct 17 '17 at 11:43

1 Answers1

0

With GDCM 3.0.8, you can read frames with something like following code,

  gdcm.ImageRegionReader imageReader = new gdcm.ImageRegionReader();
  imageReader.SetFileName(@"multiframe.dcm");
  imageReader.ReadInformation();

  gdcm.Image gimage = imageReader.GetImage();

  uint numDims = gimage.GetNumberOfDimensions();
  if (numDims < 2 || numDims > 3)
    return false;
  uint width = gimage.GetDimension(0);
  uint height = gimage.GetDimension(1);
  uint numFrames = 1;
  if (numDims == 3)
    numFrames = gimage.GetDimension(2);

  gdcm.PixelFormat pixelFormat = gimage.GetPixelFormat();
  var bytesPerPixel = pixelFormat.GetPixelSize();
  for (uint frame = 0; frame < numFrames; frame++)
  {
    gdcm.BoxRegion boxRegion = new gdcm.BoxRegion();
    boxRegion.SetDomain(0, width - 1, 0, height - 1, frame, frame);
    boxRegion.ComputeBoundingBox();
    imageReader.SetRegion(boxRegion);

    byte[] pixelBytes = new byte[width * height * bytesPerPixel];
    imageReader.ReadIntoBuffer(pixelBytes, (uint)pixelBytes.Length);
  }

Although this is C# code, C++ is almost the same. I hope someone might get help from this.

Ethan Kim
  • 1
  • 4