2 回答
TA贡献1818条经验 获得超11个赞
有一个 Tensorflow-io 包现在允许这样做。它相当简单。
安装包:
pip install -q tensorflow-io
import tensorflow_io as tfio
def load_and_preprocess_image(img_path):
_bytes = tf.io.read_file(img_path)
dicom_data = tfio.image.decode_dicom_image(_bytes, dtype=tf.float32)
return dicom_data
dicom_files_list = ['path/to/dicom']
# Create dataset (list of strings that lead to dicom paths)
image_train_ds = tf.data.Dataset.from_tensor_slices(dicom_files_list)
image_train_ds = image_train_ds.map(load_and_preprocess_image)
TA贡献1818条经验 获得超8个赞
在 中pydicom.dcmread(img_path),img_path是 tf.string 张量。我不认为pydicom支持读取张量对象。
我找到了一种解决方法,它是在 tensorflow 中提供 DICOM 操作的 gradient_decode_dicom 。以下代码改编自此 colab,并在 tf2.0 上进行了测试。
def load_and_preprocess_image(img_path):
_bytes = tf.io.read_file(img_path)
dicom_data = decode_dicom_image(_bytes, dtype=tf.float32)
return dicom_data
dicom_files_list = ['path/to/dicom']
# Create dataset (list of strings that lead to dicom paths)
image_train_ds = tf.data.Dataset.from_tensor_slices(dicom_files_list)
image_train_ds = image_train_ds.map(load_and_preprocess_image)
添加回答
举报
