日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

dcmtk程序包综述(1)

發布時間:2025/3/15 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 dcmtk程序包综述(1) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.前言

簡單列出dcmtk程序包的簡介,包括主要接口類的簡單說明,可用工具以及一些例子。下一步工作準備詳細分析每個程序包中的接口類功能,并結合源碼和dicom文檔分析其實現過程。

2.Config程序包

config目錄下的文檔:

  • config.txt:指出你編輯的任何.h .c .cc文件首先必須包含該目錄下的頭文件#include "osconfig.h"
  • dirstruc.txt:給出了dcmtk項目的項目目錄結構,這個用cmake會自動生成
  • envvars.txt:這個文件比較重要,它指出了一些運行時環境變量,這些變量可能會影響dcmtk的工具和庫的使用,這些變量包括:
    • DCMDICTPATH:影響dcmdata
    • On Win32 platforms, a built-in dictionary is used by default. If the DCMDICTPATH environment variable is set, the applications willattempt to load _additional_ DICOM data dictionaries specified in the DCMDICTPATH environment variable instead. The DCMDICTPATH environment variable has the same format as the shell PATH variable in that a semicolon (";") separates entries. The data dictionary code will attempt to load each file specified in the DCMDICTPATH environment variable.
  • TCP_BUFFER_LENGTH:影響dcmnet By default, DCMTK uses a TCP send and receive buffer length of 32K. If the environment variable TCP_BUFFER_LENGTH is set,it specified an override for the TCP buffer length. The value is specified in bytes, not in Kbytes.
  • TCP_NODELAY:影響dcmnet.If this environment variable contains a non-zero number,the Nagle algorithm will not be disabled for TCP transport connections. Also see documentation for macro DONT_DISABLE_NAGLE_ALGORITHM in config/docs/macros.txt
  • TMPDIR:影響dcmnet.Affects the implementation of the tempnam() emulation on platforms where tempnam() is not defined. See tempnam(3S) main page for a description.
  • macros.txt:這個文件也特別重要,它給出了很多編譯時的宏,這些宏可能會影響dcmtk的工具和庫的使用。大部分的宏可以用來激活一些實驗性的或很少需要的特性,另外有一些是用來取消某些功能。要盡量謹慎使用。詳細見文檔。
  • modules.txt:這個文件講述如何自己配置各個模塊,不需要掌握。
  • config的include目錄下的文件
    • osconfig.h:這個文件是必須包含在所有.h .c文件中的.其中指出在win32環境下包含 "dcmtk/config/cfwin32.h"文件
    • cfwin32.h:包含了大量的宏定義。***如果需要查找某個宏的定義,可到這個文件中查找***

3.ofstd程序包


ofstd:作為一般目的的類庫。
這個模塊包含了一般目的的類庫,這些類所描述的對象概念并非在Dicom標準中特有。它們廣泛的在toolkit中使用。主要包含下面的類

  • OFCommandLine:處理命令行參數,頭文件在ofcmdln.h。***詳情需要結合具體的代碼來理解***
  • OFCondition:描述條件碼的一般類。頭文件在ofcond.h。***詳情需要結合具體的代碼來理解***
  • OFConsole:是一個singleton(孤立)類。提供線程安全的對標準輸出流和錯誤流的訪問。允許以多線程的方式同時創建輸出。
  • OFList:是一個雙向鏈表模板類,接口是STL list類中的一個子集。頭文件在oflist.h。
  • OFStack:是一個堆棧模板類,接口是STL stack類中的一個子集。頭文件在ofstack.h.
  • OFStandard:包含大量幫助函數組成的類,用來包含大量“全局”幫助函數。注意全部都是靜態函數。其中的一些函數實現調用了windows API函數,如fileexists()。頭文件在ofstd.h。
  • OFString:一個簡單的string類,實現了std::string的一個子集,沒有iterator或trait,在速度上也沒有優化。頭文件在ofstring.h

4.dcmdata程序包

