【发布时间】:2021-02-19 07:12:02
【问题描述】:
我目前正在使用 DICOM 文件,而用于 DICOM 文件的 TensorFlow IO 库似乎会引发一些错误。所以我最初做的是这样的:
# read file bytes
image_bytes = tf.io.read_file(image_path)
# Convert to a tensor
image_as_tensor = tfio.image.decode_dicom_image(image_bytes, dtype=IMAGE_TYPE)
print(image_as_tensor.get_shape())
(1, 519, 519, 1)
无论如何,我决定用pydicom 加载DICOM 文件,这似乎可以将数据加载到numpy 数组中。然而,当我create a tensor from the data 时,我似乎无法获得正确的尺寸:
# read into dicom file
ds = pydicom.dcmread(image_path)
print(ds.pixel_array.shape)
# take pixel array, and lets create a tensor
image_as_tensor = tf.convert_to_tensor(ds.pixel_array, dtype=IMAGE_TYPE)
print(image_as_tensor.get_shape())
(519, 519)
最终,我确实希望程序的某些后续部分使用 (Z, X, Y, D) 格式,但不确定如何将 2D 张量放入该版本。
谢谢!
【问题讨论】:
-
X.reshape(1, x_shape, y_shape, 1)
标签: python numpy tensorflow