1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| 窗宽指CT图像所显示的CT 值范围,在此CT值范围内的组织和病变均以不 同的模拟灰度显示窗位(窗中心)指窗宽范围内均值或中心值,如果窗宽 为100Hu,当窗位为中心 0Hu,则CT值的范围为-50Hu ~ +50Hu;当窗位 为中心 +35Hu,则CT值的范围为-15Hu ~ +85Hu; def infer_tumorandliver(model, ct_array_nor, cube_shape=(129, 512, 512)): patch_size = cube_shape patch_stride = [60, 256, 256]
locations, image_shape = generate_test_locations(ct_array_nor, patch_size, patch_stride) print('location', locations, image_shape)
image = np.zeros((1,) + (ct_array_nor.shape)).astype(np.float32) seg = np.zeros((ct_array_nor.shape)).astype(np.float32)
print('image shape', image.shape)
for z in range(0, locations[0]): zs = min(patch_stride[0] * z, image_shape[0] - patch_size[0]) for x in range(0, locations[1]): xs = min(patch_stride[1] * x, image_shape[1] - patch_size[1]) for y in range(0, locations[2]): ys = min(patch_stride[2] * y, image_shape[2] - patch_size[2])
patch = ct_array_nor[zs:zs + patch_size[0], xs:xs + patch_size[1], ys:ys + patch_size[2]] patch = np.expand_dims(np.expand_dims(patch, axis=0), axis=0).astype(np.float32)
patch_tensor = torch.from_numpy(patch).cuda() output = patch_tensor.cpu().data.numpy()
image[:, zs:zs + patch_size[0], xs:xs + patch_size[1], ys:ys + patch_size[2]] \ = image[:, zs:zs + patch_size[0], xs:xs + patch_size[1], ys:ys + patch_size[2]] + output[0, 0, :, :, :]
seg[zs:zs + patch_size[0], xs:xs + patch_size[1], ys:ys + patch_size[2]] \ = seg[zs:zs + patch_size[0], xs:xs + patch_size[1], ys:ys + patch_size[2]] + 1
image = image / np.expand_dims(seg, axis=0)
image = np.squeeze(image) image[image<50] = 0 image[image>400] =400 mask_pred_containers = image
return mask_pred_containers
|