{
  "id": 223745,
  "title": "HPA masks not working in test data",
  "url": "/competitions/hpa-single-cell-image-classification/discussion/223745",
  "author_name": "glopezzz",
  "post_date": "2021-03-05T10:34:05.545000",
  "votes": 3,
  "comment_count": 5,
  "views": 0,
  "content": "<p>Hi,</p>\n<p>I've used the <a href=\"https://github.com/CellProfiling/HPA-Cell-Segmentation\" target=\"_blank\">HPA Cell Segmentation</a> with no trouble on the training data, but when I try the same code with the test data, it doesn't work.</p>\n<p>The <code>segmentator.pred_cells()</code> works fine, but then the <code>label_cell()</code> returns an empty array<br>\nI'll show you an example:</p>\n<pre><code>image = test_files[10]\npaths = [os.path.join(TEST, path) for path in image]\n\narrays = image_to_arrays(paths)\nnuclei = arrays[1]\nnuc_segmentations = segmentator.pred_nuclei([nuclei])\n\ninter_step = [[i] for i in paths[:-1]]\ncell_segmentations = segmentator.pred_cells(inter_step)\n\nf, ax = plt.subplots(1, 2, figsize=(16,16))\nax[0].imshow(get_blended_image(arrays))\nax[0].set_title('Original Cells', size=20)\nax[1].imshow(cell_segmentations[0])\nax[1].set_title('Segmented Cells', size=20)\nplt.show()\n\nnuclei_mask = label_nuclei(nuc_segmentations[0])\ncell_nuclei_mask, cell_mask = label_cell(nuc_segmentations[0], cell_segmentations[0])\n\nf, ax = plt.subplots(1, 3, figsize=(16,16))\nax[0].imshow(nuclei_mask)\nax[0].set_title('Nuclei Mask', size=20)\nax[1].imshow(cell_nuclei_mask)\nax[1].set_title('Cell Nuclei Mask', size=20)\nax[2].imshow(cell_mask)\nax[2].set_title('Cell Mask', size=20)\nplt.show()\n</code></pre>\n<p>It won't let me upload images, so you can check it out on this <a href=\"https://github.com/CellProfiling/HPA-Cell-Segmentation/issues/20\" target=\"_blank\">issue </a> I've oppened in Github:</p>\n<p>Thank you in advance!</p>",
  "messages": [
    {
      "id": 1227241,
      "postDate": "2021-03-05T10:34:05.547Z",
      "content": "<p>Hi,</p>\n<p>I've used the <a href=\"https://github.com/CellProfiling/HPA-Cell-Segmentation\" target=\"_blank\">HPA Cell Segmentation</a> with no trouble on the training data, but when I try the same code with the test data, it doesn't work.</p>\n<p>The <code>segmentator.pred_cells()</code> works fine, but then the <code>label_cell()</code> returns an empty array<br>\nI'll show you an example:</p>\n<pre><code>image = test_files[10]\npaths = [os.path.join(TEST, path) for path in image]\n\narrays = image_to_arrays(paths)\nnuclei = arrays[1]\nnuc_segmentations = segmentator.pred_nuclei([nuclei])\n\ninter_step = [[i] for i in paths[:-1]]\ncell_segmentations = segmentator.pred_cells(inter_step)\n\nf, ax = plt.subplots(1, 2, figsize=(16,16))\nax[0].imshow(get_blended_image(arrays))\nax[0].set_title('Original Cells', size=20)\nax[1].imshow(cell_segmentations[0])\nax[1].set_title('Segmented Cells', size=20)\nplt.show()\n\nnuclei_mask = label_nuclei(nuc_segmentations[0])\ncell_nuclei_mask, cell_mask = label_cell(nuc_segmentations[0], cell_segmentations[0])\n\nf, ax = plt.subplots(1, 3, figsize=(16,16))\nax[0].imshow(nuclei_mask)\nax[0].set_title('Nuclei Mask', size=20)\nax[1].imshow(cell_nuclei_mask)\nax[1].set_title('Cell Nuclei Mask', size=20)\nax[2].imshow(cell_mask)\nax[2].set_title('Cell Mask', size=20)\nplt.show()\n</code></pre>\n<p>It won't let me upload images, so you can check it out on this <a href=\"https://github.com/CellProfiling/HPA-Cell-Segmentation/issues/20\" target=\"_blank\">issue </a> I've oppened in Github:</p>\n<p>Thank you in advance!</p>",
      "rawMarkdown": "Hi,\n\nI've used the [HPA Cell Segmentation](https://github.com/CellProfiling/HPA-Cell-Segmentation) with no trouble on the training data, but when I try the same code with the test data, it doesn't work.\n\nThe `segmentator.pred_cells()` works fine, but then the `label_cell()` returns an empty array\nI'll show you an example:\n\n```\nimage = test_files[10]\npaths = [os.path.join(TEST, path) for path in image]\n\narrays = image_to_arrays(paths)\nnuclei = arrays[1]\nnuc_segmentations = segmentator.pred_nuclei([nuclei])\n\ninter_step = [[i] for i in paths[:-1]]\ncell_segmentations = segmentator.pred_cells(inter_step)\n\nf, ax = plt.subplots(1, 2, figsize=(16,16))\nax[0].imshow(get_blended_image(arrays))\nax[0].set_title('Original Cells', size=20)\nax[1].imshow(cell_segmentations[0])\nax[1].set_title('Segmented Cells', size=20)\nplt.show()\n\nnuclei_mask = label_nuclei(nuc_segmentations[0])\ncell_nuclei_mask, cell_mask = label_cell(nuc_segmentations[0], cell_segmentations[0])\n\nf, ax = plt.subplots(1, 3, figsize=(16,16))\nax[0].imshow(nuclei_mask)\nax[0].set_title('Nuclei Mask', size=20)\nax[1].imshow(cell_nuclei_mask)\nax[1].set_title('Cell Nuclei Mask', size=20)\nax[2].imshow(cell_mask)\nax[2].set_title('Cell Mask', size=20)\nplt.show()\n```\n\nIt won't let me upload images, so you can check it out on this [issue ](https://github.com/CellProfiling/HPA-Cell-Segmentation/issues/20) I've oppened in Github:\n\nThank you in advance!",
      "votes": 3
    },
    {
      "id": 1243588,
      "postDate": "2021-03-18T10:33:11.067Z",
      "content": "<p>Faced exactly same problem. Thanks for solution. Converting image read to cv2 worked for me as well</p>",
      "rawMarkdown": "Faced exactly same problem. Thanks for solution. Converting image read to cv2 worked for me as well",
      "votes": 1
    },
    {
      "id": 1236923,
      "postDate": "2021-03-13T14:56:59.217Z",
      "content": "<p>test images are uint16, while train ones are uint8. Maybe this is the problem in your case…</p>",
      "rawMarkdown": "test images are uint16, while train ones are uint8. Maybe this is the problem in your case...",
      "votes": 1,
      "replies": [
        {
          "id": 1238680,
          "postDate": "2021-03-15T07:46:34.827Z",
          "content": "<p>Hi, the problem was solved using <code>cv2.imread(image, cv2.IMREAD_GRAYSCALE )</code> instead of <code>Image.open(image)</code></p>\n<p>Thank you though!</p>",
          "rawMarkdown": "Hi, the problem was solved using `cv2.imread(image, cv2.IMREAD_GRAYSCALE )` instead of `Image.open(image)`\n\nThank you though!",
          "votes": 1
        }
      ]
    },
    {
      "id": 1234252,
      "postDate": "2021-03-11T04:41:59.660Z",
      "content": "<p>I set padding = True, the code works well.</p>",
      "rawMarkdown": "I set padding = True, the code works well.",
      "replies": [
        {
          "id": 1234395,
          "postDate": "2021-03-11T08:09:04.810Z",
          "content": "<p>I've tried changin the padding to 'True', but it still doesn't work on test images :c</p>",
          "rawMarkdown": "I've tried changin the padding to 'True', but it still doesn't work on test images :c"
        }
      ]
    }
  ],
  "comments": [
    {
      "id": 1243588,
      "author_name": "Mugdha Hardikar",
      "author_url": "",
      "post_date": "2021-03-18T10:33:11.067000",
      "content": "<p>Faced exactly same problem. Thanks for solution. Converting image read to cv2 worked for me as well</p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 1236923,
      "author_name": "Vladislav Ostankovich",
      "author_url": "",
      "post_date": "2021-03-13T14:56:59.217000",
      "content": "<p>test images are uint16, while train ones are uint8. Maybe this is the problem in your case…</p>",
      "votes": 1,
      "replies": [
        {
          "id": 1238680,
          "author_name": "glopezzz",
          "author_url": "",
          "post_date": "2021-03-15T07:46:34.827000",
          "content": "<p>Hi, the problem was solved using <code>cv2.imread(image, cv2.IMREAD_GRAYSCALE )</code> instead of <code>Image.open(image)</code></p>\n<p>Thank you though!</p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 1234252,
      "author_name": "Zihan Wu",
      "author_url": "",
      "post_date": "2021-03-11T04:41:59.660000",
      "content": "<p>I set padding = True, the code works well.</p>",
      "votes": 0,
      "replies": [
        {
          "id": 1234395,
          "author_name": "glopezzz",
          "author_url": "",
          "post_date": "2021-03-11T08:09:04.810000",
          "content": "<p>I've tried changin the padding to 'True', but it still doesn't work on test images :c</p>",
          "votes": 0,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1227241": "Hi,\n\nI've used the [HPA Cell Segmentation](https://github.com/CellProfiling/HPA-Cell-Segmentation) with no trouble on the training data, but when I try the same code with the test data, it doesn't work.\n\nThe `segmentator.pred_cells()` works fine, but then the `label_cell()` returns an empty array\nI'll show you an example:\n\n```\nimage = test_files[10]\npaths = [os.path.join(TEST, path) for path in image]\n\narrays = image_to_arrays(paths)\nnuclei = arrays[1]\nnuc_segmentations = segmentator.pred_nuclei([nuclei])\n\ninter_step = [[i] for i in paths[:-1]]\ncell_segmentations = segmentator.pred_cells(inter_step)\n\nf, ax = plt.subplots(1, 2, figsize=(16,16))\nax[0].imshow(get_blended_image(arrays))\nax[0].set_title('Original Cells', size=20)\nax[1].imshow(cell_segmentations[0])\nax[1].set_title('Segmented Cells', size=20)\nplt.show()\n\nnuclei_mask = label_nuclei(nuc_segmentations[0])\ncell_nuclei_mask, cell_mask = label_cell(nuc_segmentations[0], cell_segmentations[0])\n\nf, ax = plt.subplots(1, 3, figsize=(16,16))\nax[0].imshow(nuclei_mask)\nax[0].set_title('Nuclei Mask', size=20)\nax[1].imshow(cell_nuclei_mask)\nax[1].set_title('Cell Nuclei Mask', size=20)\nax[2].imshow(cell_mask)\nax[2].set_title('Cell Mask', size=20)\nplt.show()\n```\n\nIt won't let me upload images, so you can check it out on this [issue ](https://github.com/CellProfiling/HPA-Cell-Segmentation/issues/20) I've oppened in Github:\n\nThank you in advance!",
    "1243588": "Faced exactly same problem. Thanks for solution. Converting image read to cv2 worked for me as well",
    "1236923": "test images are uint16, while train ones are uint8. Maybe this is the problem in your case...",
    "1234252": "I set padding = True, the code works well."
  }
}