DCMTK讀取DICOM檔案-----獲取資料集-----建立DicomDIr
阿新 • • 發佈:2018-12-25
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;