DICOM头信息示例如下:
(0002,0000) Group Length VR: UL Length: 4 Value: 184
(0002,0001) File Meta Information Version VR: OB Length: 2 Value: 0
(0002,0002) Media Storage SOP Class UID VR: UI Length: 26 Value:
(0002,0003) Media Storage SOP Instance UID VR: UI Length: 54 Value:
(0002,0010) Transfer Syntax UID VR: UI Length: 18 Value:
(0002,0012) Implementation Class UID VR: UI Length: 24 Value:
(0002,0013) Implementation Version Name VR: SH Length: 8 Value: DCIE 2.2
(0008,0005) Specific Character Set VR: CS Length: 10 Value: ISO_IR 192
(0008,0008) Image Type VR: CS Length: 22 Value: ORIGINAL\PRIMARY\AXIAL
(0008,0012) Instance Creation Date VR: DA Length: 8 Value: 20181115
(0008,0013) Instance Creation Time VR: TM Length: 6 Value: 151330
(0008,0016) SOP Class UID VR: UI Length: 26 Value:
(0008,0018) SOP Instance UID VR: UI Length: 54 Value: 1.2.840.113619.2.278.3.346865037.388.1539042181.XXX.XX
(0008,0020) Study Date VR: DA Length: 8 Value: 20181009
(0008,0021) Series Date VR: DA Length: 8 Value: 20181009
(0008,0022) Acquisition Date VR: DA Length: 8 Value: 20181009
(0008,0023) Image Date VR: DA Length: 8 Value: 20181009
(0008,0030) Study Time VR: TM Length: 6 Value: 111141
(0008,0031) Series Time VR: TM Length: 6 Value: 111308
(0008,0032) Acquisition Time VR: TM Length: 10 Value: 111515.407
(0008,0033) Image Time VR: TM Length: 6 Value: 111520
(0008,0050) Accession Number VR: SH Length: 0
(0008,0060) Modality VR: CS Length: 2 Value: CT
(0008,0070) Manufacturer VR: LO Length: 18 Value: GE MEDICAL SYSTEMS
(0008,0080) Institution Name VR: LO Length: 26 Value:
(0008,0090) Referring Physician's Name VR: PN Length: 8 Value:
(0008,1010) Station Name VR: SH Length: 4 Value: rtct
(0008,1030) Study Description VR: LO Length: 2 Value: HN
(0008,103E) Series Description VR: LO Length: 12 Value: CHEST 2.5 MM
(0008,1048) Physician(s) of Record VR: PN Length: 14 Value:
(0008,1070) Operators' Name VR: PN Length: 14 Value:
(0008,1090) Manufacturer's Model Name VR: LO Length: 18 Value: Discovery CT590 RT
(0008,1140) Referenced Image Sequence VR: SQ Length: 104
(FFFE,E000)
(0008,1150) Referenced SOP Class UID VR: UI Length: 26 Value:
(0008,1155) Referenced SOP Instance UID VR: UI Length: 54 Value:
(0008,3010) Irradiation Event UID VR: UI Length: 52 Value:
(0010,0010) Patient's Name VR: PN Length: 14 Value:
(0010,0020) Patient ID VR: LO Length: 8 Value: XXXXX
(0010,0030) Patient's Birth Date VR: DA Length: 8 Value:
(0010,0032) Patient's Birth Time VR: TM Length: 6 Value:
(0010,0040) Patient's Sex VR: CS Length: 2 Value:
(0018,0022) Scan Options VR: CS Length: 12 Value: HELICAL MODE
(0018,0050) Slice Thickness VR: DS Length: 4 Value: 2.5
(0018,0060) KVP VR: DS Length: 4 Value: 120
(0018,0090) Data Collection Diameter VR: DS Length: 4 Value: 500
(0018,1000) Device Serial Number VR: LO Length: 2 Value: *
(0018,1020) Software Version(s) VR: LO Length: 10 Value: rt_bjcl.35
(0018,1100) Reconstruction Diameter VR: DS Length: 4 Value: 650
(0018,1110) Distance Source to Detector VR: DS Length: 8 Value: 1062.55
(0018,1111) Distance Source to Patient VR: DS Length: 8 Value: 605.945
(0018,1120) Gantry/Detector Tilt VR: DS Length: 2 Value: 0
(0018,1130) Table Height VR: DS Length: 4 Value: 174
(0018,1140) Rotation Direction VR: CS Length: 2 Value: CW
(0018,1150) Exposure Time VR: IS Length: 4 Value: 856
(0018,1151) X-Ray Tube Current VR: IS Length: 2 Value: 99
(0018,1152) Exposure VR: IS Length: 2 Value: 13
(0018,1160) Filter Type VR: SH Length: 12 Value: BODY FILTER
(0018,1170) Generator Power VR: IS Length: 6 Value: 84000
(0018,1190) Focal Spot(s) VR: DS Length: 4 Value: 1.2
(0018,1210) Convolution Kernel VR: SH Length: 8 Value: STANDARD
(0018,5100) Patient Position VR: CS Length: 4 Value: HFS
(0020,000D) Study Instance UID VR: UI Length: 52 Value: 1.2.840.113619.2.278.3.346865037.388.15390421XX.XXX
(0020,000E) Series Instance UID VR: UI Length: 52 Value: 1.2.840.113619.2.278.3.346865037.388.15390421XX.XXX
(0020,0010) Study ID VR: SH Length: 6 Value: XXXXX
(0020,0011) Series Number VR: IS Length: 2 Value: 2
(0020,0012) Acquisition Number VR: IS Length: 2 Value: 1
(0020,0013) Image Number VR: IS Length: 2 Value: 19
(0020,0032) Image Position (Patient) VR: DS Length: 16 Value: -325\-325\157.5
(0020,0037) Image Orientation (Patient) VR: DS Length: 12 Value: 1\0\0\0\1\0
(0020,0052) Frame of Reference UID VR: UI Length: 60 Value:
(0020,1040) Position Reference Indicator VR: LO Length: 0
(0020,1041) Slice Location VR: DS Length: 6 Value: 157.5
(0028,0002) Samples per Pixel VR: US Length: 2 Value: 1
(0028,0004) Photometric Interpretation VR: CS Length: 12 Value: MONOCHROME2
(0028,0010) Rows VR: US Length: 2 Value: 512
(0028,0011) Columns VR: US Length: 2 Value: 512
(0028,0030) Pixel Spacing VR: DS Length: 18 Value: 1.269531\1.269531
(0028,0100) Bits Allocated VR: US Length: 2 Value: 16
(0028,0101) Bits Stored VR: US Length: 2 Value: 16
(0028,0102) High Bit VR: US Length: 2 Value: 15
(0028,0103) Pixel Representation VR: US Length: 2 Value: 1
(0028,1050) Window Center VR: DS Length: 2 Value: 40
(0028,1051) Window Width VR: DS Length: 4 Value: 400
(0028,1052) Rescale Intercept VR: DS Length: 6 Value: -1000
(0028,1053) Rescale Slope VR: DS Length: 2 Value: 1
(0028,1054) Rescale Type VR: LO Length: 2 Value: HU
1,CT值
CT图像的CT 值反映组织对X 射线吸收值(衰减系数u),其单位为Hounsfield Unit(Hu),以水的衰减系数为参照(即水的CT 值为0);物质衰减系数大于水者为正值,小于水者为负值;并以骨皮质和空气的衰减系数为上限和下限,定为+1000 和-1000。
一般CT图像是经过量化后的灰度图像,标准的CT 灰度图像为12 位灰度图象。
获取CT值的公式位 Rescale slope∗pixelValue+Rescale intercept,其中pixelValue是从dicom文件中读取的像素值,得到CT值然后根据窗宽窗位过滤,过滤后得到的图像将凸显出所关注的目标组织。
2,截距,Rescale intercept (0028|1052) ,斜率,Rescale slope (0028|1053)
CT图像的像素值是用Hounsfield单位来测量的,而Hounsfield单位可以是负值,而CT图像的像素值通常存储为无符号整数。因此CT DICOM文件通常具有负截距。
对于线性缩放同样适用,一个像素可能有一个大范围的值,而存储的值需要占用尽可能少的bit,同时避免量化错误,这通常应用于PET成像,在PET成像中,所测量的活度值的范围可能超过小整数。
此外PET的最大活性可能因切片而异,例如与健康组织切片相比,带有肿瘤的切片可能具有很高的值。由于这个原因,Rescale intercept/Rescale slope在一个PET图像系列的切片基础上经常变化。
所以针对CT和PET,需要将实际值利用斜率和截距进行线性变换然后存储到DICOM文件中,其他情况斜率默认为1,截距默认为0。
3,DCM_PixelRepresentation
像素数据的存储类型,0代表无符号存储,1代表有符号存储
4,DCM_BitsAllocated
存储一个像素分配的bit数
4,DCM_BitsStored
DCM_BitsAllocated中的有效存储位,即有效数据所占字节长度
5,DCM_SamplesPerPixel
像素采样率,1表示灰度图,3表示彩色图
6,窗宽窗位
CT等放射医学影像常有窗宽(Window Width,简写WW)窗位(Window Level,简写WL)的转换。常规显示器颜色位深是8bit,彩色显示器是RGB每通道位深8bit,而医学图像通常是10~12bit(通常用16bit的变量类型表示)。
因此即使不做窗宽窗位转换也需要将10~12bit的数据映射到8bit来显示(显示器是彩色,则灰度图像的话每通道颜色一样即可)。
常见人体组织的CT值(HU):
组织 CT值 组织 CT值
骨组织 >400 肝脏 50~70
钙值 80~300 脾脏 35~60
血块 64~84 胰腺 30~55
脑白质 25~34 肾脏 25~50
脑灰质 28~44 肌肉 40~55
脑脊液 3~8 胆囊 10~30
血液 13~32 甲状腺 50~90
血浆 3~14 脂肪 -20~-100
渗出液 >15 水 0
1、胸部CT检查时,肺窗纵膈窗窗宽、窗位分别是:
(1)肺窗WW1500—2000HU 、WL-450—-600HU
(2)纵膈窗WW250—350HU、WL30—50HU
2、骨窗、软组织窗窗宽、窗位
(1)骨窗WW1000—1500HU、WL250—350HU
(2)软组织窗WW300—500HU、WL40—60HU
假设要将CT图中的某组织在显示器上凸显出来,且该组织的WW为400,WL为60,则该组织对应的CT值范围为-140~260,其中WW为400,表示以0为界限,-200~200,WL为60,表示偏移60,得到-140~260。
从dicom文件中解析出像素数据,计算出原始CT值,然后根据WW和WL过滤,将过滤后的像素值归一化,然后通过opencv显示图片
7,使用DCMTK解压DICOM
根据DCM_TransferSyntaxUID得到dicom的传输语法,然后进行解压,代码如下
void DcmParse::Decompress(DcmDataset* dataset, const char* transferSyntax)
{
std::string losslessTransUID = "1.2.840.10008.1.2.4.70";
std::string lossTransUID = "1.2.840.10008.1.2.4.51";
std::string losslessP14 = "1.2.840.10008.1.2.4.57";
std::string lossyP1 = "1.2.840.10008.1.2.4.50";
std::string lossyRLE = "1.2.840.10008.1.2.5";
E_TransferSyntax xfer = dataset->getOriginalXfer();
if (transferSyntax == losslessTransUID || transferSyntax == lossTransUID ||
transferSyntax == losslessP14 || transferSyntax == lossyP1)
{
DJDecoderRegistration::registerCodecs();
dataset->chooseRepresentation(EXS_LittleEndianExplicit, NULL);
DJDecoderRegistration::cleanup();
}
else if (transferSyntax == lossyRLE)
{
DcmRLEDecoderRegistration::registerCodecs();
dataset->chooseRepresentation(EXS_LittleEndianExplicit, NULL);
DcmRLEDecoderRegistration::cleanup();
}
else
{
dataset->chooseRepresentation(xfer, NULL);
}
}
如果要使用DicomImage类,则可以(xfer为传输语法):
DicomImage* dcmImage = new DicomImage((DcmObject*)dataset, xfer);
根据dicom路径获得像素数据代码如下:
DcmFileFormat fileformat;
OFCondition oc = fileformat.loadFile(dcmPath.c_str());
if (!oc.good()) {
return FILE_NOT_GOOD;
}
const char* transferSyntax = NULL;
DcmDataset* dataset = fileformat.getDataset();
//获取传输语义
fileformat.getMetaInfo()->findAndGetString(DCM_TransferSyntaxUID, transferSyntax);
std::cout << "transferSyntax is " << transferSyntax << std::endl;
//解压
Decompress(dataset, transferSyntax);
//判断文件是否损坏
DcmElement* element = NULL;
OFCondition result = dataset->findAndGetElement(DCM_PixelData, element);
if (result.bad() || element == NULL) {
return PIXEL_DATA_IS_BAD;
}
//dataset根据dicom的通道数以及数据存储位数获取,略