{
  "id": 453831,
  "title": "Run-Length Encode and Decode (RLE utility script)",
  "url": "/competitions/blood-vessel-segmentation/discussion/453831",
  "author_name": "",
  "post_date": "2023-11-07T22:37:08.359700100Z",
  "votes": 37,
  "comment_count": 7,
  "views": 0,
  "content": "<h1>RLE functions - Run Lenght Encode &amp; Decode By Paulo Pinto</h1>\n<p><a href=\"https://www.kaggle.com/code/paulorzp/rle-functions-run-lenght-encode-decode/script\" target=\"_blank\">https://www.kaggle.com/code/paulorzp/rle-functions-run-lenght-encode-decode/script</a></p>\n<p><a href=\"https://www.kaggle.com/code/paulorzp/run-length-encode-and-decode\" target=\"_blank\">https://www.kaggle.com/code/paulorzp/run-length-encode-and-decode</a></p>\n<p><a href=\"https://www.kaggle.com/code/paulorzp/fast-run-length-encode\" target=\"_blank\">https://www.kaggle.com/code/paulorzp/fast-run-length-encode</a> (On  Carvana Image Masking Challenge)</p>\n<p>That's the most copied helper function. Don't forget to vote Paulo's script!</p>\n<p>While I was reading Kaggle Notebooks from the last competitions (HubMap Kidney) and the Human Body comp, I found out that many have included (sources by Paulo Pinto snippet)</p>\n<p>Upvoting someone's work is how we show our gratitude for helping us to go forward.</p>\n<p>By the way, that script has already 4years. With so many skilled Data Scientists, it's about time to create new innovative segmenting Public Notebooks to improve and prolongue Human life.</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3012786%2F54665c27112c1e2fd873a7ef9bf75c71%2FCaptura%20de%20tela%202023-11-07%20193418.png?generation=1699396497677290&amp;alt=media\" alt=\"\"></p>\n<h1>I'm recycling my own previous topics on Hacking any Human organ : )</h1>",
  "messages": [
    {
      "id": "2516726",
      "postDate": "11/07/2023 22:37:08",
      "content": "<h1>RLE functions - Run Lenght Encode &amp; Decode By Paulo Pinto</h1>\n<p><a href=\"https://www.kaggle.com/code/paulorzp/rle-functions-run-lenght-encode-decode/script\" target=\"_blank\">https://www.kaggle.com/code/paulorzp/rle-functions-run-lenght-encode-decode/script</a></p>\n<p><a href=\"https://www.kaggle.com/code/paulorzp/run-length-encode-and-decode\" target=\"_blank\">https://www.kaggle.com/code/paulorzp/run-length-encode-and-decode</a></p>\n<p><a href=\"https://www.kaggle.com/code/paulorzp/fast-run-length-encode\" target=\"_blank\">https://www.kaggle.com/code/paulorzp/fast-run-length-encode</a> (On  Carvana Image Masking Challenge)</p>\n<p>That's the most copied helper function. Don't forget to vote Paulo's script!</p>\n<p>While I was reading Kaggle Notebooks from the last competitions (HubMap Kidney) and the Human Body comp, I found out that many have included (sources by Paulo Pinto snippet)</p>\n<p>Upvoting someone's work is how we show our gratitude for helping us to go forward.</p>\n<p>By the way, that script has already 4years. With so many skilled Data Scientists, it's about time to create new innovative segmenting Public Notebooks to improve and prolongue Human life.</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3012786%2F54665c27112c1e2fd873a7ef9bf75c71%2FCaptura%20de%20tela%202023-11-07%20193418.png?generation=1699396497677290&amp;alt=media\" alt=\"\"></p>\n<h1>I'm recycling my own previous topics on Hacking any Human organ : )</h1>",
      "rawMarkdown": "#RLE functions - Run Lenght Encode & Decode By Paulo Pinto\n\nhttps://www.kaggle.com/code/paulorzp/rle-functions-run-lenght-encode-decode/script\n\nhttps://www.kaggle.com/code/paulorzp/run-length-encode-and-decode\n\nhttps://www.kaggle.com/code/paulorzp/fast-run-length-encode (On  Carvana Image Masking Challenge)\n\nThat's the most copied helper function. Don't forget to vote Paulo's script!\n\nWhile I was reading Kaggle Notebooks from the last competitions (HubMap Kidney) and the Human Body comp, I found out that many have included (sources by Paulo Pinto snippet)\n\nUpvoting someone's work is how we show our gratitude for helping us to go forward.\n\nBy the way, that script has already 4years. With so many skilled Data Scientists, it's about time to create new innovative segmenting Public Notebooks to improve and prolongue Human life.\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3012786%2F54665c27112c1e2fd873a7ef9bf75c71%2FCaptura%20de%20tela%202023-11-07%20193418.png?generation=1699396497677290&alt=media)\n\n\n\n\n#I'm recycling my own previous topics on Hacking any Human organ : )",
      "votes": null
    },
    {
      "id": "2522158",
      "postDate": "11/12/2023 12:40:10",
      "content": "<p>Thanks for sharing! </p>\n<p>I tried this on the masks and run-length encodings given in our competition, and it seems to me that the encoding given in 'train_rles.csv' is slightly different than the one produced by the methods given here. Here's my code: </p>\n<blockquote>\n  <p>train_csv = pd.read_csv('/kaggle/input/blood-vessel-segmentation/train_rles.csv')<br>\n  folder_path_mask = '/kaggle/input/blood-vessel-segmentation/train/kidney_1_dense/labels'<br>\n  tif_files = sorted([file for file in os.listdir(folder_path_mask) if file.endswith('.tif')])</p>\n  <p>index = 1000<br>\n  tif_file = tif_files[index]<br>\n  mask_path = os.path.join(folder_path_mask, tif_file)<br>\n  mask = tifffile.imread(mask_path)<br>\n  mask = mask/255.0<br>\n  print(np.unique(mask))</p>\n  <p>plt.imshow(mask)<br>\n  plt.title(\"Input Mask\")<br>\n  plt.show()<br>\n  rle = mask2rle(mask)<br>\n  correct_rle = train_csv[\"rle\"].iloc[index]</p>\n  <p>rle_to_mask = rle2mask(rle, shape=(mask.shape[1],mask.shape[0]))<br>\n  plt.imshow(rle_to_mask)<br>\n  plt.title(\"Reconstruction of given mask based on RLE encoding by 'mask2rle' \")<br>\n  plt.show()</p>\n  <p>rle_to_mask2 = rle2mask(correct_rle, shape=(mask.shape[1],mask.shape[0]))<br>\n  plt.imshow(rle_to_mask2)<br>\n  plt.title(\"Reconstruction of given mask based on RLE encoding given in train_rles.csv \")<br>\n  plt.show()</p>\n</blockquote>\n<p>This correctly reconstructs the mask using the RLE obtained by mask2rle, but does <strong>not</strong> correctly reconstruct the image based on the RLE given in 'train_rles.csv'. </p>\n<p>You'll notice that I chose 'shape=(mask.shape[1],mask.shape[0])'. If you instead choose 'shape=(mask.shape[0],mask.shape[1])' the reconstruction of the mask based on the RLE encoding obtained by mask2rle no longer works, but the reconstruction of the mask based on the RLE given in 'train_rles.csv' <em>almost</em> works (it returns a transposed version of the mask). </p>\n<p>Also, the lengths of the RLEs in 'train_rles.csv' with the lengths of the RLEs obtained by 'mask2rle' seem to be different: </p>\n<blockquote>\n  <p>print(f'length of mask2rle:  {len(rle)} and length of correct_rle: {len(correct_rle)}')</p>\n</blockquote>\n<p>Do you have any idea how to modify this code to get consistent results? </p>",
      "rawMarkdown": "Thanks for sharing! \n\nI tried this on the masks and run-length encodings given in our competition, and it seems to me that the encoding given in 'train_rles.csv' is slightly different than the one produced by the methods given here. Here's my code: \n\n> train_csv = pd.read_csv('/kaggle/input/blood-vessel-segmentation/train_rles.csv')\nfolder_path_mask = '/kaggle/input/blood-vessel-segmentation/train/kidney_1_dense/labels'\ntif_files = sorted([file for file in os.listdir(folder_path_mask) if file.endswith('.tif')])\n\n>index = 1000\ntif_file = tif_files[index]\nmask_path = os.path.join(folder_path_mask, tif_file)\nmask = tifffile.imread(mask_path)\nmask = mask/255.0\nprint(np.unique(mask))\n\n>plt.imshow(mask)\nplt.title(\"Input Mask\")\nplt.show()\nrle = mask2rle(mask)\ncorrect_rle = train_csv[\"rle\"].iloc[index]\n\n>rle_to_mask = rle2mask(rle, shape=(mask.shape[1],mask.shape[0]))\nplt.imshow(rle_to_mask)\nplt.title(\"Reconstruction of given mask based on RLE encoding by 'mask2rle' \")\nplt.show()\n\n>rle_to_mask2 = rle2mask(correct_rle, shape=(mask.shape[1],mask.shape[0]))\nplt.imshow(rle_to_mask2)\nplt.title(\"Reconstruction of given mask based on RLE encoding given in train_rles.csv \")\nplt.show()\n\nThis correctly reconstructs the mask using the RLE obtained by mask2rle, but does **not** correctly reconstruct the image based on the RLE given in 'train_rles.csv'. \n\nYou'll notice that I chose 'shape=(mask.shape[1],mask.shape[0])'. If you instead choose 'shape=(mask.shape[0],mask.shape[1])' the reconstruction of the mask based on the RLE encoding obtained by mask2rle no longer works, but the reconstruction of the mask based on the RLE given in 'train_rles.csv' *almost* works (it returns a transposed version of the mask). \n\nAlso, the lengths of the RLEs in 'train_rles.csv' with the lengths of the RLEs obtained by 'mask2rle' seem to be different: \n> print(f'length of mask2rle:  {len(rle)} and length of correct_rle: {len(correct_rle)}')\n\nDo you have any idea how to modify this code to get consistent results?",
      "votes": null
    },
    {
      "id": "2522221",
      "postDate": "11/12/2023 14:11:03",
      "content": "<p>Hi F. Konrad,<br>\nOn this competition we have RLE \"in action\":</p>\n<p>Blood Vessel Mask to RLE- By Stpete Ishii<br>\n<a href=\"https://www.kaggle.com/code/stpeteishii/blood-vessel-mask-to-rle\" target=\"_blank\">https://www.kaggle.com/code/stpeteishii/blood-vessel-mask-to-rle</a></p>\n<p>RLE SenNet+HOA: RLE decode/encode demo submission - By Jirka Borovec<br>\n<a href=\"https://www.kaggle.com/code/jirkaborovec/sennet-hoa-rle-decode-encode-demo-submission\" target=\"_blank\">https://www.kaggle.com/code/jirkaborovec/sennet-hoa-rle-decode-encode-demo-submission</a></p>\n<p>And On the previous Hacking  the Human body:</p>\n<p>EDA – HuBMAP+HPA – Organ Segmentation By Darien Schettler</p>\n<p>Input 8:<br>\n<a href=\"https://www.kaggle.com/code/dschettler8845/eda-hubmap-hpa-organ-segmentation\" target=\"_blank\">https://www.kaggle.com/code/dschettler8845/eda-hubmap-hpa-organ-segmentation</a></p>\n<p>But I don't know how to apply Paulo's RLE utility script. I'm just a beginner 😏</p>",
      "rawMarkdown": "Hi F. Konrad,\nOn this competition we have RLE \"in action\":\n\nBlood Vessel Mask to RLE- By Stpete Ishii\nhttps://www.kaggle.com/code/stpeteishii/blood-vessel-mask-to-rle\n\nRLE SenNet+HOA: RLE decode/encode demo submission - By Jirka Borovec\nhttps://www.kaggle.com/code/jirkaborovec/sennet-hoa-rle-decode-encode-demo-submission\n\nAnd On the previous Hacking  the Human body:\n\nEDA – HuBMAP+HPA – Organ Segmentation By Darien Schettler\n\nInput 8:\nhttps://www.kaggle.com/code/dschettler8845/eda-hubmap-hpa-organ-segmentation\n\nBut I don't know how to apply Paulo's RLE utility script. I'm just a beginner 😏",
      "votes": null
    },
    {
      "id": "2522349",
      "postDate": "11/12/2023 15:55:01",
      "content": "<p>Thanks for the links. </p>\n<p>Paulo Pinto seems to have another Notebook for image-to-RLE conversion (<a href=\"https://www.kaggle.com/code/paulorzp/run-length-encode-and-decode/script)\" target=\"_blank\">https://www.kaggle.com/code/paulorzp/run-length-encode-and-decode/script)</a>. This one was linked in the competition overview. </p>\n<p>I had no issues running this program and it gave me the correct results, so I'd recommend using this one. </p>\n<p>Good luck to everyone! </p>",
      "rawMarkdown": "Thanks for the links. \n\nPaulo Pinto seems to have another Notebook for image-to-RLE conversion (https://www.kaggle.com/code/paulorzp/run-length-encode-and-decode/script). This one was linked in the competition overview. \n\nI had no issues running this program and it gave me the correct results, so I'd recommend using this one. \n\nGood luck to everyone!",
      "votes": null
    },
    {
      "id": "2522378",
      "postDate": "11/12/2023 16:09:31",
      "content": "<p>In fact, he has 3 RLE (Those below were made 6 y ago)</p>\n<p><a href=\"https://www.kaggle.com/code/paulorzp/run-length-encode-and-decode\" target=\"_blank\">https://www.kaggle.com/code/paulorzp/run-length-encode-and-decode</a></p>\n<p><a href=\"https://www.kaggle.com/code/paulorzp/fast-run-length-encode\" target=\"_blank\">https://www.kaggle.com/code/paulorzp/fast-run-length-encode</a> (On Carvana Image Masking Challenge) </p>\n<p>I think your link is page 404.</p>\n<p>Thank you Konrad. Good luck on this competition!</p>",
      "rawMarkdown": "In fact, he has 3 RLE (Those below were made 6 y ago)\n\nhttps://www.kaggle.com/code/paulorzp/run-length-encode-and-decode\n\nhttps://www.kaggle.com/code/paulorzp/fast-run-length-encode (On Carvana Image Masking Challenge) \n\nI think your link is page 404.\n\nThank you Konrad. Good luck on this competition!",
      "votes": null
    },
    {
      "id": "2522526",
      "postDate": "11/12/2023 18:37:00",
      "content": "<p>Thank you for sharing! Confirming paulorzp's \"run-length-encode-and-decode\" seems to match the rle string provided in \"/kaggle/input/blood-vessel-segmentation/train_rles.csv\"</p>\n<p>I have verified by serializing the mask in tif (via function \"rle_encode\") then asserting the output string against those provided in the csv file.  The \"rle_decode\" function also works - via asserting 0 against \"np.sum(tif_mask-deserialized_mask)\".</p>\n<p>In the \"rle_encode\" function, you just have to check for empty string \"\" and replace it with \"1 0\", e.g below snippet:</p>\n<pre><code>...\n    mystr = .((x)  x  runs)\n     mystr == :\n        mystr = \n     mystr\n</code></pre>\n<p><a href=\"https://www.kaggle.com/code/paulorzp/run-length-encode-and-decode/script\" target=\"_blank\">https://www.kaggle.com/code/paulorzp/run-length-encode-and-decode/script</a></p>",
      "rawMarkdown": "Thank you for sharing! Confirming paulorzp's \"run-length-encode-and-decode\" seems to match the rle string provided in \"/kaggle/input/blood-vessel-segmentation/train_rles.csv\"\n\nI have verified by serializing the mask in tif (via function \"rle_encode\") then asserting the output string against those provided in the csv file.  The \"rle_decode\" function also works - via asserting 0 against \"np.sum(tif_mask-deserialized_mask)\".\n\nIn the \"rle_encode\" function, you just have to check for empty string \"\" and replace it with \"1 0\", e.g below snippet:\n\n\n```\n...\n    mystr = ' '.join(str(x) for x in runs)\n    if mystr == \"\":\n        mystr = \"1 0\"\n    return mystr\n\n```\n\nhttps://www.kaggle.com/code/paulorzp/run-length-encode-and-decode/script",
      "votes": null
    },
    {
      "id": "2522606",
      "postDate": "11/12/2023 21:12:48",
      "content": "<p>You're doing great Pangyuteng.<br>\nI've already been in yours \"tiff-to-nifti visualize using ITKSNAP\".</p>",
      "rawMarkdown": "You're doing great Pangyuteng.\nI've already been in yours \"tiff-to-nifti visualize using ITKSNAP\".",
      "votes": null
    },
    {
      "id": "2562644",
      "postDate": "12/15/2023 15:25:59",
      "content": "<p>I was starting going crazy. I suspected something like that, thanks for the clarification.</p>",
      "rawMarkdown": "I was starting going crazy. I suspected something like that, thanks for the clarification.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 2522158,
      "author_name": "felixkonrad",
      "author_url": "",
      "post_date": "11/12/2023 12:40:10",
      "content": "<p>Thanks for sharing! </p>\n<p>I tried this on the masks and run-length encodings given in our competition, and it seems to me that the encoding given in 'train_rles.csv' is slightly different than the one produced by the methods given here. Here's my code: </p>\n<blockquote>\n  <p>train_csv = pd.read_csv('/kaggle/input/blood-vessel-segmentation/train_rles.csv')<br>\n  folder_path_mask = '/kaggle/input/blood-vessel-segmentation/train/kidney_1_dense/labels'<br>\n  tif_files = sorted([file for file in os.listdir(folder_path_mask) if file.endswith('.tif')])</p>\n  <p>index = 1000<br>\n  tif_file = tif_files[index]<br>\n  mask_path = os.path.join(folder_path_mask, tif_file)<br>\n  mask = tifffile.imread(mask_path)<br>\n  mask = mask/255.0<br>\n  print(np.unique(mask))</p>\n  <p>plt.imshow(mask)<br>\n  plt.title(\"Input Mask\")<br>\n  plt.show()<br>\n  rle = mask2rle(mask)<br>\n  correct_rle = train_csv[\"rle\"].iloc[index]</p>\n  <p>rle_to_mask = rle2mask(rle, shape=(mask.shape[1],mask.shape[0]))<br>\n  plt.imshow(rle_to_mask)<br>\n  plt.title(\"Reconstruction of given mask based on RLE encoding by 'mask2rle' \")<br>\n  plt.show()</p>\n  <p>rle_to_mask2 = rle2mask(correct_rle, shape=(mask.shape[1],mask.shape[0]))<br>\n  plt.imshow(rle_to_mask2)<br>\n  plt.title(\"Reconstruction of given mask based on RLE encoding given in train_rles.csv \")<br>\n  plt.show()</p>\n</blockquote>\n<p>This correctly reconstructs the mask using the RLE obtained by mask2rle, but does <strong>not</strong> correctly reconstruct the image based on the RLE given in 'train_rles.csv'. </p>\n<p>You'll notice that I chose 'shape=(mask.shape[1],mask.shape[0])'. If you instead choose 'shape=(mask.shape[0],mask.shape[1])' the reconstruction of the mask based on the RLE encoding obtained by mask2rle no longer works, but the reconstruction of the mask based on the RLE given in 'train_rles.csv' <em>almost</em> works (it returns a transposed version of the mask). </p>\n<p>Also, the lengths of the RLEs in 'train_rles.csv' with the lengths of the RLEs obtained by 'mask2rle' seem to be different: </p>\n<blockquote>\n  <p>print(f'length of mask2rle:  {len(rle)} and length of correct_rle: {len(correct_rle)}')</p>\n</blockquote>\n<p>Do you have any idea how to modify this code to get consistent results? </p>",
      "votes": null,
      "replies": [
        {
          "id": 2522221,
          "author_name": "mpwolke",
          "author_url": "",
          "post_date": "11/12/2023 14:11:03",
          "content": "<p>Hi F. Konrad,<br>\nOn this competition we have RLE \"in action\":</p>\n<p>Blood Vessel Mask to RLE- By Stpete Ishii<br>\n<a href=\"https://www.kaggle.com/code/stpeteishii/blood-vessel-mask-to-rle\" target=\"_blank\">https://www.kaggle.com/code/stpeteishii/blood-vessel-mask-to-rle</a></p>\n<p>RLE SenNet+HOA: RLE decode/encode demo submission - By Jirka Borovec<br>\n<a href=\"https://www.kaggle.com/code/jirkaborovec/sennet-hoa-rle-decode-encode-demo-submission\" target=\"_blank\">https://www.kaggle.com/code/jirkaborovec/sennet-hoa-rle-decode-encode-demo-submission</a></p>\n<p>And On the previous Hacking  the Human body:</p>\n<p>EDA – HuBMAP+HPA – Organ Segmentation By Darien Schettler</p>\n<p>Input 8:<br>\n<a href=\"https://www.kaggle.com/code/dschettler8845/eda-hubmap-hpa-organ-segmentation\" target=\"_blank\">https://www.kaggle.com/code/dschettler8845/eda-hubmap-hpa-organ-segmentation</a></p>\n<p>But I don't know how to apply Paulo's RLE utility script. I'm just a beginner 😏</p>",
          "votes": null,
          "replies": [
            {
              "id": 2522349,
              "author_name": "felixkonrad",
              "author_url": "",
              "post_date": "11/12/2023 15:55:01",
              "content": "<p>Thanks for the links. </p>\n<p>Paulo Pinto seems to have another Notebook for image-to-RLE conversion (<a href=\"https://www.kaggle.com/code/paulorzp/run-length-encode-and-decode/script)\" target=\"_blank\">https://www.kaggle.com/code/paulorzp/run-length-encode-and-decode/script)</a>. This one was linked in the competition overview. </p>\n<p>I had no issues running this program and it gave me the correct results, so I'd recommend using this one. </p>\n<p>Good luck to everyone! </p>",
              "votes": null,
              "replies": [
                {
                  "id": 2522378,
                  "author_name": "mpwolke",
                  "author_url": "",
                  "post_date": "11/12/2023 16:09:31",
                  "content": "<p>In fact, he has 3 RLE (Those below were made 6 y ago)</p>\n<p><a href=\"https://www.kaggle.com/code/paulorzp/run-length-encode-and-decode\" target=\"_blank\">https://www.kaggle.com/code/paulorzp/run-length-encode-and-decode</a></p>\n<p><a href=\"https://www.kaggle.com/code/paulorzp/fast-run-length-encode\" target=\"_blank\">https://www.kaggle.com/code/paulorzp/fast-run-length-encode</a> (On Carvana Image Masking Challenge) </p>\n<p>I think your link is page 404.</p>\n<p>Thank you Konrad. Good luck on this competition!</p>",
                  "votes": null,
                  "replies": []
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "id": 2522526,
      "author_name": "pangyuteng",
      "author_url": "",
      "post_date": "11/12/2023 18:37:00",
      "content": "<p>Thank you for sharing! Confirming paulorzp's \"run-length-encode-and-decode\" seems to match the rle string provided in \"/kaggle/input/blood-vessel-segmentation/train_rles.csv\"</p>\n<p>I have verified by serializing the mask in tif (via function \"rle_encode\") then asserting the output string against those provided in the csv file.  The \"rle_decode\" function also works - via asserting 0 against \"np.sum(tif_mask-deserialized_mask)\".</p>\n<p>In the \"rle_encode\" function, you just have to check for empty string \"\" and replace it with \"1 0\", e.g below snippet:</p>\n<pre><code>...\n    mystr = .((x)  x  runs)\n     mystr == :\n        mystr = \n     mystr\n</code></pre>\n<p><a href=\"https://www.kaggle.com/code/paulorzp/run-length-encode-and-decode/script\" target=\"_blank\">https://www.kaggle.com/code/paulorzp/run-length-encode-and-decode/script</a></p>",
      "votes": null,
      "replies": [
        {
          "id": 2522606,
          "author_name": "mpwolke",
          "author_url": "",
          "post_date": "11/12/2023 21:12:48",
          "content": "<p>You're doing great Pangyuteng.<br>\nI've already been in yours \"tiff-to-nifti visualize using ITKSNAP\".</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 2562644,
          "author_name": "sacuscreed",
          "author_url": "",
          "post_date": "12/15/2023 15:25:59",
          "content": "<p>I was starting going crazy. I suspected something like that, thanks for the clarification.</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "2516726": "#RLE functions - Run Lenght Encode & Decode By Paulo Pinto\n\nhttps://www.kaggle.com/code/paulorzp/rle-functions-run-lenght-encode-decode/script\n\nhttps://www.kaggle.com/code/paulorzp/run-length-encode-and-decode\n\nhttps://www.kaggle.com/code/paulorzp/fast-run-length-encode (On  Carvana Image Masking Challenge)\n\nThat's the most copied helper function. Don't forget to vote Paulo's script!\n\nWhile I was reading Kaggle Notebooks from the last competitions (HubMap Kidney) and the Human Body comp, I found out that many have included (sources by Paulo Pinto snippet)\n\nUpvoting someone's work is how we show our gratitude for helping us to go forward.\n\nBy the way, that script has already 4years. With so many skilled Data Scientists, it's about time to create new innovative segmenting Public Notebooks to improve and prolongue Human life.\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3012786%2F54665c27112c1e2fd873a7ef9bf75c71%2FCaptura%20de%20tela%202023-11-07%20193418.png?generation=1699396497677290&alt=media)\n\n\n\n\n#I'm recycling my own previous topics on Hacking any Human organ : )",
    "2522158": "Thanks for sharing! \n\nI tried this on the masks and run-length encodings given in our competition, and it seems to me that the encoding given in 'train_rles.csv' is slightly different than the one produced by the methods given here. Here's my code: \n\n> train_csv = pd.read_csv('/kaggle/input/blood-vessel-segmentation/train_rles.csv')\nfolder_path_mask = '/kaggle/input/blood-vessel-segmentation/train/kidney_1_dense/labels'\ntif_files = sorted([file for file in os.listdir(folder_path_mask) if file.endswith('.tif')])\n\n>index = 1000\ntif_file = tif_files[index]\nmask_path = os.path.join(folder_path_mask, tif_file)\nmask = tifffile.imread(mask_path)\nmask = mask/255.0\nprint(np.unique(mask))\n\n>plt.imshow(mask)\nplt.title(\"Input Mask\")\nplt.show()\nrle = mask2rle(mask)\ncorrect_rle = train_csv[\"rle\"].iloc[index]\n\n>rle_to_mask = rle2mask(rle, shape=(mask.shape[1],mask.shape[0]))\nplt.imshow(rle_to_mask)\nplt.title(\"Reconstruction of given mask based on RLE encoding by 'mask2rle' \")\nplt.show()\n\n>rle_to_mask2 = rle2mask(correct_rle, shape=(mask.shape[1],mask.shape[0]))\nplt.imshow(rle_to_mask2)\nplt.title(\"Reconstruction of given mask based on RLE encoding given in train_rles.csv \")\nplt.show()\n\nThis correctly reconstructs the mask using the RLE obtained by mask2rle, but does **not** correctly reconstruct the image based on the RLE given in 'train_rles.csv'. \n\nYou'll notice that I chose 'shape=(mask.shape[1],mask.shape[0])'. If you instead choose 'shape=(mask.shape[0],mask.shape[1])' the reconstruction of the mask based on the RLE encoding obtained by mask2rle no longer works, but the reconstruction of the mask based on the RLE given in 'train_rles.csv' *almost* works (it returns a transposed version of the mask). \n\nAlso, the lengths of the RLEs in 'train_rles.csv' with the lengths of the RLEs obtained by 'mask2rle' seem to be different: \n> print(f'length of mask2rle:  {len(rle)} and length of correct_rle: {len(correct_rle)}')\n\nDo you have any idea how to modify this code to get consistent results?",
    "2522221": "Hi F. Konrad,\nOn this competition we have RLE \"in action\":\n\nBlood Vessel Mask to RLE- By Stpete Ishii\nhttps://www.kaggle.com/code/stpeteishii/blood-vessel-mask-to-rle\n\nRLE SenNet+HOA: RLE decode/encode demo submission - By Jirka Borovec\nhttps://www.kaggle.com/code/jirkaborovec/sennet-hoa-rle-decode-encode-demo-submission\n\nAnd On the previous Hacking  the Human body:\n\nEDA – HuBMAP+HPA – Organ Segmentation By Darien Schettler\n\nInput 8:\nhttps://www.kaggle.com/code/dschettler8845/eda-hubmap-hpa-organ-segmentation\n\nBut I don't know how to apply Paulo's RLE utility script. I'm just a beginner 😏",
    "2522349": "Thanks for the links. \n\nPaulo Pinto seems to have another Notebook for image-to-RLE conversion (https://www.kaggle.com/code/paulorzp/run-length-encode-and-decode/script). This one was linked in the competition overview. \n\nI had no issues running this program and it gave me the correct results, so I'd recommend using this one. \n\nGood luck to everyone!",
    "2522378": "In fact, he has 3 RLE (Those below were made 6 y ago)\n\nhttps://www.kaggle.com/code/paulorzp/run-length-encode-and-decode\n\nhttps://www.kaggle.com/code/paulorzp/fast-run-length-encode (On Carvana Image Masking Challenge) \n\nI think your link is page 404.\n\nThank you Konrad. Good luck on this competition!",
    "2522526": "Thank you for sharing! Confirming paulorzp's \"run-length-encode-and-decode\" seems to match the rle string provided in \"/kaggle/input/blood-vessel-segmentation/train_rles.csv\"\n\nI have verified by serializing the mask in tif (via function \"rle_encode\") then asserting the output string against those provided in the csv file.  The \"rle_decode\" function also works - via asserting 0 against \"np.sum(tif_mask-deserialized_mask)\".\n\nIn the \"rle_encode\" function, you just have to check for empty string \"\" and replace it with \"1 0\", e.g below snippet:\n\n\n```\n...\n    mystr = ' '.join(str(x) for x in runs)\n    if mystr == \"\":\n        mystr = \"1 0\"\n    return mystr\n\n```\n\nhttps://www.kaggle.com/code/paulorzp/run-length-encode-and-decode/script",
    "2522606": "You're doing great Pangyuteng.\nI've already been in yours \"tiff-to-nifti visualize using ITKSNAP\".",
    "2562644": "I was starting going crazy. I suspected something like that, thanks for the clarification."
  },
  "source": "meta"
}