read all the dicom files in a directory?

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
qs5d
Posts: 6
Joined: Thu, 2005-04-28, 14:53

read all the dicom files in a directory?

#1 Post by qs5d »

Does DCMTK provide some method to read all the dicom files under the same directory and write into one file? Thank you.

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#2 Post by Jörg Riesmeier »

This is not supported by the DCMTK since you cannot write multiple SOP instances into one. Or do you mean a DICOMDIR file? This can be created using the tools dcmgpdir/dcmmkdir or the class DicomDirInterface.

qs5d
Posts: 6
Joined: Thu, 2005-04-28, 14:53

read multiple dicom files in the dir and write to one file

#3 Post by qs5d »

Maybe I didn't express my idea clearly in the previous question. Now I have several hundred of dicom files under a directory, those files are randomly named. I need to read those randomly named dicom files into one file with only pixel data in order to create a 3d volume of raw image. This 3d volume are saved in an array that reads in the pixel data of each dicom file slice by slice. I'm not sure whether it could be done with DCMTK? Thank you.

wrgben
Posts: 20
Joined: Thu, 2005-01-06, 10:53

#4 Post by wrgben »

You could use dcmdump with the +W option. This will dump the pixel data into a .raw file. Then you could concatenate all the .raw files together to make your volume dataset.

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#5 Post by Jörg Riesmeier »

Alternatively, you could write a little program that performs this task (load DICOM file, extract pixel data, append to output file). I guess that "qs5d" would also like to sort the individual images before creating the image volume.

Btw, I could also imagine that some of the 3D toolkits for the visualization of medical images provide such functionality.

Max
Posts: 3
Joined: Fri, 2006-04-07, 11:40

#6 Post by Max »

Jörg Riesmeier wrote:Alternatively, you could write a little program that performs this task (load DICOM file, extract pixel data, append to output file).
Hi,
This is exactly what I am trying to do, I started from the example in the DCMTK documentation and have written the following code:

Code: Select all


FILE *stream;
int main()
{
int list[65536];	//image is 256*256
DicomImage *image =new DicomImage("test.dcm");
if (image != NULL)
{
  if (image->getStatus() == EIS_Normal)
  {
    if (image->isMonochrome())
    {
      image->setMinMaxWindow();
      Uint8 *pixelData = (Uint8 *)(image->getOutputData(8 /* bits */));
      if (pixelData != NULL)
      { /* do something useful with the pixel data */ 
	     fopen_s(&stream, "test.raw", "wb" );
	     for (int i = 0; i < 65536; i++)
	     { list[i]=pixelData[i];
	        fwrite( list, sizeof( int ), 65536, stream );
              }
       }fclose(stream);
    }
  } else
    cerr << "Error: cannot load DICOM image (" << DicomImage::getString(image->getStatus()) << ")" << endl;
}
delete image;
}

I get a test.raw file which is huge compared to the correct one I get using dcmdump.exe with the +W option.
I'm sorry if the answer sounds easy to you, but I'm quite new to this kind of things.
Thank you.

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#7 Post by Jörg Riesmeier »

Why are you using a for-loop? Just write the whole array of pixel data into the file using fwrite().

Btw, DicomImage::getOutputData() does not give you access to the raw pixel data (in contrast to "dcmdump +W") as you can read both in the documentation and in various postings in this forum.

Max
Posts: 3
Joined: Fri, 2006-04-07, 11:40

#8 Post by Max »

Thank you,
I've modified my code, now it uses the findAndGetUint16Array() function and seems to work fine.
Sorry for the dumb question.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest