DCMTK에서 압축된 pixel 데이터 가져오기
5193 단어 DICOMDCMTKpixel 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
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
DCMTK에서 압축된 pixel 데이터 가져오기
If compressed DICOM images are loaded, DCMTK most of the time does the job of decompressing the image data itself, e.g. ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.
#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;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
DCMTK에서 압축된 pixel 데이터 가져오기If compressed DICOM images are loaded, DCMTK most of the time does the job of decompressing the image data itself, e.g. ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.