{
  "id": 313045,
  "title": "Block Matching to clean background",
  "url": "/competitions/ultra-mnist/discussion/313045",
  "author_name": "",
  "post_date": "2022-03-15T11:15:20.300216Z",
  "votes": 2,
  "comment_count": 4,
  "views": 0,
  "content": "<p>Hi everyone! <br>\nSince the data is being reset and everyone is sharing their approach to clean the background, sharing mine <a href=\"https://www.kaggle.com/thatgeeman/block-matching-to-clean-ultramnist-background\" target=\"_blank\">here</a>. I use a simple block matching technique to check a patch with a pure black/white patch and decide to invert colours or not based on the RMSE value. </p>",
  "messages": [
    {
      "id": "1723368",
      "postDate": "03/15/2022 11:15:20",
      "content": "<p>Hi everyone! <br>\nSince the data is being reset and everyone is sharing their approach to clean the background, sharing mine <a href=\"https://www.kaggle.com/thatgeeman/block-matching-to-clean-ultramnist-background\" target=\"_blank\">here</a>. I use a simple block matching technique to check a patch with a pure black/white patch and decide to invert colours or not based on the RMSE value. </p>",
      "rawMarkdown": "Hi everyone! \nSince the data is being reset and everyone is sharing their approach to clean the background, sharing mine [here](https://www.kaggle.com/thatgeeman/block-matching-to-clean-ultramnist-background). I use a simple block matching technique to check a patch with a pure black/white patch and decide to invert colours or not based on the RMSE value.",
      "votes": null
    },
    {
      "id": "1723412",
      "postDate": "03/15/2022 11:54:58",
      "content": "<p>Interesting Idea.</p>\n<p>Unfortunately, it does suffer from the same problem as the \"Ultra-mnist black\" method</p>\n<pre><code>ids = [\n\"bfnwpcvgdt\",\n\"vhmqewzxef\",\n\"wuumlogxge\",\n\"gcpxitjbvc\",\n\"zwhazcdilo\",\n\"zafyjsvftb\",\n\"exuzvpmqfe\",\n\"fsnaafcqor\",\n]\nfor id in ids:\n    pth = f'../input/ultramnist2048x2048/train/{id}.jpeg'\n    im_cv = cv2.cvtColor(cv2.imread(pth), cv2.COLOR_BGR2RGB)\n    im_orig = np.asarray(im_cv)\n    im = clean_bg(pth, 4) # 51 ms ± 5.35 ms per loop\n    fig = plt.figure(figsize=(10,10))\n    plt.subplot(2, 2, 1)\n    plt.imshow(im_orig, cmap='Greys')\n    plt.title('Before')\n    plt.subplot(2, 2, 2)\n    plt.imshow(im, cmap='Greys')\n    plt.title('After')\n    display(fig)\n    plt.close()\n</code></pre>",
      "rawMarkdown": "Interesting Idea.\n\nUnfortunately, it does suffer from the same problem as the \"Ultra-mnist black\" method\n\n```python\nids = [\n\"bfnwpcvgdt\",\n\"vhmqewzxef\",\n\"wuumlogxge\",\n\"gcpxitjbvc\",\n\"zwhazcdilo\",\n\"zafyjsvftb\",\n\"exuzvpmqfe\",\n\"fsnaafcqor\",\n]\nfor id in ids:\n    pth = f'../input/ultramnist2048x2048/train/{id}.jpeg'\n    im_cv = cv2.cvtColor(cv2.imread(pth), cv2.COLOR_BGR2RGB)\n    im_orig = np.asarray(im_cv)\n    im = clean_bg(pth, 4) # 51 ms ± 5.35 ms per loop\n    fig = plt.figure(figsize=(10,10))\n    plt.subplot(2, 2, 1)\n    plt.imshow(im_orig, cmap='Greys')\n    plt.title('Before')\n    plt.subplot(2, 2, 2)\n    plt.imshow(im, cmap='Greys')\n    plt.title('After')\n    display(fig)\n    plt.close()\n```",
      "votes": null
    },
    {
      "id": "1723466",
      "postDate": "03/15/2022 12:41:01",
      "content": "<p>Wow, nice catch! With <code>clean_bg(pth, 128)</code> and it behaves like a Canny edge filter for the listed images. Maybe with an extra Contour detection+fill step, it should still work.</p>",
      "rawMarkdown": "Wow, nice catch! With `clean_bg(pth, 128)` and it behaves like a Canny edge filter for the listed images. Maybe with an extra Contour detection+fill step, it should still work.",
      "votes": null
    },
    {
      "id": "1748021",
      "postDate": "04/07/2022 08:54:52",
      "content": "<p>When I try to use it on the current (new) dataset, I get this:</p>\n<p><code>BxViolation: basebx of pybx.basics: Expected single element in coords, got [array([[  0.,   0., 128., 128.],\n       [128.,   0., 256., 128.],\n       [256.,   0., 384., 128.],\n...\n</code></p>\n<p>I converted cv2.COLOR_BGR2RGB to cv2.COLOR_BGR2GRAY  but that didn't work as well.</p>\n<p>What might be wrong?</p>",
      "rawMarkdown": "When I try to use it on the current (new) dataset, I get this:\n\n`BxViolation: basebx of pybx.basics: Expected single element in coords, got [array([[  0.,   0., 128., 128.],\n       [128.,   0., 256., 128.],\n       [256.,   0., 384., 128.],\n...\n`\n\nI converted cv2.COLOR_BGR2RGB to cv2.COLOR_BGR2GRAY  but that didn't work as well.\n\nWhat might be wrong?",
      "votes": null
    },
    {
      "id": "1753440",
      "postDate": "04/12/2022 20:33:33",
      "content": "<p>Looks like a change in the API caused this. You can check the <a href=\"https://www.kaggle.com/code/thatgeeman/block-matching-to-clean-ultramnist-background\" target=\"_blank\">updated notebook</a> to see how it works with the new dataset.</p>",
      "rawMarkdown": "Looks like a change in the API caused this. You can check the [updated notebook](https://www.kaggle.com/code/thatgeeman/block-matching-to-clean-ultramnist-background) to see how it works with the new dataset.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1723412,
      "author_name": "towzeur",
      "author_url": "",
      "post_date": "03/15/2022 11:54:58",
      "content": "<p>Interesting Idea.</p>\n<p>Unfortunately, it does suffer from the same problem as the \"Ultra-mnist black\" method</p>\n<pre><code>ids = [\n\"bfnwpcvgdt\",\n\"vhmqewzxef\",\n\"wuumlogxge\",\n\"gcpxitjbvc\",\n\"zwhazcdilo\",\n\"zafyjsvftb\",\n\"exuzvpmqfe\",\n\"fsnaafcqor\",\n]\nfor id in ids:\n    pth = f'../input/ultramnist2048x2048/train/{id}.jpeg'\n    im_cv = cv2.cvtColor(cv2.imread(pth), cv2.COLOR_BGR2RGB)\n    im_orig = np.asarray(im_cv)\n    im = clean_bg(pth, 4) # 51 ms ± 5.35 ms per loop\n    fig = plt.figure(figsize=(10,10))\n    plt.subplot(2, 2, 1)\n    plt.imshow(im_orig, cmap='Greys')\n    plt.title('Before')\n    plt.subplot(2, 2, 2)\n    plt.imshow(im, cmap='Greys')\n    plt.title('After')\n    display(fig)\n    plt.close()\n</code></pre>",
      "votes": null,
      "replies": [
        {
          "id": 1723466,
          "author_name": "thatgeeman",
          "author_url": "",
          "post_date": "03/15/2022 12:41:01",
          "content": "<p>Wow, nice catch! With <code>clean_bg(pth, 128)</code> and it behaves like a Canny edge filter for the listed images. Maybe with an extra Contour detection+fill step, it should still work.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1748021,
      "author_name": "faraday",
      "author_url": "",
      "post_date": "04/07/2022 08:54:52",
      "content": "<p>When I try to use it on the current (new) dataset, I get this:</p>\n<p><code>BxViolation: basebx of pybx.basics: Expected single element in coords, got [array([[  0.,   0., 128., 128.],\n       [128.,   0., 256., 128.],\n       [256.,   0., 384., 128.],\n...\n</code></p>\n<p>I converted cv2.COLOR_BGR2RGB to cv2.COLOR_BGR2GRAY  but that didn't work as well.</p>\n<p>What might be wrong?</p>",
      "votes": null,
      "replies": [
        {
          "id": 1753440,
          "author_name": "thatgeeman",
          "author_url": "",
          "post_date": "04/12/2022 20:33:33",
          "content": "<p>Looks like a change in the API caused this. You can check the <a href=\"https://www.kaggle.com/code/thatgeeman/block-matching-to-clean-ultramnist-background\" target=\"_blank\">updated notebook</a> to see how it works with the new dataset.</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1723368": "Hi everyone! \nSince the data is being reset and everyone is sharing their approach to clean the background, sharing mine [here](https://www.kaggle.com/thatgeeman/block-matching-to-clean-ultramnist-background). I use a simple block matching technique to check a patch with a pure black/white patch and decide to invert colours or not based on the RMSE value.",
    "1723412": "Interesting Idea.\n\nUnfortunately, it does suffer from the same problem as the \"Ultra-mnist black\" method\n\n```python\nids = [\n\"bfnwpcvgdt\",\n\"vhmqewzxef\",\n\"wuumlogxge\",\n\"gcpxitjbvc\",\n\"zwhazcdilo\",\n\"zafyjsvftb\",\n\"exuzvpmqfe\",\n\"fsnaafcqor\",\n]\nfor id in ids:\n    pth = f'../input/ultramnist2048x2048/train/{id}.jpeg'\n    im_cv = cv2.cvtColor(cv2.imread(pth), cv2.COLOR_BGR2RGB)\n    im_orig = np.asarray(im_cv)\n    im = clean_bg(pth, 4) # 51 ms ± 5.35 ms per loop\n    fig = plt.figure(figsize=(10,10))\n    plt.subplot(2, 2, 1)\n    plt.imshow(im_orig, cmap='Greys')\n    plt.title('Before')\n    plt.subplot(2, 2, 2)\n    plt.imshow(im, cmap='Greys')\n    plt.title('After')\n    display(fig)\n    plt.close()\n```",
    "1723466": "Wow, nice catch! With `clean_bg(pth, 128)` and it behaves like a Canny edge filter for the listed images. Maybe with an extra Contour detection+fill step, it should still work.",
    "1748021": "When I try to use it on the current (new) dataset, I get this:\n\n`BxViolation: basebx of pybx.basics: Expected single element in coords, got [array([[  0.,   0., 128., 128.],\n       [128.,   0., 256., 128.],\n       [256.,   0., 384., 128.],\n...\n`\n\nI converted cv2.COLOR_BGR2RGB to cv2.COLOR_BGR2GRAY  but that didn't work as well.\n\nWhat might be wrong?",
    "1753440": "Looks like a change in the API caused this. You can check the [updated notebook](https://www.kaggle.com/code/thatgeeman/block-matching-to-clean-ultramnist-background) to see how it works with the new dataset."
  },
  "source": "meta"
}