{
  "id": 311983,
  "title": ".tif files - how to deal with it?",
  "url": "/competitions/geolifeclef-2022-lifeclef-2022-fgvc9/discussion/311983",
  "author_name": "",
  "post_date": "2022-03-09T20:13:59.590523700Z",
  "votes": 11,
  "comment_count": 3,
  "views": 0,
  "content": "<p>Hi, I noticed that a lot of pictures in this contest are in .tif format. I didn't know much about this format before, so I wanted to share my short research.</p>\n<p><strong>1. What is TIF?</strong><br>\nTIF (or TIFF) is an image format used for containing high quality graphics. It stands for “Tagged Image File Format” or “Tagged Image Format”. The format was created by Aldus Corporation but Adobe acquired the format later and made subsequent update in this format. TIF file is capable of holding both lossy jpeg compression and lossless image data. It can also contain vector based graphics data. TIF file format is widely supported in image editing applications. For that it’s a very popular image format among Graphic artists, Photographers, and Publishing authorities.</p>\n<p><strong>2. How to load files in Python?</strong><br>\nThere are at least several ways to load such files. A lot depends on whether we want to load an image in the form of a numeric array or hold it as a graphical object. Three most populars by StackOverflow are:</p>\n<p>By using tifffile package<br>\n<code>import tifffile as tiff</code><br>\n<code>image = tiff.imread('abc.tif')</code></p>\n<p>By using PIL and numpy packages<br>\n<code>from PIL import Image</code><br>\n<code>import numpy as np</code><br>\n<code>image = Image.open('abc.tif')</code><br>\n<code>image = np.array(image)</code></p>\n<p>By using cv2 and numpy packages<br>\n<code>import cv2</code><br>\n<code>import numpy as np</code><br>\n<code>image = cv2.imread('abc.tif')</code><br>\n<code>image = np.asarray(image, dtype = np.float64)</code></p>\n<p>If you have worked with .tif files before, share your thoughts on how to best approach this format.</p>\n<p>Sources:</p>\n<ol>\n<li><a href=\"https://www.paintshoppro.com/en/pages/tif-file/\" target=\"_blank\">https://www.paintshoppro.com/en/pages/tif-file/</a></li>\n<li><a href=\"https://stackoverflow.com/questions/18446804/python-read-and-write-tiff-16-bit-three-channel-colour-images\" target=\"_blank\">https://stackoverflow.com/questions/18446804/python-read-and-write-tiff-16-bit-three-channel-colour-images</a></li>\n<li><a href=\"https://stackoverflow.com/questions/7569553/working-with-tiffs-import-export-in-python-using-numpy\" target=\"_blank\">https://stackoverflow.com/questions/7569553/working-with-tiffs-import-export-in-python-using-numpy</a></li>\n<li><a href=\"https://stackoverflow.com/questions/29049771/working-with-tiff-files-in-python\" target=\"_blank\">https://stackoverflow.com/questions/29049771/working-with-tiff-files-in-python</a></li>\n</ol>",
  "messages": [
    {
      "id": "1717338",
      "postDate": "03/09/2022 20:13:59",
      "content": "<p>Hi, I noticed that a lot of pictures in this contest are in .tif format. I didn't know much about this format before, so I wanted to share my short research.</p>\n<p><strong>1. What is TIF?</strong><br>\nTIF (or TIFF) is an image format used for containing high quality graphics. It stands for “Tagged Image File Format” or “Tagged Image Format”. The format was created by Aldus Corporation but Adobe acquired the format later and made subsequent update in this format. TIF file is capable of holding both lossy jpeg compression and lossless image data. It can also contain vector based graphics data. TIF file format is widely supported in image editing applications. For that it’s a very popular image format among Graphic artists, Photographers, and Publishing authorities.</p>\n<p><strong>2. How to load files in Python?</strong><br>\nThere are at least several ways to load such files. A lot depends on whether we want to load an image in the form of a numeric array or hold it as a graphical object. Three most populars by StackOverflow are:</p>\n<p>By using tifffile package<br>\n<code>import tifffile as tiff</code><br>\n<code>image = tiff.imread('abc.tif')</code></p>\n<p>By using PIL and numpy packages<br>\n<code>from PIL import Image</code><br>\n<code>import numpy as np</code><br>\n<code>image = Image.open('abc.tif')</code><br>\n<code>image = np.array(image)</code></p>\n<p>By using cv2 and numpy packages<br>\n<code>import cv2</code><br>\n<code>import numpy as np</code><br>\n<code>image = cv2.imread('abc.tif')</code><br>\n<code>image = np.asarray(image, dtype = np.float64)</code></p>\n<p>If you have worked with .tif files before, share your thoughts on how to best approach this format.</p>\n<p>Sources:</p>\n<ol>\n<li><a href=\"https://www.paintshoppro.com/en/pages/tif-file/\" target=\"_blank\">https://www.paintshoppro.com/en/pages/tif-file/</a></li>\n<li><a href=\"https://stackoverflow.com/questions/18446804/python-read-and-write-tiff-16-bit-three-channel-colour-images\" target=\"_blank\">https://stackoverflow.com/questions/18446804/python-read-and-write-tiff-16-bit-three-channel-colour-images</a></li>\n<li><a href=\"https://stackoverflow.com/questions/7569553/working-with-tiffs-import-export-in-python-using-numpy\" target=\"_blank\">https://stackoverflow.com/questions/7569553/working-with-tiffs-import-export-in-python-using-numpy</a></li>\n<li><a href=\"https://stackoverflow.com/questions/29049771/working-with-tiff-files-in-python\" target=\"_blank\">https://stackoverflow.com/questions/29049771/working-with-tiff-files-in-python</a></li>\n</ol>",
      "rawMarkdown": "Hi, I noticed that a lot of pictures in this contest are in .tif format. I didn't know much about this format before, so I wanted to share my short research.\n\n\n**1. What is TIF?**\nTIF (or TIFF) is an image format used for containing high quality graphics. It stands for “Tagged Image File Format” or “Tagged Image Format”. The format was created by Aldus Corporation but Adobe acquired the format later and made subsequent update in this format. TIF file is capable of holding both lossy jpeg compression and lossless image data. It can also contain vector based graphics data. TIF file format is widely supported in image editing applications. For that it’s a very popular image format among Graphic artists, Photographers, and Publishing authorities.\n\n**2. How to load files in Python?**\nThere are at least several ways to load such files. A lot depends on whether we want to load an image in the form of a numeric array or hold it as a graphical object. Three most populars by StackOverflow are:\n\nBy using tifffile package\n`import tifffile as tiff`\n`image = tiff.imread('abc.tif')`\n\nBy using PIL and numpy packages\n`from PIL import Image`\n`import numpy as np`\n`image = Image.open('abc.tif')`\n`image = np.array(image)`\n\nBy using cv2 and numpy packages\n`import cv2`\n`import numpy as np`\n`image = cv2.imread('abc.tif')`\n`image = np.asarray(image, dtype = np.float64)`\n\nIf you have worked with .tif files before, share your thoughts on how to best approach this format.\n\nSources:\n1. https://www.paintshoppro.com/en/pages/tif-file/\n2. https://stackoverflow.com/questions/18446804/python-read-and-write-tiff-16-bit-three-channel-colour-images\n3. https://stackoverflow.com/questions/7569553/working-with-tiffs-import-export-in-python-using-numpy\n4. https://stackoverflow.com/questions/29049771/working-with-tiff-files-in-python",
      "votes": null
    },
    {
      "id": "1717913",
      "postDate": "03/10/2022 10:30:20",
      "content": "<p>Hi Michal,</p>\n<p>Thanks a lot for sharing this!</p>\n<p>Note that we provide code for data loading (and other stuffs) on our GitHub: <a href=\"https://github.com/maximiliense/GLC/\" target=\"_blank\">https://github.com/maximiliense/GLC/</a><br>\nMoreover, you might be interested in our starter code for data loading and visualization on this notebook: <a href=\"https://www.kaggle.com/tlorieul/geolifeclef2022-data-loading-and-visualization\" target=\"_blank\">https://www.kaggle.com/tlorieul/geolifeclef2022-data-loading-and-visualization</a></p>\n<p>The function <code>load_patch</code> enables you to easily load the patches associated to a given observation (either all the patches - RGB, Near-IR, altitude, landcover - or only some of them).<br>\nIf you are interested or want to modify it, you can find its implementation here: <a href=\"https://github.com/maximiliense/GLC/blob/master/data_loading/common.py#L8\" target=\"_blank\">https://github.com/maximiliense/GLC/blob/master/data_loading/common.py#L8</a></p>",
      "rawMarkdown": "Hi Michal,\n\nThanks a lot for sharing this!\n\nNote that we provide code for data loading (and other stuffs) on our GitHub: https://github.com/maximiliense/GLC/\nMoreover, you might be interested in our starter code for data loading and visualization on this notebook: https://www.kaggle.com/tlorieul/geolifeclef2022-data-loading-and-visualization\n\nThe function `load_patch` enables you to easily load the patches associated to a given observation (either all the patches - RGB, Near-IR, altitude, landcover - or only some of them).\nIf you are interested or want to modify it, you can find its implementation here: https://github.com/maximiliense/GLC/blob/master/data_loading/common.py#L8",
      "votes": null
    },
    {
      "id": "1718347",
      "postDate": "03/10/2022 18:34:26",
      "content": "<p>Thanks. <br>\nAnother option to load (and display) is by using rasterio library.</p>\n<pre><code>import rasterio as rio\ntif = rio.open('my_tif.tif')\nrio.plot.show(tif);\n</code></pre>",
      "rawMarkdown": "Thanks. \nAnother option to load (and display) is by using rasterio library.\n\n\n```\nimport rasterio as rio\ntif = rio.open('my_tif.tif')\nrio.plot.show(tif);\n```",
      "votes": null
    },
    {
      "id": "1721217",
      "postDate": "03/13/2022 14:12:08",
      "content": "<p>Thanks a lot for sharing <a href=\"https://www.kaggle.com/michau96\" target=\"_blank\">@michau96</a> !!!</p>",
      "rawMarkdown": "Thanks a lot for sharing @michau96 !!!",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1717913,
      "author_name": "tlorieul",
      "author_url": "",
      "post_date": "03/10/2022 10:30:20",
      "content": "<p>Hi Michal,</p>\n<p>Thanks a lot for sharing this!</p>\n<p>Note that we provide code for data loading (and other stuffs) on our GitHub: <a href=\"https://github.com/maximiliense/GLC/\" target=\"_blank\">https://github.com/maximiliense/GLC/</a><br>\nMoreover, you might be interested in our starter code for data loading and visualization on this notebook: <a href=\"https://www.kaggle.com/tlorieul/geolifeclef2022-data-loading-and-visualization\" target=\"_blank\">https://www.kaggle.com/tlorieul/geolifeclef2022-data-loading-and-visualization</a></p>\n<p>The function <code>load_patch</code> enables you to easily load the patches associated to a given observation (either all the patches - RGB, Near-IR, altitude, landcover - or only some of them).<br>\nIf you are interested or want to modify it, you can find its implementation here: <a href=\"https://github.com/maximiliense/GLC/blob/master/data_loading/common.py#L8\" target=\"_blank\">https://github.com/maximiliense/GLC/blob/master/data_loading/common.py#L8</a></p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1718347,
      "author_name": "ofirmazor",
      "author_url": "",
      "post_date": "03/10/2022 18:34:26",
      "content": "<p>Thanks. <br>\nAnother option to load (and display) is by using rasterio library.</p>\n<pre><code>import rasterio as rio\ntif = rio.open('my_tif.tif')\nrio.plot.show(tif);\n</code></pre>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1721217,
      "author_name": "",
      "author_url": "",
      "post_date": "03/13/2022 14:12:08",
      "content": "<p>Thanks a lot for sharing <a href=\"https://www.kaggle.com/michau96\" target=\"_blank\">@michau96</a> !!!</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1717338": "Hi, I noticed that a lot of pictures in this contest are in .tif format. I didn't know much about this format before, so I wanted to share my short research.\n\n\n**1. What is TIF?**\nTIF (or TIFF) is an image format used for containing high quality graphics. It stands for “Tagged Image File Format” or “Tagged Image Format”. The format was created by Aldus Corporation but Adobe acquired the format later and made subsequent update in this format. TIF file is capable of holding both lossy jpeg compression and lossless image data. It can also contain vector based graphics data. TIF file format is widely supported in image editing applications. For that it’s a very popular image format among Graphic artists, Photographers, and Publishing authorities.\n\n**2. How to load files in Python?**\nThere are at least several ways to load such files. A lot depends on whether we want to load an image in the form of a numeric array or hold it as a graphical object. Three most populars by StackOverflow are:\n\nBy using tifffile package\n`import tifffile as tiff`\n`image = tiff.imread('abc.tif')`\n\nBy using PIL and numpy packages\n`from PIL import Image`\n`import numpy as np`\n`image = Image.open('abc.tif')`\n`image = np.array(image)`\n\nBy using cv2 and numpy packages\n`import cv2`\n`import numpy as np`\n`image = cv2.imread('abc.tif')`\n`image = np.asarray(image, dtype = np.float64)`\n\nIf you have worked with .tif files before, share your thoughts on how to best approach this format.\n\nSources:\n1. https://www.paintshoppro.com/en/pages/tif-file/\n2. https://stackoverflow.com/questions/18446804/python-read-and-write-tiff-16-bit-three-channel-colour-images\n3. https://stackoverflow.com/questions/7569553/working-with-tiffs-import-export-in-python-using-numpy\n4. https://stackoverflow.com/questions/29049771/working-with-tiff-files-in-python",
    "1717913": "Hi Michal,\n\nThanks a lot for sharing this!\n\nNote that we provide code for data loading (and other stuffs) on our GitHub: https://github.com/maximiliense/GLC/\nMoreover, you might be interested in our starter code for data loading and visualization on this notebook: https://www.kaggle.com/tlorieul/geolifeclef2022-data-loading-and-visualization\n\nThe function `load_patch` enables you to easily load the patches associated to a given observation (either all the patches - RGB, Near-IR, altitude, landcover - or only some of them).\nIf you are interested or want to modify it, you can find its implementation here: https://github.com/maximiliense/GLC/blob/master/data_loading/common.py#L8",
    "1718347": "Thanks. \nAnother option to load (and display) is by using rasterio library.\n\n\n```\nimport rasterio as rio\ntif = rio.open('my_tif.tif')\nrio.plot.show(tif);\n```",
    "1721217": "Thanks a lot for sharing @michau96 !!!"
  },
  "source": "meta"
}