{
  "id": 75509,
  "title": "How to convert 4 channel image to single RGB image? like http://v18.proteinatlas.org/images/10580/1610_C1_1_blue_red_green_yellow.jpg",
  "url": "/competitions/human-protein-atlas-image-classification/discussion/75509",
  "author_name": "",
  "post_date": "2018-12-22T14:13:04.229536100Z",
  "votes": 1,
  "comment_count": 2,
  "views": 0,
  "content": "<p>In external data, I find <a href=\"http://v18.proteinatlas.org/images/10580/1610_C1_1_blue_red_green_yellow.jpg\">http://v18.proteinatlas.org/images/10580/1610_C1_1_blue_red_green_yellow.jpg</a>, it is single RGB image, but I think it is converted from 4 channel image,  do you have idea how to do it  like proteinatlas ever had done? thanks! </p>",
  "messages": [
    {
      "id": "443827",
      "postDate": "12/22/2018 14:13:04",
      "content": "<p>In external data, I find <a href=\"http://v18.proteinatlas.org/images/10580/1610_C1_1_blue_red_green_yellow.jpg\">http://v18.proteinatlas.org/images/10580/1610_C1_1_blue_red_green_yellow.jpg</a>, it is single RGB image, but I think it is converted from 4 channel image,  do you have idea how to do it  like proteinatlas ever had done? thanks! </p>",
      "rawMarkdown": "In external data, I find http://v18.proteinatlas.org/images/10580/1610_C1_1_blue_red_green_yellow.jpg, it is single RGB image, but I think it is converted from 4 channel image,  do you have idea how to do it  like proteinatlas ever had done? thanks!",
      "votes": null
    },
    {
      "id": "443828",
      "postDate": "12/22/2018 14:14:44",
      "content": "<p>convert.exe is able to do it, but I don't know how to combine the yellow channel. \nwho know proteinatlas how to achieve it? </p>",
      "rawMarkdown": "convert.exe is able to do it, but I don't know how to combine the yellow channel. \nwho know proteinatlas how to achieve it?",
      "votes": null
    },
    {
      "id": "444481",
      "postDate": "12/24/2018 05:08:34",
      "content": "<p>You can use <code>cv2.imwrite('name.tif',data)</code> and <code>cv2.imread('name.tif',-1)</code> functions to write and read 4 channel images. You can generate an image with this method and check that loading gives you exactly the same as <code>data</code>. <code>data</code> - is (sz,sz,4) array that can be generated from the original images with using the following function:</p>\n\n<pre><code>def open_rgby(arch,id,t='png'): #a function that reads RGBY image\n    colors = ['red','green','blue','yellow']\n    flags = cv2.IMREAD_GRAYSCALE\n    img = [cv2.imdecode(np.frombuffer(arch.read(id+'_'+color+'.'+t), np.uint8), flags)#.astype(np.float32)/255\n           for color in colors]\n    return np.stack(img, axis=-1)\n</code></pre>",
      "rawMarkdown": "You can use `cv2.imwrite('name.tif',data)` and `cv2.imread('name.tif',-1)` functions to write and read 4 channel images. You can generate an image with this method and check that loading gives you exactly the same as `data`. `data` - is (sz,sz,4) array that can be generated from the original images with using the following function:\n\n    def open_rgby(arch,id,t='png'): #a function that reads RGBY image\n        colors = ['red','green','blue','yellow']\n        flags = cv2.IMREAD_GRAYSCALE\n        img = [cv2.imdecode(np.frombuffer(arch.read(id+'_'+color+'.'+t), np.uint8), flags)#.astype(np.float32)/255\n               for color in colors]\n        return np.stack(img, axis=-1)",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 443828,
      "author_name": "crilinux",
      "author_url": "",
      "post_date": "12/22/2018 14:14:44",
      "content": "<p>convert.exe is able to do it, but I don't know how to combine the yellow channel. \nwho know proteinatlas how to achieve it? </p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 444481,
      "author_name": "iafoss",
      "author_url": "",
      "post_date": "12/24/2018 05:08:34",
      "content": "<p>You can use <code>cv2.imwrite('name.tif',data)</code> and <code>cv2.imread('name.tif',-1)</code> functions to write and read 4 channel images. You can generate an image with this method and check that loading gives you exactly the same as <code>data</code>. <code>data</code> - is (sz,sz,4) array that can be generated from the original images with using the following function:</p>\n\n<pre><code>def open_rgby(arch,id,t='png'): #a function that reads RGBY image\n    colors = ['red','green','blue','yellow']\n    flags = cv2.IMREAD_GRAYSCALE\n    img = [cv2.imdecode(np.frombuffer(arch.read(id+'_'+color+'.'+t), np.uint8), flags)#.astype(np.float32)/255\n           for color in colors]\n    return np.stack(img, axis=-1)\n</code></pre>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "443827": "In external data, I find http://v18.proteinatlas.org/images/10580/1610_C1_1_blue_red_green_yellow.jpg, it is single RGB image, but I think it is converted from 4 channel image,  do you have idea how to do it  like proteinatlas ever had done? thanks!",
    "443828": "convert.exe is able to do it, but I don't know how to combine the yellow channel. \nwho know proteinatlas how to achieve it?",
    "444481": "You can use `cv2.imwrite('name.tif',data)` and `cv2.imread('name.tif',-1)` functions to write and read 4 channel images. You can generate an image with this method and check that loading gives you exactly the same as `data`. `data` - is (sz,sz,4) array that can be generated from the original images with using the following function:\n\n    def open_rgby(arch,id,t='png'): #a function that reads RGBY image\n        colors = ['red','green','blue','yellow']\n        flags = cv2.IMREAD_GRAYSCALE\n        img = [cv2.imdecode(np.frombuffer(arch.read(id+'_'+color+'.'+t), np.uint8), flags)#.astype(np.float32)/255\n               for color in colors]\n        return np.stack(img, axis=-1)"
  },
  "source": "meta"
}