פענוח קבצי DICOM להדמיה רפואית

הצג באתר TensorFlow.org הפעל בגוגל קולאב צפה במקור ב-GitHub הורד מחברת

סקירה כללית

מופעים הדרכה זו כיצד להשתמש tfio.image.decode_dicom_image ב TensorFlow IO לפענח DICOM קבצים עם TensorFlow.

הגדרה ושימוש

הורד תמונת DICOM

התמונה DICOM המשמש הדרכה זו היא מן הנתונים רנטגן חזה NIH .

מערך הנתונים של NIH חזה רנטגן מורכב 100,000 תמונות דה-מזוהה של צילומי רנטגן בפורמט PNG, שמספק המרכז הקליני NIH וניתן להוריד דרך הקישור הזה .

Google Cloud מספק גם גרסת DICOM של התמונות, זמינה לאחסון בענן .

במדריך זה, תוכלו להוריד קובץ מדגם של בסיס הנתונים מן ריפו GitHub

  • Xiaosong Wang, Yifan Peng, Le Lu, Zhiyong Lu, Mohammadhadi Bagheri, Ronald Summers, ChestX-ray8: מסד נתונים של רנטגן חזה בקנה מידה בית חולים ומדדים על סיווג ולוקליזציה בפיקוח חלש של מחלות חזה נפוצות, IEEE CVPR, עמ' 3462 -3471, 2017
curl -OL https://github.com/tensorflow/io/raw/master/docs/tutorials/dicom/dicom_00000001_000.dcm
ls -l dicom_00000001_000.dcm
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   164    0   164    0     0    600      0 --:--:-- --:--:-- --:--:--   598
100 1024k  100 1024k    0     0  1915k      0 --:--:-- --:--:-- --:--:-- 1915k
-rw-rw-r-- 1 kbuilder kokoro 1049332 Nov 22 03:47 dicom_00000001_000.dcm

התקן את החבילות הנדרשות והפעל מחדש את זמן הריצה

try:
  # Use the Colab's preinstalled TensorFlow 2.x
  %tensorflow_version 2.x 
except:
  pass
pip install tensorflow-io

פענוח תמונת DICOM

import matplotlib.pyplot as plt
import numpy as np

import tensorflow as tf
import tensorflow_io as tfio

image_bytes = tf.io.read_file('dicom_00000001_000.dcm')

image = tfio.image.decode_dicom_image(image_bytes, dtype=tf.uint16)

skipped = tfio.image.decode_dicom_image(image_bytes, on_error='skip', dtype=tf.uint8)

lossy_image = tfio.image.decode_dicom_image(image_bytes, scale='auto', on_error='lossy', dtype=tf.uint8)


fig, axes = plt.subplots(1,2, figsize=(10,10))
axes[0].imshow(np.squeeze(image.numpy()), cmap='gray')
axes[0].set_title('image')
axes[1].imshow(np.squeeze(lossy_image.numpy()), cmap='gray')
axes[1].set_title('lossy image');
2021-11-22 03:47:53.016507: E tensorflow/stream_executor/cuda/cuda_driver.cc:271] failed call to cuInit: CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected

png

פענוח DICOM Metadata ועבודה עם תגיות

decode_dicom_data מפענח מידע תג. dicom_tags מכיל מידע שימושי כמו גיל החולה ומין, כך שאתה יכול להשתמש DICOM תגיות כגון dicom_tags.PatientsAge ו dicom_tags.PatientsSex . tensorflow_io שאלו את אותו סימון תג מחבילת pydicom dicom.

tag_id = tfio.image.dicom_tags.PatientsAge
tag_value = tfio.image.decode_dicom_data(image_bytes,tag_id)
print(tag_value)
tf.Tensor(b'58', shape=(), dtype=string)
print(f"PatientsAge : {tag_value.numpy().decode('UTF-8')}")
PatientsAge : 58
tag_id = tfio.image.dicom_tags.PatientsSex
tag_value = tfio.image.decode_dicom_data(image_bytes,tag_id)
print(f"PatientsSex : {tag_value.numpy().decode('UTF-8')}")
PatientsSex : M