{
  "id": 128198,
  "title": "Morphological transformations as image augmentation",
  "url": "/competitions/bengaliai-cv19/discussion/128198",
  "author_name": "",
  "post_date": "2020-01-29T14:48:53.612417500Z",
  "votes": 34,
  "comment_count": 5,
  "views": 0,
  "content": "<p><a href=\"https://www.kaggle.com/ren4yu/bengali-morphological-ops-as-image-augmentation\">This kernel</a> shows some image augmentation using random morphological transformations. It might help to make the model to be more robust. Or standard augmentation might be enough... Anyway try it!</p>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F745525%2F46eb2e21f3236c3d7c52fb9342d4d917%2F2020-01-29%2023.43.47.png?generation=1580309063628317&amp;alt=media\" alt=\"\"></p>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F745525%2F1eb01b19ef93ebc9fde1ae44751e8a4f%2F2020-01-29%2023.43.56.png?generation=1580309066652181&amp;alt=media\" alt=\"\"></p>",
  "messages": [
    {
      "id": "732182",
      "postDate": "01/29/2020 14:48:53",
      "content": "<p><a href=\"https://www.kaggle.com/ren4yu/bengali-morphological-ops-as-image-augmentation\">This kernel</a> shows some image augmentation using random morphological transformations. It might help to make the model to be more robust. Or standard augmentation might be enough... Anyway try it!</p>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F745525%2F46eb2e21f3236c3d7c52fb9342d4d917%2F2020-01-29%2023.43.47.png?generation=1580309063628317&amp;alt=media\" alt=\"\"></p>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F745525%2F1eb01b19ef93ebc9fde1ae44751e8a4f%2F2020-01-29%2023.43.56.png?generation=1580309066652181&amp;alt=media\" alt=\"\"></p>",
      "rawMarkdown": "[This kernel](https://www.kaggle.com/ren4yu/bengali-morphological-ops-as-image-augmentation) shows some image augmentation using random morphological transformations. It might help to make the model to be more robust. Or standard augmentation might be enough... Anyway try it!\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F745525%2F46eb2e21f3236c3d7c52fb9342d4d917%2F2020-01-29%2023.43.47.png?generation=1580309063628317&amp;alt=media)\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F745525%2F1eb01b19ef93ebc9fde1ae44751e8a4f%2F2020-01-29%2023.43.56.png?generation=1580309066652181&amp;alt=media)",
      "votes": null
    },
    {
      "id": "733114",
      "postDate": "01/30/2020 17:18:40",
      "content": "<p>Really cool idea, excellent variation for augmenting the data!</p>",
      "rawMarkdown": "Really cool idea, excellent variation for augmenting the data!",
      "votes": null
    },
    {
      "id": "734220",
      "postDate": "02/01/2020 05:29:33",
      "content": "<p>Thank you for sharing an interesting idea. \nI wrote a basic albumetations' transform using <code>cv2.erode</code> and <code>cv2.dilate</code> from <a href=\"https://www.kaggle.com/ren4yu/bengali-morphological-ops-as-image-augmentation\">the kernel</a>.</p>\n\n<p>```\nclass RandomMorph(ImageOnlyTransform):</p>\n\n<pre><code>def __init__(self, _min=2, _max=6, element_shape=cv2.MORPH_ELLIPSE, always_apply=False, p=0.5):\n    super().__init__(always_apply, p)\n    self._min = _min\n    self._max = _max\n    self.element_shape = element_shape\n\ndef apply(self, image, **params):\n    arr = np.random.randint(self._min, self._max, 2)\n    kernel = cv2.getStructuringElement(self.element_shape, tuple(arr))\n\n    if random.random() &amp;gt; 0.5:\n        # make it thinner\n        image = cv2.erode(image, kernel, iterations=1)\n    else:\n        # make it thicker\n        image = cv2.dilate(image, kernel, iterations=1)\n\n    return image\n</code></pre>\n\n<p>```</p>",
      "rawMarkdown": "Thank you for sharing an interesting idea. \nI wrote a basic albumetations' transform using `cv2.erode` and `cv2.dilate` from [the kernel](https://www.kaggle.com/ren4yu/bengali-morphological-ops-as-image-augmentation).\n\n```\nclass RandomMorph(ImageOnlyTransform):\n\n    def __init__(self, _min=2, _max=6, element_shape=cv2.MORPH_ELLIPSE, always_apply=False, p=0.5):\n        super().__init__(always_apply, p)\n        self._min = _min\n        self._max = _max\n        self.element_shape = element_shape\n\n    def apply(self, image, **params):\n        arr = np.random.randint(self._min, self._max, 2)\n        kernel = cv2.getStructuringElement(self.element_shape, tuple(arr))\n\n        if random.random() &gt; 0.5:\n            # make it thinner\n            image = cv2.erode(image, kernel, iterations=1)\n        else:\n            # make it thicker\n            image = cv2.dilate(image, kernel, iterations=1)\n\n        return image\n```",
      "votes": null
    },
    {
      "id": "734927",
      "postDate": "02/02/2020 08:32:11",
      "content": "<p>Thank you! </p>",
      "rawMarkdown": "Thank you!",
      "votes": null
    },
    {
      "id": "751492",
      "postDate": "02/20/2020 08:28:31",
      "content": "<p>Nice</p>",
      "rawMarkdown": "Nice",
      "votes": null
    },
    {
      "id": "752678",
      "postDate": "02/21/2020 09:46:50",
      "content": "<p>good</p>",
      "rawMarkdown": "good",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 733114,
      "author_name": "ninapberry",
      "author_url": "",
      "post_date": "01/30/2020 17:18:40",
      "content": "<p>Really cool idea, excellent variation for augmenting the data!</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 734220,
      "author_name": "appian",
      "author_url": "",
      "post_date": "02/01/2020 05:29:33",
      "content": "<p>Thank you for sharing an interesting idea. \nI wrote a basic albumetations' transform using <code>cv2.erode</code> and <code>cv2.dilate</code> from <a href=\"https://www.kaggle.com/ren4yu/bengali-morphological-ops-as-image-augmentation\">the kernel</a>.</p>\n\n<p>```\nclass RandomMorph(ImageOnlyTransform):</p>\n\n<pre><code>def __init__(self, _min=2, _max=6, element_shape=cv2.MORPH_ELLIPSE, always_apply=False, p=0.5):\n    super().__init__(always_apply, p)\n    self._min = _min\n    self._max = _max\n    self.element_shape = element_shape\n\ndef apply(self, image, **params):\n    arr = np.random.randint(self._min, self._max, 2)\n    kernel = cv2.getStructuringElement(self.element_shape, tuple(arr))\n\n    if random.random() &amp;gt; 0.5:\n        # make it thinner\n        image = cv2.erode(image, kernel, iterations=1)\n    else:\n        # make it thicker\n        image = cv2.dilate(image, kernel, iterations=1)\n\n    return image\n</code></pre>\n\n<p>```</p>",
      "votes": null,
      "replies": [
        {
          "id": 734927,
          "author_name": "moximo13",
          "author_url": "",
          "post_date": "02/02/2020 08:32:11",
          "content": "<p>Thank you! </p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 751492,
      "author_name": "",
      "author_url": "",
      "post_date": "02/20/2020 08:28:31",
      "content": "<p>Nice</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 752678,
      "author_name": "",
      "author_url": "",
      "post_date": "02/21/2020 09:46:50",
      "content": "<p>good</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "732182": "[This kernel](https://www.kaggle.com/ren4yu/bengali-morphological-ops-as-image-augmentation) shows some image augmentation using random morphological transformations. It might help to make the model to be more robust. Or standard augmentation might be enough... Anyway try it!\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F745525%2F46eb2e21f3236c3d7c52fb9342d4d917%2F2020-01-29%2023.43.47.png?generation=1580309063628317&amp;alt=media)\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F745525%2F1eb01b19ef93ebc9fde1ae44751e8a4f%2F2020-01-29%2023.43.56.png?generation=1580309066652181&amp;alt=media)",
    "733114": "Really cool idea, excellent variation for augmenting the data!",
    "734220": "Thank you for sharing an interesting idea. \nI wrote a basic albumetations' transform using `cv2.erode` and `cv2.dilate` from [the kernel](https://www.kaggle.com/ren4yu/bengali-morphological-ops-as-image-augmentation).\n\n```\nclass RandomMorph(ImageOnlyTransform):\n\n    def __init__(self, _min=2, _max=6, element_shape=cv2.MORPH_ELLIPSE, always_apply=False, p=0.5):\n        super().__init__(always_apply, p)\n        self._min = _min\n        self._max = _max\n        self.element_shape = element_shape\n\n    def apply(self, image, **params):\n        arr = np.random.randint(self._min, self._max, 2)\n        kernel = cv2.getStructuringElement(self.element_shape, tuple(arr))\n\n        if random.random() &gt; 0.5:\n            # make it thinner\n            image = cv2.erode(image, kernel, iterations=1)\n        else:\n            # make it thicker\n            image = cv2.dilate(image, kernel, iterations=1)\n\n        return image\n```",
    "734927": "Thank you!",
    "751492": "Nice",
    "752678": "good"
  },
  "source": "meta"
}