{
  "id": 99543,
  "title": "Problem with cv2.resize",
  "url": "/competitions/aptos2019-blindness-detection/discussion/99543",
  "author_name": "",
  "post_date": "2019-07-12T04:57:38.467736Z",
  "votes": null,
  "comment_count": 2,
  "views": 0,
  "content": "<p>I am resizing the images with the follow code:\nSIZE= 256\nX_train = np.zeros((train.shape[0], SIZE, SIZE, 3))\nfig = plt.figure(figsize=(25, 16))\nfor i in range(train.shape[0]):\n    image = cv2.imread('../input/train_images/' + train.loc[i, 'id_code'] + '.png')\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)</p>\n\n<pre><code>image = cv2.resize(image, (SIZE, SIZE))\nimage = cv2.addWeighted(image, 4, cv2.GaussianBlur(image , (0,0) , 10) ,-4 ,128)\nX_train[i, :, :] = cv2.resize(image, (SIZE, SIZE))\n</code></pre>\n\n<p>If i plot the image with \nplt.imshow(cv2.resize(X_train[i])\nIt shows an incorrect image</p>\n\n<p>But if i plot with \nplt.imshow(cv2.resize(image, (SIZE, SIZE)))\nIt shows the corret image\nAn image example is attached for both cases.</p>\n\n<p>I use np.array_equal to compare the arrays, and return True.</p>\n\n<p>So, i dont understand, why different plots for same data.</p>\n\n<p>Ps: I got the code above from other kernels I was studying.</p>",
  "messages": [
    {
      "id": "573294",
      "postDate": "07/12/2019 04:57:38",
      "content": "<p>I am resizing the images with the follow code:\nSIZE= 256\nX_train = np.zeros((train.shape[0], SIZE, SIZE, 3))\nfig = plt.figure(figsize=(25, 16))\nfor i in range(train.shape[0]):\n    image = cv2.imread('../input/train_images/' + train.loc[i, 'id_code'] + '.png')\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)</p>\n\n<pre><code>image = cv2.resize(image, (SIZE, SIZE))\nimage = cv2.addWeighted(image, 4, cv2.GaussianBlur(image , (0,0) , 10) ,-4 ,128)\nX_train[i, :, :] = cv2.resize(image, (SIZE, SIZE))\n</code></pre>\n\n<p>If i plot the image with \nplt.imshow(cv2.resize(X_train[i])\nIt shows an incorrect image</p>\n\n<p>But if i plot with \nplt.imshow(cv2.resize(image, (SIZE, SIZE)))\nIt shows the corret image\nAn image example is attached for both cases.</p>\n\n<p>I use np.array_equal to compare the arrays, and return True.</p>\n\n<p>So, i dont understand, why different plots for same data.</p>\n\n<p>Ps: I got the code above from other kernels I was studying.</p>",
      "rawMarkdown": "I am resizing the images with the follow code:\nSIZE= 256\nX_train = np.zeros((train.shape[0], SIZE, SIZE, 3))\nfig = plt.figure(figsize=(25, 16))\nfor i in range(train.shape[0]):\n    image = cv2.imread('../input/train_images/' + train.loc[i, 'id_code'] + '.png')\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n\n    image = cv2.resize(image, (SIZE, SIZE))\n    image = cv2.addWeighted(image, 4, cv2.GaussianBlur(image , (0,0) , 10) ,-4 ,128)\n    X_train[i, :, :] = cv2.resize(image, (SIZE, SIZE))\n\n\nIf i plot the image with \nplt.imshow(cv2.resize(X_train[i])\nIt shows an incorrect image\n\nBut if i plot with \nplt.imshow(cv2.resize(image, (SIZE, SIZE)))\nIt shows the corret image\nAn image example is attached for both cases.\n\nI use np.array_equal to compare the arrays, and return True.\n\nSo, i dont understand, why different plots for same data.\n\nPs: I got the code above from other kernels I was studying.",
      "votes": null
    },
    {
      "id": "573583",
      "postDate": "07/12/2019 12:49:48",
      "content": "<p>That's because you should also consider that every image has 3 channels (RGB).\nTry with this <code>X_train[i, :, :, :] = cv2.resize(image, (SIZE, SIZE))</code></p>",
      "rawMarkdown": "That's because you should also consider that every image has 3 channels (RGB).\nTry with this `X_train[i, :, :, :] = cv2.resize(image, (SIZE, SIZE))`",
      "votes": null
    },
    {
      "id": "573666",
      "postDate": "07/12/2019 15:27:30",
      "content": "<p>Same thing :(</p>\n\n<p>It's very strange, comparing the arrays with np.array_equal, it returns True, it means that they are equal.\nSo, it should plot the same image, considering that is the same data.</p>",
      "rawMarkdown": "Same thing :(\n\n\nIt's very strange, comparing the arrays with np.array_equal, it returns True, it means that they are equal.\nSo, it should plot the same image, considering that is the same data.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 573583,
      "author_name": "raimonds1993",
      "author_url": "",
      "post_date": "07/12/2019 12:49:48",
      "content": "<p>That's because you should also consider that every image has 3 channels (RGB).\nTry with this <code>X_train[i, :, :, :] = cv2.resize(image, (SIZE, SIZE))</code></p>",
      "votes": null,
      "replies": [
        {
          "id": 573666,
          "author_name": "nandodmelo",
          "author_url": "",
          "post_date": "07/12/2019 15:27:30",
          "content": "<p>Same thing :(</p>\n\n<p>It's very strange, comparing the arrays with np.array_equal, it returns True, it means that they are equal.\nSo, it should plot the same image, considering that is the same data.</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "573294": "I am resizing the images with the follow code:\nSIZE= 256\nX_train = np.zeros((train.shape[0], SIZE, SIZE, 3))\nfig = plt.figure(figsize=(25, 16))\nfor i in range(train.shape[0]):\n    image = cv2.imread('../input/train_images/' + train.loc[i, 'id_code'] + '.png')\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n\n    image = cv2.resize(image, (SIZE, SIZE))\n    image = cv2.addWeighted(image, 4, cv2.GaussianBlur(image , (0,0) , 10) ,-4 ,128)\n    X_train[i, :, :] = cv2.resize(image, (SIZE, SIZE))\n\n\nIf i plot the image with \nplt.imshow(cv2.resize(X_train[i])\nIt shows an incorrect image\n\nBut if i plot with \nplt.imshow(cv2.resize(image, (SIZE, SIZE)))\nIt shows the corret image\nAn image example is attached for both cases.\n\nI use np.array_equal to compare the arrays, and return True.\n\nSo, i dont understand, why different plots for same data.\n\nPs: I got the code above from other kernels I was studying.",
    "573583": "That's because you should also consider that every image has 3 channels (RGB).\nTry with this `X_train[i, :, :, :] = cv2.resize(image, (SIZE, SIZE))`",
    "573666": "Same thing :(\n\n\nIt's very strange, comparing the arrays with np.array_equal, it returns True, it means that they are equal.\nSo, it should plot the same image, considering that is the same data."
  },
  "source": "meta"
}