{
  "id": 222124,
  "title": "please explain famous rle2mask function breaking details to last atom?",
  "url": "/competitions/hubmap-kidney-segmentation/discussion/222124",
  "author_name": "",
  "post_date": "2021-02-25T11:53:48.814802Z",
  "votes": 2,
  "comment_count": 2,
  "views": 0,
  "content": "<p>I have difficulty understanding the function…why start-=1? and other things…plz explain</p>",
  "messages": [
    {
      "id": "1217910",
      "postDate": "02/25/2021 11:53:48",
      "content": "<p>I have difficulty understanding the function…why start-=1? and other things…plz explain</p>",
      "rawMarkdown": "I have difficulty understanding the function...why start-=1? and other things...plz explain",
      "votes": null
    },
    {
      "id": "1219968",
      "postDate": "02/27/2021 12:14:07",
      "content": "<p>Hi Kartika, mask_data is stored in rle encoding. You can check this out if you wanna know how rle encoding works <a href=\"url\" target=\"_blank\">http://stoimen.com/2012/01/09/computer-algorithms-data-compression-with-run-length-encoding/</a><br>\nNow you can try and print the rle encoding file, it is stored in this way:<br>\n296084587 4 296115835 6 296115859 14 296147109…<br>\n[296084587] -&gt; is pixel /index<br>\n[4] -&gt; repetition till<br>\nmeaning from 296084586 to 296084586+4 there is repetition.<br>\nNow see this rle2mask function:</p>\n<p>def rleToMask(rleString,height,width):<br>\n      rows,cols = height,width ### this is the size of mask you want<br>\n      rleNumbers = [int(numstring) for numstring in rleString.split(' ')] ## converting the rle_encoded_data into a list<br>\n      rlePairs = np.array(rleNumbers).reshape(-1,2) ## converting the list into an numpy array of size (anything, 2) <br>\n      img = np.zeros(rows*cols,dtype=np.uint8) ## creating a mask/image with black colour <br>\n      for index,length in rlePairs:<br>\n        index -= 1 ## 296084587 -1 = 296084586<br>\n        img[index:index+length] = 255 ## colouring white pixels from 296084586 to 296084586+4<br>\n      img = img.reshape(cols,rows) ## reshaping <br>\n      img = img.T ## transpose<br>\n      return img</p>",
      "rawMarkdown": "Hi Kartika, mask_data is stored in rle encoding. You can check this out if you wanna know how rle encoding works [http://stoimen.com/2012/01/09/computer-algorithms-data-compression-with-run-length-encoding/](url)\nNow you can try and print the rle encoding file, it is stored in this way:\n296084587 4 296115835 6 296115859 14 296147109...\n[296084587] -> is pixel /index\n[4] -> repetition till\nmeaning from 296084586 to 296084586+4 there is repetition.\nNow see this rle2mask function:\n\ndef rleToMask(rleString,height,width):\n      rows,cols = height,width ### this is the size of mask you want\n      rleNumbers = [int(numstring) for numstring in rleString.split(' ')] ## converting the rle_encoded_data into a list\n      rlePairs = np.array(rleNumbers).reshape(-1,2) ## converting the list into an numpy array of size (anything, 2) \n      img = np.zeros(rows*cols,dtype=np.uint8) ## creating a mask/image with black colour \n      for index,length in rlePairs:\n        index -= 1 ## 296084587 -1 = 296084586\n        img[index:index+length] = 255 ## colouring white pixels from 296084586 to 296084586+4\n      img = img.reshape(cols,rows) ## reshaping \n      img = img.T ## transpose\n      return img",
      "votes": null
    },
    {
      "id": "1221224",
      "postDate": "02/28/2021 19:09:29",
      "content": "<p>thank you ….that helps</p>",
      "rawMarkdown": "thank you ....that helps",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1219968,
      "author_name": "arpitjoshi333",
      "author_url": "",
      "post_date": "02/27/2021 12:14:07",
      "content": "<p>Hi Kartika, mask_data is stored in rle encoding. You can check this out if you wanna know how rle encoding works <a href=\"url\" target=\"_blank\">http://stoimen.com/2012/01/09/computer-algorithms-data-compression-with-run-length-encoding/</a><br>\nNow you can try and print the rle encoding file, it is stored in this way:<br>\n296084587 4 296115835 6 296115859 14 296147109…<br>\n[296084587] -&gt; is pixel /index<br>\n[4] -&gt; repetition till<br>\nmeaning from 296084586 to 296084586+4 there is repetition.<br>\nNow see this rle2mask function:</p>\n<p>def rleToMask(rleString,height,width):<br>\n      rows,cols = height,width ### this is the size of mask you want<br>\n      rleNumbers = [int(numstring) for numstring in rleString.split(' ')] ## converting the rle_encoded_data into a list<br>\n      rlePairs = np.array(rleNumbers).reshape(-1,2) ## converting the list into an numpy array of size (anything, 2) <br>\n      img = np.zeros(rows*cols,dtype=np.uint8) ## creating a mask/image with black colour <br>\n      for index,length in rlePairs:<br>\n        index -= 1 ## 296084587 -1 = 296084586<br>\n        img[index:index+length] = 255 ## colouring white pixels from 296084586 to 296084586+4<br>\n      img = img.reshape(cols,rows) ## reshaping <br>\n      img = img.T ## transpose<br>\n      return img</p>",
      "votes": null,
      "replies": [
        {
          "id": 1221224,
          "author_name": "kartikasharma",
          "author_url": "",
          "post_date": "02/28/2021 19:09:29",
          "content": "<p>thank you ….that helps</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1217910": "I have difficulty understanding the function...why start-=1? and other things...plz explain",
    "1219968": "Hi Kartika, mask_data is stored in rle encoding. You can check this out if you wanna know how rle encoding works [http://stoimen.com/2012/01/09/computer-algorithms-data-compression-with-run-length-encoding/](url)\nNow you can try and print the rle encoding file, it is stored in this way:\n296084587 4 296115835 6 296115859 14 296147109...\n[296084587] -> is pixel /index\n[4] -> repetition till\nmeaning from 296084586 to 296084586+4 there is repetition.\nNow see this rle2mask function:\n\ndef rleToMask(rleString,height,width):\n      rows,cols = height,width ### this is the size of mask you want\n      rleNumbers = [int(numstring) for numstring in rleString.split(' ')] ## converting the rle_encoded_data into a list\n      rlePairs = np.array(rleNumbers).reshape(-1,2) ## converting the list into an numpy array of size (anything, 2) \n      img = np.zeros(rows*cols,dtype=np.uint8) ## creating a mask/image with black colour \n      for index,length in rlePairs:\n        index -= 1 ## 296084587 -1 = 296084586\n        img[index:index+length] = 255 ## colouring white pixels from 296084586 to 296084586+4\n      img = img.reshape(cols,rows) ## reshaping \n      img = img.T ## transpose\n      return img",
    "1221224": "thank you ....that helps"
  },
  "source": "meta"
}