{
  "id": 358878,
  "title": "Issue when loading dicoms with TF I/O",
  "url": "/competitions/rsna-2022-cervical-spine-fracture-detection/discussion/358878",
  "author_name": "Francois Lemarchand",
  "post_date": "2022-10-10T01:02:52.179000",
  "votes": 1,
  "comment_count": 1,
  "views": 0,
  "content": "<p>Hi everyone!</p>\n<p>I am currently trying to train a model loading directly the data from the DICOM files using Tensorflow I/O and I am having issues with some of the files. It appears that, when using Tensorflow I/O, the PixelData array is empty for some files when it loads perfectly fine with <code>pydicom</code>.</p>\n<blockquote>\n  <p>image_bytes = tf.io.read_file('../input/rsna-2022-cervical-spine-fracture-detection/train_images/1.2.826.0.1.3680043.5133/189.dcm')<br>\n  image = tfio.image.decode_dicom_image(image_bytes, tfio.image.dicom_tags.PixelData)<br>\n  plt.imshow(np.squeeze(image.numpy()))<br>\n  plt.show()</p>\n</blockquote>\n<p>I haven't been able to figure out the main reason but it seems to affect all images from a same study. I would be super grateful if anyone had a suggestion!</p>",
  "messages": [
    {
      "id": 1980049,
      "postDate": "2022-10-10T01:02:52.180Z",
      "content": "<p>Hi everyone!</p>\n<p>I am currently trying to train a model loading directly the data from the DICOM files using Tensorflow I/O and I am having issues with some of the files. It appears that, when using Tensorflow I/O, the PixelData array is empty for some files when it loads perfectly fine with <code>pydicom</code>.</p>\n<blockquote>\n  <p>image_bytes = tf.io.read_file('../input/rsna-2022-cervical-spine-fracture-detection/train_images/1.2.826.0.1.3680043.5133/189.dcm')<br>\n  image = tfio.image.decode_dicom_image(image_bytes, tfio.image.dicom_tags.PixelData)<br>\n  plt.imshow(np.squeeze(image.numpy()))<br>\n  plt.show()</p>\n</blockquote>\n<p>I haven't been able to figure out the main reason but it seems to affect all images from a same study. I would be super grateful if anyone had a suggestion!</p>",
      "rawMarkdown": "Hi everyone!\n\nI am currently trying to train a model loading directly the data from the DICOM files using Tensorflow I/O and I am having issues with some of the files. It appears that, when using Tensorflow I/O, the PixelData array is empty for some files when it loads perfectly fine with `pydicom`.\n\n> image_bytes = tf.io.read_file('../input/rsna-2022-cervical-spine-fracture-detection/train_images/1.2.826.0.1.3680043.5133/189.dcm')\nimage = tfio.image.decode_dicom_image(image_bytes, tfio.image.dicom_tags.PixelData)\nplt.imshow(np.squeeze(image.numpy()))\nplt.show()\n\nI haven't been able to figure out the main reason but it seems to affect all images from a same study. I would be super grateful if anyone had a suggestion!",
      "votes": 1
    },
    {
      "id": 2066568,
      "postDate": "2022-12-15T20:38:42.603Z",
      "content": "<p><a href=\"https://www.kaggle.com/frlemarchand\" target=\"_blank\">@frlemarchand</a> <br>\nTry this </p>\n<pre><code>image_bytes = tf.io.read_file()\nimage = tfio.image.decode_dicom_image(image_bytes, dtype=tf.float32)\n</code></pre>\n<p>If you use <code>tf.uint8/16</code>, you might face empty data. Other types are ok (maybe, didn't check all.)</p>",
      "rawMarkdown": "@frlemarchand \nTry this \n\n```python\nimage_bytes = tf.io.read_file('file.dcm')\nimage = tfio.image.decode_dicom_image(image_bytes, dtype=tf.float32)\n```\nIf you use `tf.uint8/16`, you might face empty data. Other types are ok (maybe, didn't check all.)"
    }
  ],
  "comments": [
    {
      "id": 2066568,
      "author_name": "Innat",
      "author_url": "",
      "post_date": "2022-12-15T20:38:42.603000",
      "content": "<p><a href=\"https://www.kaggle.com/frlemarchand\" target=\"_blank\">@frlemarchand</a> <br>\nTry this </p>\n<pre><code>image_bytes = tf.io.read_file()\nimage = tfio.image.decode_dicom_image(image_bytes, dtype=tf.float32)\n</code></pre>\n<p>If you use <code>tf.uint8/16</code>, you might face empty data. Other types are ok (maybe, didn't check all.)</p>",
      "votes": 0,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1980049": "Hi everyone!\n\nI am currently trying to train a model loading directly the data from the DICOM files using Tensorflow I/O and I am having issues with some of the files. It appears that, when using Tensorflow I/O, the PixelData array is empty for some files when it loads perfectly fine with `pydicom`.\n\n> image_bytes = tf.io.read_file('../input/rsna-2022-cervical-spine-fracture-detection/train_images/1.2.826.0.1.3680043.5133/189.dcm')\nimage = tfio.image.decode_dicom_image(image_bytes, tfio.image.dicom_tags.PixelData)\nplt.imshow(np.squeeze(image.numpy()))\nplt.show()\n\nI haven't been able to figure out the main reason but it seems to affect all images from a same study. I would be super grateful if anyone had a suggestion!",
    "2066568": "@frlemarchand \nTry this \n\n```python\nimage_bytes = tf.io.read_file('file.dcm')\nimage = tfio.image.decode_dicom_image(image_bytes, dtype=tf.float32)\n```\nIf you use `tf.uint8/16`, you might face empty data. Other types are ok (maybe, didn't check all.)"
  }
}