一、数据格式
1.1 dicomDICOM是医学图像中的标准文件,这些文件包含了诸多元数据信息(比如像素尺寸),此处以kaggle Data Science Bowl数据集为例:data-science-bowl-2017,数据列表如下:
后缀为 .dcm。
每个病人的一次扫描CT(scan)可能有几十到一百多个dcm数据文件(slices)。可以使用 python的dicom包读取,读取示例代码如下:
dicom.read_file('/data/lung_competition/stage1/7050f8141e92fa42fd9c471a8b2f50ce/498d16aa2222d76cae1da144ddc59a13.dcm')其pixl_array包含了真实数据。
slices = [dicom.read_file(os.path.join(folder_name,filename)) for filename in os.listdir(folder_name)]
slices = np.stack([s.pixel_array for s in slices])
1.2 mhd格式
一个raw通常有几百兆,对应的mhd文件只有1kb。mhd文件需要借助python的SimpleITK包来处理。SimpleITK 示例代码如下:
import SimpleITK as sitk
itk_img = sitk.ReadImage(img_file)
img_array = sitk.GetArrayFromImage(itk_img) # indexes are z,y,x (notice the ordering)
num_z, height, width = img_array.shape #heightXwidth constitute the transverse plane
origin = np.array(itk_img.GetOrigin()) # x,y,z Origin in world coordinates (mm)
spacing = np.array(itk_img.GetSpacing()) # spacing of voxels in world coor. (mm)
需要注意的是,SimpleITK的img_array的数组不是直接的像素值,而是相对于CT扫描中原点位置的差值,需要做进一步转换。
1.3 查看CT扫描文件软件一个开源免费的查看软件 mango
二 dicom格式数据处理过程
2.1 处理思路首先,需要明白的是医学扫描图像其实是三维图像,使用代码读取之后查看不同的切面的切片(slices),可以从不同轴切割。
如下图展示了一个病人CT扫描中,其中部分切片slices:
其次,CT扫描图是包含了所有组织的,如果直接去看,看不到任何有用的信息,需要做一些预处理,预处理中一个重要概念是仿射剂量,衡量单位为HU(Hounsfield Unit),下表是不同放射剂量对应的组织器官:
Hounsfield Unit = pixel_value * rescale_slope + rescale_intercept一般情况rescale slope = 1, intercept = -1024。
上表中肺部组织的HU数值为-500,但通常是大于这个值,比如-320、-400。挑选出这些区域,然后做其他变换抽取出肺部像素点。
2.2 先载入必要的包
# -*- coding:utf-8 -*-
'''
this script is used for basic process of lung 2017 in Data Science Bowl
'''
import glob
import os
import pandas as pd
import SimpleITK as sitk
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
import skimage, os
from skimage.morphology import ball, disk, dilation, binary_erosion, remove_small_objects, erosion, closing, reconstruction, binary_closing
from skimage.measure import label,regionprops, perimeter
from skimage.morphology import binary_dilation, binary_opening
from skimage.filters import roberts, sobel

本文介绍了医学图像处理中的CT扫描图像格式,包括DICOM和MHD,以及处理过程。首先,讲解了如何读取和处理DICOM文件,通过Python的dicom库获取像素数据,并进行切片厚度的补充。接着,讨论了CT图像从灰度值转换为HU单位的过程。此外,还介绍了使用SimpleITK库处理MHD格式文件的方法。预处理步骤包括重采样以达到同构分辨率、图像归一化以及坐标的转换。文章提供了数据可视化和3D重建的示例,以及对LUNA16数据集的处理方法。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