dcmdata:一個數據編碼/解碼庫和可用的工具.
這個模塊包含了一些類來管理Dicom數據結構和文件。同時它也提供了對DICOMDIR文件的支持以滿足Dicom storage media(存儲介質)的需要。

主要的接口類有:

  • DcmFileFormat:a class handling the DICOM file format (with meta header) 。頭文件在dcfilefo.h。
  • DcmDataset:a class handling the DICOM dataset format (files without meta header) 。頭文件在dcdatset.h.
  • DcmItem:a class representing a collection of DICOM elements。頭文件在dcitem.h。
  • DcmElement:abstract base class for all DICOM elements。頭文件在dcelem.h。
  • DcmAttributeTag/DcmByteString/DcmFloatingPointDouble/DcmFloatingPointSingle/DcmOtherByteOtherWord/DcmSequenceOfItems/DcmSignedLong/DcmSignedShort/DcmUnsignedLong/DcmUnsignedShor
工具:這個模塊包含了下面的命令行工具:
dcm2xml: Convert DICOM file and data set to XML
dcmconv: Convert DICOM file encoding
dcmcrle: Encode DICOM file to RLE transfer syntax
dcmdrle: Decode RLE-compressed DICOM file
dcmdump: Dump DICOM file and data set
dcmftest: Test if file uses DICOM part 10 format
dcmgpdir: Create a general purpose DICOMDIR
dcmodify: Modify DICOM files
dump2dcm: Convert ASCII dump to DICOM file
xml2dcm: Convert XML document to DICOM file or data set

例一:調入一個DICOM文件,輸出病人姓名:

DcmFileFormat fileformat; OFCondition status = fileformat.loadFile("test.dcm"); if (status.good()) {OFString patientsName;if (fileformat.getDataset()->findAndGetOFString(DCM_PatientsName, patientsName).good()){cout << "Patient's Name: " << patientsName << endl;} else{cerr << "Error: cannot access Patient's Name!" << endl;} elsecerr << "Error: cannot read DICOM file (" << status.text() << ")" << endl;例二:創建一個DICOM dataset數據集,并保存為文件
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_PatientsName, "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;例三:如何為多個文件創建一般目的的DICOMDIR

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; } elsecerr << "Error: cannot create DICOMDIR (" << status.text() << ")" << endl;

5.dcmimgle程序包

dcmimgle是一個圖像處理庫和可用的工具模塊,它包括了對DICOM單色圖像的訪問和顯示。對顏色圖像的支持由dcmimage模塊提供,對JPEG壓縮圖像的支持由dcmjpeg模塊支持。
主要接口類:

  • DicomImage: 為dcmimgle/dcmimage模塊提供接口類。主要目的是圖像顯示。在dcmimage.h中定義
  • DiDisplayFunction: Class to handle hardcopy and softcopy device characteristics file and manage display LUTs (for calibration). 在didispfn.h中定義。
可用工具:
  • dcmdspfn: Export standard display curves to a text file
  • dcod2lum: Convert hardcopy characteristic curve file to softcopy format
  • dconvlum: Convert VeriLUM files to DCMTK display files
例一:載入一幅DICOM單幀單色圖像,并顯示其像素數據

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 */}}} elsecerr << "Error: cannot load DICOM img(" << DicomImage::getString(image->getStatus()) << ")" << endl; } delete image;

6.dcmimage程序包

dcmimage模塊為dcmimgle模塊提供對彩色圖像的支持。對單色圖像的支持由dcmimgle提供,對JPEG壓縮圖像的支持由dcmjpeg模塊支持。
主要接口類:

  • DicomImage: 在dcmimgle中已介紹。
工具:
  • dcm2pnm: Convert DICOM images to PPM/PGM, PNG, TIFF or BMP
  • dcmquant: Convert DICOM color images to palette color
  • dcmscale: Scale DICOM image
