print(dcm_itk.GetPixel(0, 0, 0)) # -1024 unscaled, raw data
data_itk = itk.GetArrayFromImage(dcm_itk)
print(data_itk) # -1024,unscaled, raw data
print(pydicom.dcmread(dcm_file).pixel_array) # == data_itk,unscaled, raw data
复制代码
dicom转化为hu的示例代码
如下:
def get_pixels_hu(scans):
#type(scans[0].pixel_array)
#Out[15]: numpy.ndarray
#scans[0].pixel_array.shape
#Out[16]: (512, 512)
# image.shape: (129,512,512)
image = np.stack([s.pixel_array for s in scans])
# Convert to int16 (from sometimes int16),
# should be possible as values should always be low enough (<32k)
image = image.astype(np.int16)
# Set outside-of-scan pixels to 1
# The intercept is usually -1024, so air is approximately 0
image[image == -2000] = 0
# Convert to Hounsfield units (HU)
intercept = scans[0].RescaleIntercept
slope = scans[0].RescaleSlope
if slope != 1:
image = slope * image.astype(np.float64)
image = image.astype(np.int16)
image += np.int16(intercept)
return np.array(image, dtype=np.int16)
复制代码
windowing
然而,hu的范围一般来说很大,这就导致了对比度很差,如果需要针对具体的器官进行处理,效果会不好,于是就有了windowing的方法:
Windowing, also known as grey-level mapping, contrast stretching, histogram modification or contrast enhancement is the process in which the CT image greyscale component of an image is manipulated via the CT numbers; doing this will change the appearance of the picture to highlight particular structures. The brightness of the image is, adjusted via the window level. The contrast is adjusted via the window width. 图像的亮度取决于window level,图像的对比度取决于window width。
Window width
The window width (WW) as the name suggests is the measure of the range of CT numbers that an image contains.
窗口宽度就是一幅ct图片包含的ct值范围。
A wider window width (2000 HU), therefore, will display a wider range of CT numbers. Consequently, the transition of dark to light structures will occur over a larger transition area to that of a narrow window width (<1000 HU).
更宽的窗口,相对于窄的窗口来说,从暗到亮的结构过度将会在发生在更大的过度区域。
Accordingly, it is important to note, that a significantly wide window displaying all the CT numbers will result in different attenuations between soft tissues to become obscured.
因此,一个展示了所有ct值的宽窗口,将导致软组织间不同的ct值变得模糊。
Wide window
Defined as 400-2000 HU best used in areas of acute differing attenuation values, a good example is lungs or cortical tissue, where air and vessels will sit side by side.
宽窗口经常用于ct值变化很大的领域,比如肺部或外皮组织,这些地方空气和血管将会一同出现。
Narrow window
Defined as 50-350 HU are excellent when examining areas of similar attenuation, for example, soft tissue.
窄的窗口常用于ct值相似的区域,例如软组织。
Window level/center
The window level (WL), often also referred to as window center, is the midpoint of the range of the CT numbers displayed.
窗口水平,也经常成为窗口中心,是ct值的中点。
When the window level is decreased the CT image will be brighter and vice versa.
窗口level减少,图片将变亮,level增大,图片变暗。
Upper and lower grey level calculation
When presented with a WW and WL one can calculate the upper and lower grey levels i.e. values over x will be white and values below y will be black.
当给定了window width和window level后,就能计算出窗口的上下界。
超过上界的,是白色,低于下界的,是黑色。
下面是计算方法和举例。
the upper grey level (x) is calculated via WL + (WW ÷ 2)
the lower grey level (y) is calculated via WL - (WW ÷ 2)
For example, a brain is W:80 L:40, therefore, all values above +80 will be white and all values below 0 are black.
windowing代码