{
  "id": 42698,
  "title": "Image resizing",
  "url": "/competitions/dog-breed-identification/discussion/42698",
  "author_name": "",
  "post_date": "2017-11-03T08:25:47.675830200Z",
  "votes": 2,
  "comment_count": 7,
  "views": 0,
  "content": "<p>Hi all,</p>\n\n<p>I have a question concerning the image preprocessing. What do you use to deal with the different image sizes? Simply resizing all images and ignore image distortion, or do you add white pixels to make the images quadratic before resizing. Looking forward to read your thoughts ...</p>\n\n<p>Cheers</p>",
  "messages": [
    {
      "id": "239344",
      "postDate": "11/03/2017 08:25:47",
      "content": "<p>Hi all,</p>\n\n<p>I have a question concerning the image preprocessing. What do you use to deal with the different image sizes? Simply resizing all images and ignore image distortion, or do you add white pixels to make the images quadratic before resizing. Looking forward to read your thoughts ...</p>\n\n<p>Cheers</p>",
      "rawMarkdown": "Hi all,\n\nI have a question concerning the image preprocessing. What do you use to deal with the different image sizes? Simply resizing all images and ignore image distortion, or do you add white pixels to make the images quadratic before resizing. Looking forward to read your thoughts ...\n\nCheers",
      "votes": null
    },
    {
      "id": "239461",
      "postDate": "11/03/2017 15:25:25",
      "content": "<pre><code>from keras.preprocessing import image \nimg = image.load_img(path, target_size=size) \nimg = image.img_to_array(img)\n</code></pre>",
      "rawMarkdown": "from keras.preprocessing import image \n    img = image.load_img(path, target_size=size) \n    img = image.img_to_array(img)",
      "votes": null
    },
    {
      "id": "239546",
      "postDate": "11/03/2017 18:48:27",
      "content": "<p>make use of scikit-image library for image preprocessing</p>",
      "rawMarkdown": "make use of scikit-image library for image preprocessing",
      "votes": null
    },
    {
      "id": "241682",
      "postDate": "11/09/2017 15:16:04",
      "content": "<p>some function change the elements float and less than 1.0 , scikit-image lib over 255 automatically</p>",
      "rawMarkdown": "some function change the elements float and less than 1.0 , scikit-image lib over 255 automatically",
      "votes": null
    },
    {
      "id": "241710",
      "postDate": "11/09/2017 16:43:16",
      "content": "<p>As you have mentioned simply resizing the images will distort the images. Of course you can pad the images with white pixels but there are more strategies.</p>\n\n<p>Say we have an image of shape 600x400 and want to scale it to 224x224. A solution would be to scale the image such that the aspect ratio remains the same, but the shortest side has 224 pixels. That is, 224*(600/400)x224 = 336x224. Then we can get a random crop of 224x224. </p>\n\n<p>This strategy gets us square images without padding. We do lose some data there, but you can also see it as some data augmentation, as the next epoch a different random crop is made.</p>",
      "rawMarkdown": "As you have mentioned simply resizing the images will distort the images. Of course you can pad the images with white pixels but there are more strategies.\n\nSay we have an image of shape 600x400 and want to scale it to 224x224. A solution would be to scale the image such that the aspect ratio remains the same, but the shortest side has 224 pixels. That is, 224*(600/400)x224 = 336x224. Then we can get a random crop of 224x224. \n\nThis strategy gets us square images without padding. We do lose some data there, but you can also see it as some data augmentation, as the next epoch a different random crop is made.",
      "votes": null
    },
    {
      "id": "242852",
      "postDate": "11/12/2017 19:38:30",
      "content": "<p>I would think there would be a benefit to doing both. You aren't always going to have the luxury of a high definition image so training on some blurry images might help by exposing your model to a wider array of inputs.</p>",
      "rawMarkdown": "I would think there would be a benefit to doing both. You aren't always going to have the luxury of a high definition image so training on some blurry images might help by exposing your model to a wider array of inputs.",
      "votes": null
    },
    {
      "id": "246289",
      "postDate": "11/20/2017 21:52:06",
      "content": "<p>Well I performed a quick analysis over sizes....took a number near the avg. size....and resized all the images greater than that dimension.</p>",
      "rawMarkdown": "Well I performed a quick analysis over sizes....took a number near the avg. size....and resized all the images greater than that dimension.",
      "votes": null
    },
    {
      "id": "251319",
      "postDate": "12/01/2017 01:45:46",
      "content": "<p>Hi! I want to scale the image to 224*224 and remain the original aspect ratio .If the shortest side of images is less than 224,how to do it ??  </p>",
      "rawMarkdown": "Hi! I want to scale the image to 224*224 and remain the original aspect ratio .If the shortest side of images is less than 224,how to do it ??",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 239461,
      "author_name": "sermakarevich",
      "author_url": "",
      "post_date": "11/03/2017 15:25:25",
      "content": "<pre><code>from keras.preprocessing import image \nimg = image.load_img(path, target_size=size) \nimg = image.img_to_array(img)\n</code></pre>",
      "votes": null,
      "replies": []
    },
    {
      "id": 239546,
      "author_name": "tanmayrauth",
      "author_url": "",
      "post_date": "11/03/2017 18:48:27",
      "content": "<p>make use of scikit-image library for image preprocessing</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 241682,
      "author_name": "colorfulclouds",
      "author_url": "",
      "post_date": "11/09/2017 15:16:04",
      "content": "<p>some function change the elements float and less than 1.0 , scikit-image lib over 255 automatically</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 241710,
      "author_name": "danibr",
      "author_url": "",
      "post_date": "11/09/2017 16:43:16",
      "content": "<p>As you have mentioned simply resizing the images will distort the images. Of course you can pad the images with white pixels but there are more strategies.</p>\n\n<p>Say we have an image of shape 600x400 and want to scale it to 224x224. A solution would be to scale the image such that the aspect ratio remains the same, but the shortest side has 224 pixels. That is, 224*(600/400)x224 = 336x224. Then we can get a random crop of 224x224. </p>\n\n<p>This strategy gets us square images without padding. We do lose some data there, but you can also see it as some data augmentation, as the next epoch a different random crop is made.</p>",
      "votes": null,
      "replies": [
        {
          "id": 251319,
          "author_name": "ptlinyi",
          "author_url": "",
          "post_date": "12/01/2017 01:45:46",
          "content": "<p>Hi! I want to scale the image to 224*224 and remain the original aspect ratio .If the shortest side of images is less than 224,how to do it ??  </p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 242852,
      "author_name": "andrewcopp",
      "author_url": "",
      "post_date": "11/12/2017 19:38:30",
      "content": "<p>I would think there would be a benefit to doing both. You aren't always going to have the luxury of a high definition image so training on some blurry images might help by exposing your model to a wider array of inputs.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 246289,
      "author_name": "damngamerz",
      "author_url": "",
      "post_date": "11/20/2017 21:52:06",
      "content": "<p>Well I performed a quick analysis over sizes....took a number near the avg. size....and resized all the images greater than that dimension.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "239344": "Hi all,\n\nI have a question concerning the image preprocessing. What do you use to deal with the different image sizes? Simply resizing all images and ignore image distortion, or do you add white pixels to make the images quadratic before resizing. Looking forward to read your thoughts ...\n\nCheers",
    "239461": "from keras.preprocessing import image \n    img = image.load_img(path, target_size=size) \n    img = image.img_to_array(img)",
    "239546": "make use of scikit-image library for image preprocessing",
    "241682": "some function change the elements float and less than 1.0 , scikit-image lib over 255 automatically",
    "241710": "As you have mentioned simply resizing the images will distort the images. Of course you can pad the images with white pixels but there are more strategies.\n\nSay we have an image of shape 600x400 and want to scale it to 224x224. A solution would be to scale the image such that the aspect ratio remains the same, but the shortest side has 224 pixels. That is, 224*(600/400)x224 = 336x224. Then we can get a random crop of 224x224. \n\nThis strategy gets us square images without padding. We do lose some data there, but you can also see it as some data augmentation, as the next epoch a different random crop is made.",
    "242852": "I would think there would be a benefit to doing both. You aren't always going to have the luxury of a high definition image so training on some blurry images might help by exposing your model to a wider array of inputs.",
    "246289": "Well I performed a quick analysis over sizes....took a number near the avg. size....and resized all the images greater than that dimension.",
    "251319": "Hi! I want to scale the image to 224*224 and remain the original aspect ratio .If the shortest side of images is less than 224,how to do it ??"
  },
  "source": "meta"
}