{
  "id": 412396,
  "title": "StainTools for Augmentation",
  "url": "/competitions/hubmap-hacking-the-human-vasculature/discussion/412396",
  "author_name": "",
  "post_date": "2023-05-23T15:18:23.547427800Z",
  "votes": 27,
  "comment_count": 4,
  "views": 0,
  "content": "<h1>Overview</h1>\n<p>StainTools is a super useful library I came across when looking through successful solutions from the previous HuBMAP + HPA - Hacking the Human Body competition. </p>\n<p>This library is for tissue image stain normalization and augmentation.</p>\n<p>The library attempts to handle the problem of variation in color due to differences in color responses of slide scanners. They utilize stain separation and color normalization, which preserves biological structure information by modelling stain density maps based on non-negativity, sparsity, and soft-classification.</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F6537187%2F90bbcb0dbdc449fd96f459f2ee94ca55%2Fstaintools.gif?generation=1684854788762791&amp;alt=media\" alt=\"\"><br>\nImage from <a href=\"https://ieeexplore.ieee.org/abstract/document/7460968\" target=\"_blank\">paper</a></p>\n<h1>Implementation</h1>\n<p><strong>Installing</strong></p>\n<pre><code>!pip install staintools\n!pip install spams\n</code></pre>\n<p><strong>Imports</strong></p>\n<pre><code> numpy  np\n matplotlib.pyplot  plt\n staintools\n spams\n</code></pre>\n<p><strong>Reading in images</strong></p>\n<pre><code>target = staintools.read_image()\nto_transform = staintools.read_image()\n</code></pre>\n<p><strong>Standardize brightness</strong> (optional, can improve the tissue mask calculation)</p>\n<pre><code>target = staintools.LuminosityStandardizer.standardize(target)\nto_transform = staintools.LuminosityStandardizer.standardize(to_transform)\n</code></pre>\n<p><strong>Stain normalize</strong></p>\n<pre><code>normalizer = staintools.StainNormalizer(method=)\nnormalizer.fit(target)\ntransformed1 = normalizer.transform(to_transform)\nplt.imshow(transformed1)\n</code></pre>\n<h1>References</h1>\n<p><a href=\"https://www.kaggle.com/code/gray98/stain-normalization-color-transfer\" target=\"_blank\">Kaggle Notebook from previous competition by </a><a href=\"https://www.kaggle.com/gray98\" target=\"_blank\">@gray98</a><br>\n<a href=\"https://hackmd.io/@peter554/staintools\" target=\"_blank\">Article by Peter Byfield</a><br>\n<a href=\"https://ieeexplore.ieee.org/abstract/document/7460968\" target=\"_blank\">Paper by A. Vahadane et al.</a></p>",
  "messages": [
    {
      "id": "2271025",
      "postDate": "05/23/2023 15:18:23",
      "content": "<h1>Overview</h1>\n<p>StainTools is a super useful library I came across when looking through successful solutions from the previous HuBMAP + HPA - Hacking the Human Body competition. </p>\n<p>This library is for tissue image stain normalization and augmentation.</p>\n<p>The library attempts to handle the problem of variation in color due to differences in color responses of slide scanners. They utilize stain separation and color normalization, which preserves biological structure information by modelling stain density maps based on non-negativity, sparsity, and soft-classification.</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F6537187%2F90bbcb0dbdc449fd96f459f2ee94ca55%2Fstaintools.gif?generation=1684854788762791&amp;alt=media\" alt=\"\"><br>\nImage from <a href=\"https://ieeexplore.ieee.org/abstract/document/7460968\" target=\"_blank\">paper</a></p>\n<h1>Implementation</h1>\n<p><strong>Installing</strong></p>\n<pre><code>!pip install staintools\n!pip install spams\n</code></pre>\n<p><strong>Imports</strong></p>\n<pre><code> numpy  np\n matplotlib.pyplot  plt\n staintools\n spams\n</code></pre>\n<p><strong>Reading in images</strong></p>\n<pre><code>target = staintools.read_image()\nto_transform = staintools.read_image()\n</code></pre>\n<p><strong>Standardize brightness</strong> (optional, can improve the tissue mask calculation)</p>\n<pre><code>target = staintools.LuminosityStandardizer.standardize(target)\nto_transform = staintools.LuminosityStandardizer.standardize(to_transform)\n</code></pre>\n<p><strong>Stain normalize</strong></p>\n<pre><code>normalizer = staintools.StainNormalizer(method=)\nnormalizer.fit(target)\ntransformed1 = normalizer.transform(to_transform)\nplt.imshow(transformed1)\n</code></pre>\n<h1>References</h1>\n<p><a href=\"https://www.kaggle.com/code/gray98/stain-normalization-color-transfer\" target=\"_blank\">Kaggle Notebook from previous competition by </a><a href=\"https://www.kaggle.com/gray98\" target=\"_blank\">@gray98</a><br>\n<a href=\"https://hackmd.io/@peter554/staintools\" target=\"_blank\">Article by Peter Byfield</a><br>\n<a href=\"https://ieeexplore.ieee.org/abstract/document/7460968\" target=\"_blank\">Paper by A. Vahadane et al.</a></p>",
      "rawMarkdown": "# Overview\n\nStainTools is a super useful library I came across when looking through successful solutions from the previous HuBMAP + HPA - Hacking the Human Body competition. \n\nThis library is for tissue image stain normalization and augmentation.\n\nThe library attempts to handle the problem of variation in color due to differences in color responses of slide scanners. They utilize stain separation and color normalization, which preserves biological structure information by modelling stain density maps based on non-negativity, sparsity, and soft-classification.\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F6537187%2F90bbcb0dbdc449fd96f459f2ee94ca55%2Fstaintools.gif?generation=1684854788762791&alt=media)\nImage from [paper](https://ieeexplore.ieee.org/abstract/document/7460968)\n\n# Implementation\n\n**Installing**\n```\n!pip install staintools\n!pip install spams\n```\n\n**Imports**\n```python\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport staintools\nimport spams\n```\n\n**Reading in images**\n```python\ntarget = staintools.read_image(\"./data/my_target_image.png\")\nto_transform = staintools.read_image(\"./data/my_image_to_transform.png\")\n```\n\n**Standardize brightness** (optional, can improve the tissue mask calculation)\n```python\ntarget = staintools.LuminosityStandardizer.standardize(target)\nto_transform = staintools.LuminosityStandardizer.standardize(to_transform)\n```\n\n**Stain normalize**\n```python\nnormalizer = staintools.StainNormalizer(method='vahadane')\nnormalizer.fit(target)\ntransformed1 = normalizer.transform(to_transform)\nplt.imshow(transformed1)\n```\n\n# References\n[Kaggle Notebook from previous competition by @gray98](https://www.kaggle.com/code/gray98/stain-normalization-color-transfer)\n[Article by Peter Byfield](https://hackmd.io/@peter554/staintools)\n[Paper by A. Vahadane et al.](https://ieeexplore.ieee.org/abstract/document/7460968)",
      "votes": null
    },
    {
      "id": "2271075",
      "postDate": "05/23/2023 15:51:52",
      "content": "<p>Thanks for sharing such informative work <a href=\"https://www.kaggle.com/ravishah1\" target=\"_blank\">@ravishah1</a></p>",
      "rawMarkdown": "Thanks for sharing such informative work @ravishah1",
      "votes": null
    },
    {
      "id": "2294235",
      "postDate": "06/09/2023 22:50:20",
      "content": "<p>how to install spams of inference mode?<br>\nI get this error when i try</p>\n<ol>\n<li><p>ERROR: Could not find a version that satisfies the requirement spams (from versions: none)<br>\nERROR: No matching distribution found for spams</p></li>\n<li><p>ERROR: spams-2.6.5.4-cp37-cp37m-linux_x86_64.whl is not a supported wheel on this platform.</p></li>\n</ol>",
      "rawMarkdown": "how to install spams of inference mode?\nI get this error when i try\n\n1. \nERROR: Could not find a version that satisfies the requirement spams (from versions: none)\nERROR: No matching distribution found for spams\n\n2. \nERROR: spams-2.6.5.4-cp37-cp37m-linux_x86_64.whl is not a supported wheel on this platform.",
      "votes": null
    },
    {
      "id": "2311532",
      "postDate": "06/21/2023 08:08:18",
      "content": "<p>Thanks for sharing but HuBMAP + HPA - Hacking the Human Body was different. There were different stain types, pixel sizes and tissue thicknesses which model should generalize. There are only PAS stained WSIs with 10µm tissue thickness and ~0.5 µm pixel size here, so I don't think it will be useful here.</p>",
      "rawMarkdown": "Thanks for sharing but HuBMAP + HPA - Hacking the Human Body was different. There were different stain types, pixel sizes and tissue thicknesses which model should generalize. There are only PAS stained WSIs with 10µm tissue thickness and ~0.5 µm pixel size here, so I don't think it will be useful here.",
      "votes": null
    },
    {
      "id": "2311592",
      "postDate": "06/21/2023 09:16:07",
      "content": "<p>Is there still a chance we can correct for differences in staining between the different WSIs? <br>\nI guess it will be a lot more subtle. </p>\n<p>Then again, I know nothing about medical imagery, so feel free to tell me I am wrong</p>",
      "rawMarkdown": "Is there still a chance we can correct for differences in staining between the different WSIs? \nI guess it will be a lot more subtle. \n\nThen again, I know nothing about medical imagery, so feel free to tell me I am wrong",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 2271075,
      "author_name": "tamannaakterswarna",
      "author_url": "",
      "post_date": "05/23/2023 15:51:52",
      "content": "<p>Thanks for sharing such informative work <a href=\"https://www.kaggle.com/ravishah1\" target=\"_blank\">@ravishah1</a></p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 2294235,
      "author_name": "",
      "author_url": "",
      "post_date": "06/09/2023 22:50:20",
      "content": "<p>how to install spams of inference mode?<br>\nI get this error when i try</p>\n<ol>\n<li><p>ERROR: Could not find a version that satisfies the requirement spams (from versions: none)<br>\nERROR: No matching distribution found for spams</p></li>\n<li><p>ERROR: spams-2.6.5.4-cp37-cp37m-linux_x86_64.whl is not a supported wheel on this platform.</p></li>\n</ol>",
      "votes": null,
      "replies": []
    },
    {
      "id": 2311532,
      "author_name": "gunesevitan",
      "author_url": "",
      "post_date": "06/21/2023 08:08:18",
      "content": "<p>Thanks for sharing but HuBMAP + HPA - Hacking the Human Body was different. There were different stain types, pixel sizes and tissue thicknesses which model should generalize. There are only PAS stained WSIs with 10µm tissue thickness and ~0.5 µm pixel size here, so I don't think it will be useful here.</p>",
      "votes": null,
      "replies": [
        {
          "id": 2311592,
          "author_name": "fnands",
          "author_url": "",
          "post_date": "06/21/2023 09:16:07",
          "content": "<p>Is there still a chance we can correct for differences in staining between the different WSIs? <br>\nI guess it will be a lot more subtle. </p>\n<p>Then again, I know nothing about medical imagery, so feel free to tell me I am wrong</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "2271025": "# Overview\n\nStainTools is a super useful library I came across when looking through successful solutions from the previous HuBMAP + HPA - Hacking the Human Body competition. \n\nThis library is for tissue image stain normalization and augmentation.\n\nThe library attempts to handle the problem of variation in color due to differences in color responses of slide scanners. They utilize stain separation and color normalization, which preserves biological structure information by modelling stain density maps based on non-negativity, sparsity, and soft-classification.\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F6537187%2F90bbcb0dbdc449fd96f459f2ee94ca55%2Fstaintools.gif?generation=1684854788762791&alt=media)\nImage from [paper](https://ieeexplore.ieee.org/abstract/document/7460968)\n\n# Implementation\n\n**Installing**\n```\n!pip install staintools\n!pip install spams\n```\n\n**Imports**\n```python\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport staintools\nimport spams\n```\n\n**Reading in images**\n```python\ntarget = staintools.read_image(\"./data/my_target_image.png\")\nto_transform = staintools.read_image(\"./data/my_image_to_transform.png\")\n```\n\n**Standardize brightness** (optional, can improve the tissue mask calculation)\n```python\ntarget = staintools.LuminosityStandardizer.standardize(target)\nto_transform = staintools.LuminosityStandardizer.standardize(to_transform)\n```\n\n**Stain normalize**\n```python\nnormalizer = staintools.StainNormalizer(method='vahadane')\nnormalizer.fit(target)\ntransformed1 = normalizer.transform(to_transform)\nplt.imshow(transformed1)\n```\n\n# References\n[Kaggle Notebook from previous competition by @gray98](https://www.kaggle.com/code/gray98/stain-normalization-color-transfer)\n[Article by Peter Byfield](https://hackmd.io/@peter554/staintools)\n[Paper by A. Vahadane et al.](https://ieeexplore.ieee.org/abstract/document/7460968)",
    "2271075": "Thanks for sharing such informative work @ravishah1",
    "2294235": "how to install spams of inference mode?\nI get this error when i try\n\n1. \nERROR: Could not find a version that satisfies the requirement spams (from versions: none)\nERROR: No matching distribution found for spams\n\n2. \nERROR: spams-2.6.5.4-cp37-cp37m-linux_x86_64.whl is not a supported wheel on this platform.",
    "2311532": "Thanks for sharing but HuBMAP + HPA - Hacking the Human Body was different. There were different stain types, pixel sizes and tissue thicknesses which model should generalize. There are only PAS stained WSIs with 10µm tissue thickness and ~0.5 µm pixel size here, so I don't think it will be useful here.",
    "2311592": "Is there still a chance we can correct for differences in staining between the different WSIs? \nI guess it will be a lot more subtle. \n\nThen again, I know nothing about medical imagery, so feel free to tell me I am wrong"
  },
  "source": "meta"
}