`
qimo601
  • 浏览: 3439265 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

DCMTK获取压缩后的pixel data

阅读更多

 

Howto: Accessing Compressed Data

If compressed DICOM images are loaded, DCMTK most of the time does the job of decompressing the image data itself, e.g. when the user feeds it into the DicomImage class for visualization or directly calls chooseRepresentation() to change the transfer syntax. However, sometimes it may be useful to access the original, compressed pixel data of a single- or multi-frame image. This may be the case if the compressed data should be decompressed by an external library (e.g. because DCMTK does not support this kind of compression codec like for MPEG2) or if the data should be decompressed at all since it should be inserted directly into to another file.

For uncompressed pixel data usually this is done very easily by just finding the Pixel Data element in the DICOM dataset by calling DcmItem's findAndGetElement() routine and then call getUint8Array() (for example) on the resulting element to access the uncompressed raw pixel data vaules. For compressed data, however, there are some intermediate steps necessary in order to parse the underlying DICOM structures.

The reason is that for compressed data, there is a pseudo-sequence embedded into the Pixel Data element that has to be parsed before actually accessing the compressed data (and individual frames if applicable). The first pseudo-item in that sequence is always the offset table indicating at which byte position each frame actually starts within the following raw data of the Pixel Data element. However, you cannot rely on that table since it may be empty (always empty for MPEG2, for example). Within the next items so-called fragments stored. Usually, one fragment refers to exactly one frame of the image, but that is not a requirement at all. For the rest of the example, at least, this is assumed since this covers 90% of all cases.

In order to access the pixel sequence and the items it is containing, you have to deal with the Pixel Sequence within the Pixel Data element, and that is done using the DcmPixelSequence class in DCMTK. Here is a full (compiling) example how to accomplish that:

 

#include "dcmtk/config/osconfig.h"    /* make sure OS specific configuration is included first */
#include "dcmtk/dcmdata/dctk.h"
#include "dcmtk/dcmdata/dcpxitem.h"
 
 
int main(int argc, char *argv[])
{
  OFCondition result = EC_Normal;
  /* Load file and get pixel data element */
  DcmFileFormat dfile;
  result = dfile.loadFile("example.dcm");
  if (result.bad())
    return 1;
  DcmDataset *data = dfile.getDataset();
  if (data == NULL)
    return 1;
  DcmElement* element = NULL;
  result = data->findAndGetElement(DCM_PixelData, element);
  if (result.bad() || element == NULL)
    return 1;
  DcmPixelData *dpix = NULL;
  dpix = OFstatic_cast(DcmPixelData*, element);
  /* Since we have compressed data, we must utilize DcmPixelSequence
     in order to access it in raw format, e. g. for decompressing it
     with an external library.
   */
  DcmPixelSequence *dseq = NULL;
  E_TransferSyntax xferSyntax = EXS_Unknown;
  const DcmRepresentationParameter *rep = NULL;
  // Find the key that is needed to access the right representation of the data within DCMTK
  dpix->getOriginalRepresentationKey(xferSyntax, rep);
  // Access original data representation and get result within pixel sequence
  result = dpix->getEncapsulatedRepresentation(xferSyntax, rep, dseq);
  if ( result == EC_Normal )
  {
    DcmPixelItem* pixitem = NULL;
    // Access first frame (skipping offset table)
    dseq->getItem(pixitem, 1);
    if (pixitem == NULL)
      return 1;
    Uint8* pixData = NULL;
    // Get the length of this pixel item (i.e. fragment, i.e. most of the time, the lenght of the frame)
    Uint32 length = pixitem->getLength();
    if (length == 0)
      return 1;
    // Finally, get the compressed data for this pixel item
    result = pixitem->getUint8Array(pixData);
    // Do something useful with pixData...
  }
  if (result.bad())
    return 1;
  else
    return 0;
}

 

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

柳北风儿

http://qimo601.iteye.com

转载:http://support.dcmtk.org/wiki/dcmtk/howto/accessing-compressed-data

分享到:
评论

相关推荐

    C, C++读取 DICOM & DICONDE 图像数据

    DcmPixelData* pixelData = (DcmPixelData*)dataset->findAndGetSequenceOfItems(DCM_PixelData); Uint16* pixelBuffer = NULL; unsigned long numberOfFrames = 0; if (pixelData && pixelData->getUint16Array(&...

    java获取DICOM格式图片demo

    DICOM图像数据通常以像素数组的形式存储,可以通过`PixelData`元素获取。然后,我们可以使用`PixelUtil`类将这些数据转换为常见的图像格式: ```java byte[] pixelData = ds.getPixelData().toByteArray(); ...

    DICOM_DARASET.zip

    7. **DICOM数据解析**: 学习和理解DICOM数据,需要掌握如何解析其数据结构,包括解析DICOM Header(头部信息)和Pixel Data(像素数据)。Header中的信息帮助我们理解图像的来源、类型以及扫描参数,而Pixel Data则...

    读取DICOM文件(c编写).rar.rar

    - 对于像素数据(Pixel Data),由于其通常非常大,可能需要特殊处理,例如使用`DcmPixelData::getUint8Array()`获取像素值。 5. 处理像素数据: DICOM中的像素数据可以是多种编码格式,如未压缩的灰度或RGB图像...

    dicom文件的读写源码

    另一部分是Pixel Data(像素数据),存储实际的图像信息。Header 中的数据按照 DICOM 标准规定的数据元素(Element)进行组织,每个元素都有一个特定的标签(Tag)和对应的值。 2. **DICOM Header**:Header 包含了...

    DICOM格式,医学数据文件

    在 DICOM 格式中,每个文件都由多个部分组成,包括一个文件头(Header)和数据体(Pixel Data)。文件头包含了 DICOM 元数据,这些元数据以 Tag 的形式存在,Tag 是一个16位的标识符,用于定义数据元素的类型。例如...

    数字图像处理——MFC实现DICOM图像打开与处理

    理解DICOM格式是处理此类图像的基础,包括其文件结构、数据元素(如Pixel Data、Patient Information等)以及编码方式(如JPEG、RLE等)。 MFC是微软提供的一个面向对象的C++库,它简化了Windows应用程序开发,提供...

    DICOM文件 DCM文件

    在实际应用中,C#开发者可能需要编写代码来解析DCM文件的各个部分,如DIR(DICOM Information Repository)用于存储患者和研究信息,而Pixel Data元素则包含了实际的图像像素值。理解DICOM文件结构和编码方式(如...

    DICOM协议资料汇集

    3. **像素数据(Pixel Data)**:DICOM图像的像素数据通常经过压缩存储,常见的压缩算法有JPEG、RLE(Run Length Encoding)等。理解像素数据的解码过程对于正确显示图像至关重要。 4. **元数据(Metadata)**:...

    新建文件夹.zip_dicom文件_读取DICOM文件

    2. **像素数据(Pixel Data)**:文件中的图像数据部分,通常编码为灰度或颜色像素的数组。DICOM支持多种压缩算法,如JPEG、RLE(Run Length Encoding)和JPEG 2000,这些压缩方式会影响像素数据的存储方式和大小。 ...

    模拟Dicom设备发送程序.rar

    以及一个数据体(Pixel Data),存储了实际的医学影像。 2. **DICOM 格式编码**:DICOM 文件可以采用多种编码方式,如灰度图像编码、JPEG 压缩、RLE(Run-Length Encoding)等,以适应不同的影像质量和传输速度需求...

    在DICOM格式转换为BMP位图格式的C++源代码.rar

    1. DICOM解析:首先,你需要了解DICOM文件的结构,包括它的头信息(Header)和像素数据(Pixel Data)。DICOM头信息包含了许多重要的元数据,如图像尺寸、像素间距、色彩空间等。解析这些信息是转换的第一步。 2. ...

    修改dicom的检查号

    关于"读取DICOM文件",这涉及到理解DICOM文件结构,包括文件头(Header)、像素数据(Pixel Data)以及一系列的DICOM元素(Elements),每个元素都有一个特定的Tag,如(0008,0020) - Study Date, (0008,0030) - ...

    和DICOM有关的资料

    3. **Pixel Data**:图像的实际像素数据,根据不同的压缩算法(如JPEG、RLE、未压缩等)以二进制形式存储。 4. **Transfer Syntax**:DICOM文件可以使用多种传输语法,比如JPEG、PNG、未压缩等,决定了数据如何在...

    matlab开发-DICOMdebugutility.zip.zip

    1. **DICOM结构**:了解DICOM文件的结构至关重要,包括元数据(Header)和图像数据(Pixel Data)。元数据包含了关于图像的临床信息,如患者信息、设备信息、扫描参数等;像素数据则存储实际的图像内容。 2. **...

    DICOM 学习入门资料

    DICOM数据通常以DICOM文件的形式存在,这些文件遵循特定的文件格式,其中包括DICOM头(Header)和像素数据(Pixel Data)。头部信息以一系列称为DICOM元素(DICOM Tags)的形式存储,每个元素都有一个唯一的16位标签...

    DICOM-Stand.rar_图形图像处理_Visual_C++_

    3. **图像数据**:DICOM图像数据存储在Pixel Data(0x7fe0,0x0010)字段,可以是未压缩的原始像素值,也可以是经过JPEG、RLE或其它压缩算法压缩的数据。解码这部分数据以得到实际图像,需要根据DICOM文件的压缩编码...

Global site tag (gtag.js) - Google Analytics