The NIH Chest X-ray dataset consists of 100,000 de-identified images of chest x-rays in PNG format, provided by NIH Clinical Center and could be downloaded through this link.
Google Cloud also provides a DICOM version of the images, available in Cloud Storage.
In this tutorial, you will download a sample file of the dataset from the GitHub repo
Xiaosong Wang, Yifan Peng, Le Lu, Zhiyong Lu, Mohammadhadi Bagheri, Ronald Summers, ChestX-ray8: Hospital-scale Chest X-ray Database and Benchmarks on Weakly-Supervised Classification and Localization of Common Thorax Diseases, IEEE CVPR, pp. 3462-3471, 2017
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
Decode DICOM Metadata and working with Tags
decode_dicom_data decodes tag information. dicom_tags contains useful information as the patient's age and sex, so you can use DICOM tags such as dicom_tags.PatientsAge and dicom_tags.PatientsSex. tensorflow_io borrow the same tag notation from the pydicom dicom package.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2022-01-10 UTC."],[],[],null,["# Decode DICOM files for medical imaging\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------|\n| [View on TensorFlow.org](https://www.tensorflow.org/io/tutorials/dicom) | [Run in Google Colab](https://colab.research.google.com/github/tensorflow/io/blob/master/docs/tutorials/dicom.ipynb) | [View source on GitHub](https://github.com/tensorflow/io/blob/master/docs/tutorials/dicom.ipynb) | [Download notebook](https://storage.googleapis.com/tensorflow_docs/io/docs/tutorials/dicom.ipynb) |\n\nOverview\n--------\n\nThis tutorial shows how to use [`tfio.image.decode_dicom_image`](https://www.tensorflow.org/io/api_docs/python/tfio/image/decode_dicom_image) in TensorFlow IO to decode DICOM files with TensorFlow.\n\nSetup and Usage\n---------------\n\n#### Download DICOM image\n\nThe DICOM image used in this tutorial is from the [NIH Chest X-ray dataset](https://cloud.google.com/healthcare/docs/resources/public-datasets/nih-chest).\n\nThe NIH Chest X-ray dataset consists of 100,000 de-identified images of chest x-rays in PNG format, provided by NIH Clinical Center and could be downloaded through [this link](https://nihcc.app.box.com/v/ChestXray-NIHCC).\n\nGoogle Cloud also provides a DICOM version of the images, available in [Cloud Storage](https://cloud.google.com/healthcare/docs/resources/public-datasets/nih-chest).\n\nIn this tutorial, you will download a sample file of the dataset from the [GitHub repo](https://github.com/tensorflow/io/raw/master/docs/tutorials/dicom/dicom_00000001_000.dcm)\n| **Note:** For more information about the dataset, please find the following reference:\n\n- Xiaosong Wang, Yifan Peng, Le Lu, Zhiyong Lu, Mohammadhadi Bagheri, Ronald Summers, ChestX-ray8: Hospital-scale Chest X-ray Database and Benchmarks on Weakly-Supervised Classification and Localization of Common Thorax Diseases, IEEE CVPR, pp. 3462-3471, 2017\n\n curl -OL https://github.com/tensorflow/io/raw/master/docs/tutorials/dicom/dicom_00000001_000.dcm\n ls -l dicom_00000001_000.dcm\n\n```\n% Total % Received % Xferd Average Speed Time Time Time Current\n Dload Upload Total Spent Left Speed\n100 164 0 164 0 0 600 0 --:--:-- --:--:-- --:--:-- 598\n100 1024k 100 1024k 0 0 1915k 0 --:--:-- --:--:-- --:--:-- 1915k\n-rw-rw-r-- 1 kbuilder kokoro 1049332 Nov 22 03:47 dicom_00000001_000.dcm\n```\n\n### Install required Packages, and restart runtime\n\n try:\n # Use the Colab's preinstalled TensorFlow 2.x\n %tensorflow_version 2.x \n except:\n pass\n\n pip install tensorflow-io\n\n### Decode DICOM image\n\n import matplotlib.pyplot as plt\n import numpy as np\n\n import tensorflow as tf\n\n import tensorflow_io as tfio\n\n image_bytes = tf.io.read_file('dicom_00000001_000.dcm')\n\n image = tfio.image.decode_dicom_image(image_bytes, dtype=tf.uint16)\n\n skipped = tfio.image.decode_dicom_image(image_bytes, on_error='skip', dtype=tf.uint8)\n\n lossy_image = tfio.image.decode_dicom_image(image_bytes, scale='auto', on_error='lossy', dtype=tf.uint8)\n\n\n fig, axes = plt.subplots(1,2, figsize=(10,10))\n axes[0].imshow(np.squeeze(image.numpy()), cmap='gray')\n axes[0].set_title('image')\n axes[1].imshow(np.squeeze(lossy_image.numpy()), cmap='gray')\n axes[1].set_title('lossy image');\n\n```\n2021-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\n```\n\n### Decode DICOM Metadata and working with Tags\n\n`decode_dicom_data` decodes tag information. `dicom_tags` contains useful information as the patient's age and sex, so you can use DICOM tags such as [`dicom_tags.PatientsAge`](https://www.tensorflow.org/io/api_docs/python/tfio/image/dicom_tags#PatientsAge) and [`dicom_tags.PatientsSex`](https://www.tensorflow.org/io/api_docs/python/tfio/image/dicom_tags#PatientsSex). tensorflow_io borrow the same tag notation from the pydicom dicom package. \n\n tag_id = tfio.image.dicom_tags.PatientsAge\n tag_value = tfio.image.decode_dicom_data(image_bytes,tag_id)\n print(tag_value)\n\n```\ntf.Tensor(b'58', shape=(), dtype=string)\n``` \n\n print(f\"PatientsAge : {tag_value.numpy().decode('UTF-8')}\")\n\n```\nPatientsAge : 58\n``` \n\n tag_id = tfio.image.dicom_tags.PatientsSex\n tag_value = tfio.image.decode_dicom_data(image_bytes,tag_id)\n print(f\"PatientsSex : {tag_value.numpy().decode('UTF-8')}\")\n\n```\nPatientsSex : M\n```"]]