DCMTK读取DICOM文件,获取数据集、建立DicomDIr

阅读更多

 

Examples

The following example shows how to load a DICOM file and output the patient's name:

 

DcmFileFormat fileformat;
OFCondition status = fileformat.loadFile("test.dcm");
if (status.good())
{
  OFString patientName;
  if (fileformat.getDataset()->findAndGetOFString(DCM_PatientName, patientName).good())
  {
    cout << "Patient's Name: " << patientName << endl;
  } else
    cerr << "Error: cannot access Patient's Name!" << endl;
} else
  cerr << "Error: cannot read DICOM file (" << status.text() << ")" << endl;

 The following example shows how to create a DICOM dataset and save it to a file:

 

char uid[100];
DcmFileFormat fileformat;
DcmDataset *dataset = fileformat.getDataset();
dataset->putAndInsertString(DCM_SOPClassUID, UID_SecondaryCaptureImageStorage);
dataset->putAndInsertString(DCM_SOPInstanceUID, dcmGenerateUniqueIdentifier(uid, SITE_INSTANCE_UID_ROOT));
dataset->putAndInsertString(DCM_PatientName, "Doe^John");
/* ... */
dataset->putAndInsertUint8Array(DCM_PixelData, pixelData, pixelLength);
OFCondition status = fileformat.saveFile("test.dcm", EXS_LittleEndianExplicit);
if (status.bad())
  cerr << "Error: cannot write DICOM file (" << status.text() << ")" << endl;

 The following example shows how to create a general purpose DICOMDIR from multiple files:

 

DicomDirInterface dicomdir;
OFCondition status = dicomdir.createNewDicomDir();
if (status.good())
{
  while ( /* there are files */ )
    dicomdir.addDicomFile( /* current filename */ );
  status = dicomdir.writeDicomDir();
  if (status.bad())
    cerr << "Error: cannot write DICOMDIR (" << status.text() << ")" << endl;
} else
  cerr << "Error: cannot create DICOMDIR (" << status.text() << ")" << endl;
 

 

------------------------------------------------------------------

柳北风儿

http://qimo601.iteye.com

转载:http://support.dcmtk.org/docs/mod_dcmdata.html

你可能感兴趣的:(DCMTK,DICOM,DCMTK例子)