{
  "id": 413276,
  "title": "Picking Up desired Subvolumes, code editing ask",
  "url": "/competitions/vesuvius-challenge-ink-detection/discussion/413276",
  "author_name": "SALAH ELDIN ELNABARAWY",
  "post_date": "2023-05-27T20:01:48.467000",
  "votes": 4,
  "comment_count": 0,
  "views": 0,
  "content": "<p>Hello, I'm using this notebook as a base code, now<br>\n<a href=\"https://www.kaggle.com/code/danielhavir/vesuvius-challenge-example-submission\" target=\"_blank\">https://www.kaggle.com/code/danielhavir/vesuvius-challenge-example-submission</a></p>\n<p>I'm trying to pick up a subvolume for each 2x2 square pixel, instead of having subvolumes for each pixel.<br>\nI'm trying my best but could anyone help?</p>\n<p>` def getitem(self, index):<br>\ncenter_y, center_x, fragment_id = self.pixels[index]<br>\nz_dim, y_dim, x_dim = self.voxel_shape<br>\nimage_stack = self.image_stacks[fragment_id]<br>\n_, height, width = image_stack.shape</p>\n<pre><code>y_start = center_y - (y_dim // 2)\nx_start = center_x - (x_dim // 2)\ny_end = center_y + (y_dim // 2)\nx_end = center_x + (x_dim // 2)\n\nsubvolume = np.zeros(self.voxel_shape, dtype=np.float32)\nsubvolume[:, :y_dim, :x_dim] = (\n    image_stack[:, y_start:y_end, x_start:x_end].astype(np.float32) / 65535\n)\n\nif self.load_inklabels:\n    inklabel = np.zeros((2, 2), dtype=np.float32)\n    inklabel[:2, :2] = self.labels[fragment_id][center_y-1:center_y+1, center_x-1:center_x+1]\nelse:\n    inklabel = -1.0\n\nreturn torch.from_numpy(subvolume).unsqueeze(0), torch.from_numpy(np.array([inklabel]))`\n</code></pre>\n<hr>\n<p>I think it's all about this part, the rest of the code will not be changed, but how to make take a subvolume, in the same way, that I picked up the inklabel</p>",
  "messages": [
    {
      "id": 2277487,
      "postDate": "2023-05-27T20:01:48.467Z",
      "content": "<p>Hello, I'm using this notebook as a base code, now<br>\n<a href=\"https://www.kaggle.com/code/danielhavir/vesuvius-challenge-example-submission\" target=\"_blank\">https://www.kaggle.com/code/danielhavir/vesuvius-challenge-example-submission</a></p>\n<p>I'm trying to pick up a subvolume for each 2x2 square pixel, instead of having subvolumes for each pixel.<br>\nI'm trying my best but could anyone help?</p>\n<p>` def getitem(self, index):<br>\ncenter_y, center_x, fragment_id = self.pixels[index]<br>\nz_dim, y_dim, x_dim = self.voxel_shape<br>\nimage_stack = self.image_stacks[fragment_id]<br>\n_, height, width = image_stack.shape</p>\n<pre><code>y_start = center_y - (y_dim // 2)\nx_start = center_x - (x_dim // 2)\ny_end = center_y + (y_dim // 2)\nx_end = center_x + (x_dim // 2)\n\nsubvolume = np.zeros(self.voxel_shape, dtype=np.float32)\nsubvolume[:, :y_dim, :x_dim] = (\n    image_stack[:, y_start:y_end, x_start:x_end].astype(np.float32) / 65535\n)\n\nif self.load_inklabels:\n    inklabel = np.zeros((2, 2), dtype=np.float32)\n    inklabel[:2, :2] = self.labels[fragment_id][center_y-1:center_y+1, center_x-1:center_x+1]\nelse:\n    inklabel = -1.0\n\nreturn torch.from_numpy(subvolume).unsqueeze(0), torch.from_numpy(np.array([inklabel]))`\n</code></pre>\n<hr>\n<p>I think it's all about this part, the rest of the code will not be changed, but how to make take a subvolume, in the same way, that I picked up the inklabel</p>",
      "rawMarkdown": "Hello, I'm using this notebook as a base code, now\nhttps://www.kaggle.com/code/danielhavir/vesuvius-challenge-example-submission\n\nI'm trying to pick up a subvolume for each 2x2 square pixel, instead of having subvolumes for each pixel.\nI'm trying my best but could anyone help?\n\n` def getitem(self, index):\ncenter_y, center_x, fragment_id = self.pixels[index]\nz_dim, y_dim, x_dim = self.voxel_shape\nimage_stack = self.image_stacks[fragment_id]\n_, height, width = image_stack.shape\n\n    y_start = center_y - (y_dim // 2)\n    x_start = center_x - (x_dim // 2)\n    y_end = center_y + (y_dim // 2)\n    x_end = center_x + (x_dim // 2)\n\n    subvolume = np.zeros(self.voxel_shape, dtype=np.float32)\n    subvolume[:, :y_dim, :x_dim] = (\n        image_stack[:, y_start:y_end, x_start:x_end].astype(np.float32) / 65535\n    )\n\n    if self.load_inklabels:\n        inklabel = np.zeros((2, 2), dtype=np.float32)\n        inklabel[:2, :2] = self.labels[fragment_id][center_y-1:center_y+1, center_x-1:center_x+1]\n    else:\n        inklabel = -1.0\n\n    return torch.from_numpy(subvolume).unsqueeze(0), torch.from_numpy(np.array([inklabel]))`\n\n****\nI think it's all about this part, the rest of the code will not be changed, but how to make take a subvolume, in the same way, that I picked up the inklabel",
      "votes": 4
    }
  ],
  "comments": [],
  "raw_markdown_by_id": {
    "2277487": "Hello, I'm using this notebook as a base code, now\nhttps://www.kaggle.com/code/danielhavir/vesuvius-challenge-example-submission\n\nI'm trying to pick up a subvolume for each 2x2 square pixel, instead of having subvolumes for each pixel.\nI'm trying my best but could anyone help?\n\n` def getitem(self, index):\ncenter_y, center_x, fragment_id = self.pixels[index]\nz_dim, y_dim, x_dim = self.voxel_shape\nimage_stack = self.image_stacks[fragment_id]\n_, height, width = image_stack.shape\n\n    y_start = center_y - (y_dim // 2)\n    x_start = center_x - (x_dim // 2)\n    y_end = center_y + (y_dim // 2)\n    x_end = center_x + (x_dim // 2)\n\n    subvolume = np.zeros(self.voxel_shape, dtype=np.float32)\n    subvolume[:, :y_dim, :x_dim] = (\n        image_stack[:, y_start:y_end, x_start:x_end].astype(np.float32) / 65535\n    )\n\n    if self.load_inklabels:\n        inklabel = np.zeros((2, 2), dtype=np.float32)\n        inklabel[:2, :2] = self.labels[fragment_id][center_y-1:center_y+1, center_x-1:center_x+1]\n    else:\n        inklabel = -1.0\n\n    return torch.from_numpy(subvolume).unsqueeze(0), torch.from_numpy(np.array([inklabel]))`\n\n****\nI think it's all about this part, the rest of the code will not be changed, but how to make take a subvolume, in the same way, that I picked up the inklabel"
  }
}