{
  "id": 31558,
  "title": "Corrupted EXIF data?",
  "url": "/competitions/intel-mobileodt-cervical-cancer-screening/discussion/31558",
  "author_name": "",
  "post_date": "2017-04-13T08:54:30.984002700Z",
  "votes": 3,
  "comment_count": 5,
  "views": 0,
  "content": "<p>I'm trying to load the images with Python2 (I'm using <code>scipy.misc.imread</code> function if that matters). In case of some images a warning like this is printed:</p>\n\n<pre><code>/home/grzegorz/PycharmProjects/Environments/std/local/lib/python2.7/site-packages/PIL/TiffImagePlugin.py:692: UserWarning: Possibly corrupt EXIF data.  Expecting to read 524288 bytes but only got 0. Skipping tag 3\n  \"Skipping tag %s\" % (size, len(data), tag))\n/home/grzegorz/PycharmProjects/Environments/std/local/lib/python2.7/site-packages/PIL/TiffImagePlugin.py:692: UserWarning: Possibly corrupt EXIF data.  Expecting to read 393216 bytes but only got 0. Skipping tag 3\n  \"Skipping tag %s\" % (size, len(data), tag))\n/home/grzegorz/PycharmProjects/Environments/std/local/lib/python2.7/site-packages/PIL/TiffImagePlugin.py:692: UserWarning: Possibly corrupt EXIF data.  Expecting to read 33554432 bytes but only got 0. Skipping tag 4\n  \"Skipping tag %s\" % (size, len(data), tag))\n⋮\n</code></pre>\n\n<p>Did you also have this problem? If yes, how did you handle it?</p>",
  "messages": [
    {
      "id": "174941",
      "postDate": "04/13/2017 08:54:30",
      "content": "<p>I'm trying to load the images with Python2 (I'm using <code>scipy.misc.imread</code> function if that matters). In case of some images a warning like this is printed:</p>\n\n<pre><code>/home/grzegorz/PycharmProjects/Environments/std/local/lib/python2.7/site-packages/PIL/TiffImagePlugin.py:692: UserWarning: Possibly corrupt EXIF data.  Expecting to read 524288 bytes but only got 0. Skipping tag 3\n  \"Skipping tag %s\" % (size, len(data), tag))\n/home/grzegorz/PycharmProjects/Environments/std/local/lib/python2.7/site-packages/PIL/TiffImagePlugin.py:692: UserWarning: Possibly corrupt EXIF data.  Expecting to read 393216 bytes but only got 0. Skipping tag 3\n  \"Skipping tag %s\" % (size, len(data), tag))\n/home/grzegorz/PycharmProjects/Environments/std/local/lib/python2.7/site-packages/PIL/TiffImagePlugin.py:692: UserWarning: Possibly corrupt EXIF data.  Expecting to read 33554432 bytes but only got 0. Skipping tag 4\n  \"Skipping tag %s\" % (size, len(data), tag))\n⋮\n</code></pre>\n\n<p>Did you also have this problem? If yes, how did you handle it?</p>",
      "rawMarkdown": "I'm trying to load the images with Python2 (I'm using `scipy.misc.imread` function if that matters). In case of some images a warning like this is printed:\n\n    /home/grzegorz/PycharmProjects/Environments/std/local/lib/python2.7/site-packages/PIL/TiffImagePlugin.py:692: UserWarning: Possibly corrupt EXIF data.  Expecting to read 524288 bytes but only got 0. Skipping tag 3\n      \"Skipping tag %s\" % (size, len(data), tag))\n    /home/grzegorz/PycharmProjects/Environments/std/local/lib/python2.7/site-packages/PIL/TiffImagePlugin.py:692: UserWarning: Possibly corrupt EXIF data.  Expecting to read 393216 bytes but only got 0. Skipping tag 3\n      \"Skipping tag %s\" % (size, len(data), tag))\n    /home/grzegorz/PycharmProjects/Environments/std/local/lib/python2.7/site-packages/PIL/TiffImagePlugin.py:692: UserWarning: Possibly corrupt EXIF data.  Expecting to read 33554432 bytes but only got 0. Skipping tag 4\n      \"Skipping tag %s\" % (size, len(data), tag))\n    ⋮\n\nDid you also have this problem? If yes, how did you handle it?",
      "votes": null
    },
    {
      "id": "174988",
      "postDate": "04/13/2017 11:51:52",
      "content": "<p>I did have the same problem using PIL... managed to read some of the image's EXIF data with ExifRead python package though...</p>",
      "rawMarkdown": "I did have the same problem using PIL... managed to read some of the image's EXIF data with ExifRead python package though...",
      "votes": null
    },
    {
      "id": "175519",
      "postDate": "04/15/2017 21:53:31",
      "content": "<p>I ran into this as well. Probably the easiest fix is just to remove the EXIF data. You can delete the EXIF data with:</p>\n\n<pre><code>jhead -de *.jpg\n</code></pre>\n\n<p>You can also generate new EXIF data with:</p>\n\n<pre><code>jhead -mkexif *.jpg\n</code></pre>",
      "rawMarkdown": "I ran into this as well. Probably the easiest fix is just to remove the EXIF data. You can delete the EXIF data with:\n\n    jhead -de *.jpg\n\nYou can also generate new EXIF data with:\n\n    jhead -mkexif *.jpg",
      "votes": null
    },
    {
      "id": "176337",
      "postDate": "04/20/2017 03:03:17",
      "content": "<p>I had the same issue. Try the <a href=\"https://pypi.python.org/pypi/piexif\">piexif</a> library. You can clear out all the exif data and you won't run into the issue anymore.</p>\n\n<pre><code>import piexif\npiexif.remove(img)\n</code></pre>\n\n<p>Do that for each image and then you can do whatever you need to do with PIL afterwards. </p>",
      "rawMarkdown": "I had the same issue. Try the [piexif][1] library. You can clear out all the exif data and you won't run into the issue anymore.\n\n    import piexif\n    piexif.remove(img)\n\nDo that for each image and then you can do whatever you need to do with PIL afterwards. \n\n  [1]: https://pypi.python.org/pypi/piexif",
      "votes": null
    },
    {
      "id": "185010",
      "postDate": "05/23/2017 19:26:00",
      "content": "<p>use opencv</p>\n\n<pre><code>import cv2\nimg = cv2.imread(imagepath)\nimg = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n</code></pre>",
      "rawMarkdown": "use opencv\n\n    import cv2\n    img = cv2.imread(imagepath)\n    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)",
      "votes": null
    },
    {
      "id": "599367",
      "postDate": "08/14/2019 21:37:40",
      "content": "<p>I wouldn't recommend this.  If you are looping over a bunch of images, this shouldn't be the way to go </p>\n\n<p>When you use opencv to read images instead of PIL , it loads the entire image into memory as compared to PIL which just reads the image metadata. </p>",
      "rawMarkdown": "I wouldn't recommend this.  If you are looping over a bunch of images, this shouldn't be the way to go \n\nWhen you use opencv to read images instead of PIL , it loads the entire image into memory as compared to PIL which just reads the image metadata.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 174988,
      "author_name": "josmoreira",
      "author_url": "",
      "post_date": "04/13/2017 11:51:52",
      "content": "<p>I did have the same problem using PIL... managed to read some of the image's EXIF data with ExifRead python package though...</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 175519,
      "author_name": "ethanfast",
      "author_url": "",
      "post_date": "04/15/2017 21:53:31",
      "content": "<p>I ran into this as well. Probably the easiest fix is just to remove the EXIF data. You can delete the EXIF data with:</p>\n\n<pre><code>jhead -de *.jpg\n</code></pre>\n\n<p>You can also generate new EXIF data with:</p>\n\n<pre><code>jhead -mkexif *.jpg\n</code></pre>",
      "votes": null,
      "replies": []
    },
    {
      "id": 176337,
      "author_name": "jjgarrett0",
      "author_url": "",
      "post_date": "04/20/2017 03:03:17",
      "content": "<p>I had the same issue. Try the <a href=\"https://pypi.python.org/pypi/piexif\">piexif</a> library. You can clear out all the exif data and you won't run into the issue anymore.</p>\n\n<pre><code>import piexif\npiexif.remove(img)\n</code></pre>\n\n<p>Do that for each image and then you can do whatever you need to do with PIL afterwards. </p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 185010,
      "author_name": "sbharti",
      "author_url": "",
      "post_date": "05/23/2017 19:26:00",
      "content": "<p>use opencv</p>\n\n<pre><code>import cv2\nimg = cv2.imread(imagepath)\nimg = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n</code></pre>",
      "votes": null,
      "replies": [
        {
          "id": 599367,
          "author_name": "codeislife99",
          "author_url": "",
          "post_date": "08/14/2019 21:37:40",
          "content": "<p>I wouldn't recommend this.  If you are looping over a bunch of images, this shouldn't be the way to go </p>\n\n<p>When you use opencv to read images instead of PIL , it loads the entire image into memory as compared to PIL which just reads the image metadata. </p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "174941": "I'm trying to load the images with Python2 (I'm using `scipy.misc.imread` function if that matters). In case of some images a warning like this is printed:\n\n    /home/grzegorz/PycharmProjects/Environments/std/local/lib/python2.7/site-packages/PIL/TiffImagePlugin.py:692: UserWarning: Possibly corrupt EXIF data.  Expecting to read 524288 bytes but only got 0. Skipping tag 3\n      \"Skipping tag %s\" % (size, len(data), tag))\n    /home/grzegorz/PycharmProjects/Environments/std/local/lib/python2.7/site-packages/PIL/TiffImagePlugin.py:692: UserWarning: Possibly corrupt EXIF data.  Expecting to read 393216 bytes but only got 0. Skipping tag 3\n      \"Skipping tag %s\" % (size, len(data), tag))\n    /home/grzegorz/PycharmProjects/Environments/std/local/lib/python2.7/site-packages/PIL/TiffImagePlugin.py:692: UserWarning: Possibly corrupt EXIF data.  Expecting to read 33554432 bytes but only got 0. Skipping tag 4\n      \"Skipping tag %s\" % (size, len(data), tag))\n    ⋮\n\nDid you also have this problem? If yes, how did you handle it?",
    "174988": "I did have the same problem using PIL... managed to read some of the image's EXIF data with ExifRead python package though...",
    "175519": "I ran into this as well. Probably the easiest fix is just to remove the EXIF data. You can delete the EXIF data with:\n\n    jhead -de *.jpg\n\nYou can also generate new EXIF data with:\n\n    jhead -mkexif *.jpg",
    "176337": "I had the same issue. Try the [piexif][1] library. You can clear out all the exif data and you won't run into the issue anymore.\n\n    import piexif\n    piexif.remove(img)\n\nDo that for each image and then you can do whatever you need to do with PIL afterwards. \n\n  [1]: https://pypi.python.org/pypi/piexif",
    "185010": "use opencv\n\n    import cv2\n    img = cv2.imread(imagepath)\n    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)",
    "599367": "I wouldn't recommend this.  If you are looping over a bunch of images, this shouldn't be the way to go \n\nWhen you use opencv to read images instead of PIL , it loads the entire image into memory as compared to PIL which just reads the image metadata."
  },
  "source": "meta"
}