DCMTK-dcmimage-向dcmigle添加对彩色图像的支持
Posted itzyjr
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DCMTK-dcmimage-向dcmigle添加对彩色图像的支持相关的知识,希望对你有一定的参考价值。
该模块包含访问和渲染DICOM彩色图像的类。模块dcmigle支持单色图像。模块dcmjpeg提供了对JPEG压缩图像的支持。
示例:
以下示例显示如何加载DICOM单帧图像(单色或彩色)并渲染其像素数据:
#include "dcmtk/dcmimage/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 */
else
cerr << "Error: cannot load DICOM image (" << DicomImage::getString(image->getStatus()) << ")" << endl;
delete image;
构造函数:
DicomImage::DicomImage(
const char* filename,
const unsigned long flags = 0,
const unsigned long fstart = 0,
const unsigned long fcount = 0
)
打开指定的文件并读取图像相关数据,创建图像数据的内部表示。使用getStatus()获取有关任何错误的详细信息。
filename
- DICOM文件。
flags
- 配置标志(自动设置为CIF_MayDetachPixelData)。
fstart
- 要处理的第一帧(可选,0=第一帧),该类中标记为“frame”的参数的所有后续使用都指向该起始帧。
fcount
- 帧数目,默认值0代表所有帧。
重要函数
inline const void* DicomImage::getOutputData(
const int bits = 0,
const unsigned long frame = 0,
const int planar = 0
)
render pixel data and return pointer to internal memory buffer.
apply VOI/PLUT transformation and (visible) overlay planes. internal memory buffer will be delete for the next getBitmap/Output operation. output data is always padded to 8, 16, 32, … bits (bits allocated). Supported output color models: Monochrome 2 for monochrome images and RGB (or YCbCr_Full if flag CIF_KeepYCbCrColorModel is set) for color images. The rendered pixel data is always unsigned.
Parameters:
bits
number of bits per sample used to render the pixel data (image depth, 1…MAX_BITS, 0 means ‘bits stored’ in the image) (MI_PastelColor = -1 for true color pastel mode, EXPERIMENTAL)
frame
number of frame to be rendered (0…n-1)
planar
0 = color-by-pixel (R1G1B1…R2G2B2…R3G3B3…), 1 = color-by-plane (R1R2R3…G1G2G3…B1B2B3…) (only applicable to multi-planar/color images, otherwise ignored)
Returns:
pointer to internal memory buffer containing rendered pixel data (if successful, NULL otherwise)
inline int DicomImage::getOutputData(
void * buffer,
const unsigned long size,
const int bits = 0,
const unsigned long frame = 0,
const int planar = 0
)
render pixel data and output to given memory buffer.
apply VOI/PLUT transformation and (visible) overlay planes. output data is always padded to 8, 16, 32, … bits (bits allocated). Supported output color models: Monochrome 2 for monochrome images and RGB (or YCbCr_Full if flag CIF_KeepYCbCrColorModel is set) for color images. The rendered pixel data is always unsigned.
Parameters:
buffer
pointer to memory buffer (must already be allocated)
size
size of memory buffer (will be checked whether it is sufficient)
bits
number of bits per sample used to render the pixel data (image depth, 1…MAX_BITS, 0 means ‘bits stored’ in the image) (MI_PastelColor = -1 for true color pastel mode, EXPERIMENTAL)
frame
number of frame to be rendered (0…n-1)
planar
0 = color-by-pixel (R1G1B1…R2G2B2…R3G3B3…), 1 = color-by-plane (R1R2R3…G1G2G3…B1B2B3…) (only applicable to multi-planar/color images, otherwise ignored)
Returns:
status code (true if successful)
inline unsigned long DicomImage::getOutputDataSize(const int bits = 0) const
get number of bytes required for the rendered output of a single frame.
This function determines the size of a rendered frame as created by getOutputData(). Therefore, it can be used to allocate a sufficiently large memory buffer and pass its size to the second variant of getOutputData().
Parameters:
bits
number of bits per sample used to render the pixel data (image depth, 1…MAX_BITS, 0 means ‘bits stored’ in the image) (MI_PastelColor = -1 for true color pastel mode, EXPERIMENTAL)
Returns:
number of bytes if successful, 0 otherwise
以上是关于DCMTK-dcmimage-向dcmigle添加对彩色图像的支持的主要内容,如果未能解决你的问题,请参考以下文章