所以我预处理了一些 dicom 图像来输入神经网络,在图像增强步骤中,图像数据生成器需要 4d 输入,而我的数据是 3d (200, 420, 420)
我尝试重塑数组并扩展尺寸,但在这两种情况下,我都无法绘制数组中的各个图像(期望形状为 420, 420 的图像,而我的新图像的形状为 420, 420, 1)
这是我的代码;
我有三个函数可以将 DICOM 图像转换为对比度良好的图像;
这个需要 housefield 单位
def transform_to_hu(medical_image, image):
intercept = medical_image.RescaleIntercept
slope = medical_image.RescaleSlope
hu_image = image * slope + intercept
return hu_image
Run Code Online (Sandbox Code Playgroud)
这设置了窗口图像值;
def window_image(image, window_center, window_width):
img_min = window_center - window_width // 2
img_max = window_center + window_width // 2
window_image = image.copy()
window_image[window_image < img_min] = img_min
window_image[window_image > img_max] = img_max
return window_image
Run Code Online (Sandbox Code Playgroud)
这个函数加载图像:
def load_image(file_path):
medical_image = …Run Code Online (Sandbox Code Playgroud)