舉例:載入一幅DICOM單幀圖像(單色或彩色),并顯示其像素數據
#include "diregist.h" /* required to support color images */ DicomImage *image = new DicomImage("test.dcm"); if (image != NULL) {if (image->getStatus() == EIS_Normal){Uint8 *pixelData = (Uint8 *)(image->getOutputData(8 /* bits per sample */));if (pixelData != NULL){/* do something useful with the pixel data */}} elsecerr << "Error: cannot load DICOM img (" << DicomImage::getString(image->getStatus()) << ")" << endl; } delete image;

7.dcmjpeg程序包

dcmjpeg提供了一個壓縮/解壓縮庫以及可用工具。該模塊包含一些類,可將DICOM圖像對象在非壓縮和JPEG壓縮表示(傳輸協議)之間轉換。無失真和有失真JPEG處理都被支持。這個模塊實現了一族codec(編碼解碼器,由DcmCodec類派生而來),可以將這些codec在codec list中注冊,codec list是由dcmdata模塊保存的。
主要接口類:

  • DJEncoderRegistration: 一個singleton(孤立)類,為所有支持的JPEG處理注冊編碼器。在djencode.h中定義。
  • DJDecoderRegistration: 一個singleton(孤立)類,為所有支持的JPEG處理注冊解碼器。在djdecode.h中定義。
  • DJCodecEncoder: JPEG編碼器的一個抽象codec類。This abstract class contains most of the application logic needed for a dcmdata codec object that implements a JPEG encoder using the DJEncoder interface to the underlying JPEG implementation. This class only supports compression, it neither implements decoding nor transcoding. 在djcodece.h中定義
  • DJCodecDecoder: JPEG解碼器的一個抽象codec類。This abstract class contains most of the application logic needed for a dcmdata codec object that implements a JPEG decoder using the DJDecoder interface to the underlying JPEG implementation. This class only supports decompression, it neither implements encoding nor transcoding.
工具:
  • dcmcjpeg: Encode DICOM file to JPEG transfer syntax
  • dcmdjpeg: Decode JPEG-compressed DICOM file
  • dcmj2pnm: Convert DICOM images to PGM, PPM, BMP, TIFF or JPEG
  • dcmmkdir: Create a DICOMDIR file

例1:用無失真JPEG壓縮一幅DICOM圖像文件

DJEncoderRegistration::registerCodecs(); // register JPEG codecs DcmFileFormat fileformat; if (fileformat.loadFile("test.dcm").good()) {DcmDataset *dataset = fileformat.getDataset();DcmItem *metaInfo = fileformat.getMetaInfo();DJ_RPLossless params; // codec parameters, we use the defaults// this causes the lossless JPEG version of the dataset to be createddataset->chooseRepresentation(EXS_JPEGProcess14SV1TransferSyntax, ?ms);// check if everything went wellif (dataset->canWriteXfer(EXS_JPEGProcess14SV1TransferSyntax)){// force the meta-header UIDs to be re-generated when storing the file// since the UIDs in the data set may have changeddelete metaInfo->remove(DCM_MediaStorageSOPClassUID);delete metaInfo->remove(DCM_MediaStorageSOPInstanceUID);// store in lossless JPEG formatfileformat.saveFile("test_jpeg.dcm", EXS_JPEGProcess14SV1TransferSyntax);} } DJEncoderRegistration::cleanup(); // deregister JPEG codecs例2:解壓縮一幅JPEG壓縮的DICOM圖像文件
DJDecoderRegistration::registerCodecs(); // register JPEG codecs DcmFileFormat fileformat; if (fileformat.loadFile("test_jpeg.dcm").good()) {DcmDataset *dataset = fileformat.getDataset();// decompress data set if compresseddataset->chooseRepresentation(EXS_LittleEndianExplicit, NULL);// check if everything went wellif (dataset->canWriteXfer(EXS_LittleEndianExplicit)){fileformat.saveFile("test_decompressed.dcm", EXS_LittleEndianExplicit);} } DJDecoderRegistration::cleanup(); // deregister JPEG codecs

總結

以上是生活随笔為你收集整理的dcmtk程序包综述(1)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。