本篇文章对应的DICOM原理部分,在专栏从零讲解DICOM协议-成像协议的文章DICOM图像CT值计算和DICOM图像CT值转RGB,建议先了解原理,有助于理清代码思路。
dcmimgle模块提供处理DICOM 单色图像的类。模块dcmimage提供对彩色图像的支持。dcmjpeg模块提供了对 JPEG 压缩图像的支持。因此如果要获取压缩图像的像素数据,需要先用dcmjpeg模块解压,再用dcmimgle模块读取像素数据。
要显示DICOM图像,首先要正确获取像素数据,DCMTK有三种方式获取像素数据:
原理部分讲过,要将12位灰阶的CT值转换为普通显示器能显示的8位灰阶的灰度值,要进行如下几步:
以上三个dcmtk方法,分别对应三种像素计算方式。
通过手动计算,原点像素的像素值为0,CT值为-1028,灰度值为63。
下面进行详细分析:
dcmtk对getOutputData和getInterData函数描述如下
/** 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.
*
** @param 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)
* @param frame number of frame to be rendered (0..n-1)
* @param planar 0 = color-by-pixel (R1G1B1...R2G2B2...R3G3B3...),
* 1 = color-by-plane (R1R2R3...G1G2G3...B1B2B3...)
* (only applicable to multi-planar/color images, otherwise ignored)
*
** @return pointer to internal memory buffer containing rendered pixel data
* (if successful, NULL otherwise)
*/
inline const void *getOutputData(const int bits = 0,
const unsigned long frame = 0,
const int planar = 0)
/** get intermediate pixel data representation (read-only).
* This function allows to access the pixel data after they have been extracted
* from the DICOM data element and the modality transformation has been applied
* (if present and not disabled). Please note that for monochrome images the
* internal representation might be signed whereas color images are automatically
* converted to unsigned RGB format. Pixels are aligned to 8, 16 or 32 bits.
* Always use DiPixel::getRepresentation() in order to determine the integer
* representation of the internally stored pixel data.
*
** @return pointer to intermediate pixel data representation
*/
inline const DiPixel *getInterData()
getInterData函数描述较清晰,说明了输出数据是基于PixelData和转换函数转换后的数据,且monochrome images(灰阶图像,如CT)为有符号或无符号数据, color images(彩色图像ÿ