Skip to content
Raphael Kim edited this page Jul 5, 2017 · 1 revision

Read a DCM file from file system

  • This lecture may help you understand how to read DCM and load it to memory.

Preparation

  • Compiled, or prebuilt library : libtinydicom.a
  • Inlcude header file "libDCM.h" in your source code.
  • And ability to link libtinydicom.a
  • An example DCM file.

Open DCM file

  • You can read DCM file from your file system.
// decide using namespace of std

using namespace std;

string fileDCM = "LLVM.DCM";

if ( OpenDCM( fileDCM.c_str() ) == true )
{
	// Get DICOM tag element count
	int elements = GetElementCount(); 
	
	// Proceed if elements exists.
	if ( elements > 0 )
	{
		// Read DICOM image .
		ImageInformation dcmimg = {0};
		
		if ( ImagePixelData( &dcmimg ) == true )
		{
			printf( "DICOM pixel image information : \n");
			printf( "\t- pixel data BPP = %d\n", dcmimg.bpp );
			printf( "\t- width x height = %d x %d\n", dcmimg.width, dcmimg.height );
		}
		else
		{
			printf( "Failure : No pixel data in DCM.\n" );
		}
	}
	
	// Let close DCM file handle.
	CloseDCM();
}