六、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 举例:
--用无失真JPEG压缩一幅DICOM图像文件。
DJEncoderRegistration::registerCodecs(); // register JPEG codecs DcmFileFormat fileformat;
if (fileformat.loadFile(\
{
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 created
dataset->chooseRepresentation(EXS_JPEGProcess14SV1TransferSyntax, ¶ms); // check if everything went well
if (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 changed
delete metaInfo->remove(DCM_MediaStorageSOPClassUID); delete metaInfo->remove(DCM_MediaStorageSOPInstanceUID); // store in lossless JPEG format
fileformat.saveFile(\} }
DJEncoderRegistration::cleanup(); // deregister JPEG codecs --解压缩一幅JPEG压缩的DICOM图像文件。
DJDecoderRegistration::registerCodecs(); // register JPEG codecs DcmFileFormat fileformat;
if (fileformat.loadFile(\{
DcmDataset *dataset = fileformat.getDataset();
// decompress data set if compressed
dataset->chooseRepresentation(EXS_LittleEndianExplicit, NULL); // check if everything went well
if (dataset->canWriteXfer(EXS_LittleEndianExplicit)) {
fileformat.saveFile(\} }
DJDecoderRegistration::cleanup(); // deregister JPEG codecs 七、dcmnet程序包
dcmnet是一个网络库及可用工具。该模块包含了实现DICOM网络通信的所有函数集,即:DICOM上层有限状态机(DICOM Upper Layer Finite State Machine),关联控制服务元素(Association Control Service Element, ACSE)以及DICOM消息服务元素(DICOM Message Service Element, DIMSE)。
主要接口:该模块的主要接口包括在文件assoc.h和dimse.h中定义的大量结构和函数。
--assoc.h: 这个文件包含程序,为DICOM应用提供关联管理。它维护描述活动关联的结构,提供对关联特定信息的访问。也提供程序帮助关联协议association negotiation(presentation contexts, abstract syntaxes, transfer syntaxes, maximum PDU length, and other extended negotiation)。该包使用了DICOM上层机制接收/发送关联请求/响应。每一个活动的关联由T_ASC_Association结构表示,包含了所有相关的信息。模块前缀ASC_。
--dimse.h: 这个文件包含程序,为DICOM应用提供dimse层的服务。 工具:
--echoscu: DICOM verification (C-ECHO) SCU --findscu: DICOM query (C-FIND) SCU --movescu: DICOM retrieve (C-MOVE) SCU --storescp: DICOM storage (C-STORE) SCP --storescu: DICOM storage (C-STORE) SCU
--termscu: DICOM termination SCU 举例:
--一个简单的Echo SCU(Verification Service Class SCU)。大多数错误处理代码省去了,在Win32上的特定代码如WinSock初始化也省去了。
T_ASC_Network *net; // network struct, contains DICOM upper layer FSM etc. ASC_initializeNetwork(NET_REQUESTOR, 0, 1000 /* timeout */, &net); T_ASC_Parameters *params; // parameters of association request ASC_createAssociationParameters(¶ms, ASC_DEFAULTMAXPDU); // set calling and called AE titles
ASC_setAPTitles(params, \
// the DICOM server accepts connections at server.nowhere.com port 104 ASC_setPresentationAddresses(params, \
// list of transfer syntaxes, only a single entry here
const char* ts[] = { UID_LittleEndianImplicitTransferSyntax }; // add presentation context to association request
ASC_addPresentationContext(params, 1, UID_VerificationSOPClass, ts, 1); // request DICOM association T_ASC_Association *assoc;
if (ASC_requestAssociation(net, params, &assoc).good()) {
if (ASC_countAcceptedPresentationContexts(params) == 1) {
// the remote SCP has accepted the Verification Service Class
相关推荐: