{
  "id": 411448,
  "title": "Split fragment 2",
  "url": "/competitions/vesuvius-challenge-ink-detection/discussion/411448",
  "author_name": "",
  "post_date": "2023-05-19T08:57:37.157692500Z",
  "votes": null,
  "comment_count": 1,
  "views": 0,
  "content": "<p>How to split the fragment 2 as 2 fragments a and b</p>",
  "messages": [
    {
      "id": "2265460",
      "postDate": "05/19/2023 08:57:37",
      "content": "<p>How to split the fragment 2 as 2 fragments a and b</p>",
      "rawMarkdown": "How to split the fragment 2 as 2 fragments a and b",
      "votes": null
    },
    {
      "id": "2265842",
      "postDate": "05/19/2023 14:51:30",
      "content": "<p>For really basic stuff like this i prefer ask chat gpt..<br>\nhere is a fast  example code i use to split the tif horizontally and you can just change .tif with png to do the same with the mask, label and ir…</p>\n<pre><code>import cv2\nimport os\n\n\n# Folder path containing the images** EDIT with the kaggle input path**\nfolder_path = '/path/train/2/surface_volume'\n\n# Create new folders for saving the split images\noutput_folder_part1 = '/path/basesplit/2a'\noutput_folder_part2 = '/path/basesplit/2b'\n\nos.makedirs(output_folder_part1, exist_ok=True)\nos.makedirs(output_folder_part2, exist_ok=True)\n\n# Process each image one at a time\nfor filename in os.listdir(folder_path):\n    if filename.endswith('.tif'):  # Specify the file extension of your images\n        img_path = os.path.join(folder_path, filename)\n        img = cv2.imread(img_path)\n\n        # Split the image into two parts CONTROL where to SLICE (Here slice at 6000 pixels height)\n        split_pixels = 6000\n        height, width, channels = img.shape\n        img_part1 = img[:split_pixels, :, :]\n        img_part2 = img[split_pixels:, :, :]\n\n        # Save the split images to the respective folders with the same name as the original image\n        output_path_part1 = os.path.join(output_folder_part1, filename)\n        output_path_part2 = os.path.join(output_folder_part2, filename)\n        cv2.imwrite(output_path_part1, img_part1)\n        cv2.imwrite(output_path_part2, img_part2)\n\n        print(f'Saved split images of {filename} to {output_folder_part1} and {output_folder_part2}')\n\nprint(f'Split and saved {len(os.listdir(folder_path))} images to {output_folder_part1}, {output_folder_part2}')\n</code></pre>",
      "rawMarkdown": "For really basic stuff like this i prefer ask chat gpt..\nhere is a fast  example code i use to split the tif horizontally and you can just change .tif with png to do the same with the mask, label and ir...\n\n```\nimport cv2\nimport os\n\n\n# Folder path containing the images** EDIT with the kaggle input path**\nfolder_path = '/path/train/2/surface_volume'\n\n# Create new folders for saving the split images\noutput_folder_part1 = '/path/basesplit/2a'\noutput_folder_part2 = '/path/basesplit/2b'\n\nos.makedirs(output_folder_part1, exist_ok=True)\nos.makedirs(output_folder_part2, exist_ok=True)\n\n# Process each image one at a time\nfor filename in os.listdir(folder_path):\n    if filename.endswith('.tif'):  # Specify the file extension of your images\n        img_path = os.path.join(folder_path, filename)\n        img = cv2.imread(img_path)\n\n        # Split the image into two parts CONTROL where to SLICE (Here slice at 6000 pixels height)\n        split_pixels = 6000\n        height, width, channels = img.shape\n        img_part1 = img[:split_pixels, :, :]\n        img_part2 = img[split_pixels:, :, :]\n\n        # Save the split images to the respective folders with the same name as the original image\n        output_path_part1 = os.path.join(output_folder_part1, filename)\n        output_path_part2 = os.path.join(output_folder_part2, filename)\n        cv2.imwrite(output_path_part1, img_part1)\n        cv2.imwrite(output_path_part2, img_part2)\n\n        print(f'Saved split images of {filename} to {output_folder_part1} and {output_folder_part2}')\n\nprint(f'Split and saved {len(os.listdir(folder_path))} images to {output_folder_part1}, {output_folder_part2}')\n```",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 2265842,
      "author_name": "iraqbot",
      "author_url": "",
      "post_date": "05/19/2023 14:51:30",
      "content": "<p>For really basic stuff like this i prefer ask chat gpt..<br>\nhere is a fast  example code i use to split the tif horizontally and you can just change .tif with png to do the same with the mask, label and ir…</p>\n<pre><code>import cv2\nimport os\n\n\n# Folder path containing the images** EDIT with the kaggle input path**\nfolder_path = '/path/train/2/surface_volume'\n\n# Create new folders for saving the split images\noutput_folder_part1 = '/path/basesplit/2a'\noutput_folder_part2 = '/path/basesplit/2b'\n\nos.makedirs(output_folder_part1, exist_ok=True)\nos.makedirs(output_folder_part2, exist_ok=True)\n\n# Process each image one at a time\nfor filename in os.listdir(folder_path):\n    if filename.endswith('.tif'):  # Specify the file extension of your images\n        img_path = os.path.join(folder_path, filename)\n        img = cv2.imread(img_path)\n\n        # Split the image into two parts CONTROL where to SLICE (Here slice at 6000 pixels height)\n        split_pixels = 6000\n        height, width, channels = img.shape\n        img_part1 = img[:split_pixels, :, :]\n        img_part2 = img[split_pixels:, :, :]\n\n        # Save the split images to the respective folders with the same name as the original image\n        output_path_part1 = os.path.join(output_folder_part1, filename)\n        output_path_part2 = os.path.join(output_folder_part2, filename)\n        cv2.imwrite(output_path_part1, img_part1)\n        cv2.imwrite(output_path_part2, img_part2)\n\n        print(f'Saved split images of {filename} to {output_folder_part1} and {output_folder_part2}')\n\nprint(f'Split and saved {len(os.listdir(folder_path))} images to {output_folder_part1}, {output_folder_part2}')\n</code></pre>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "2265460": "How to split the fragment 2 as 2 fragments a and b",
    "2265842": "For really basic stuff like this i prefer ask chat gpt..\nhere is a fast  example code i use to split the tif horizontally and you can just change .tif with png to do the same with the mask, label and ir...\n\n```\nimport cv2\nimport os\n\n\n# Folder path containing the images** EDIT with the kaggle input path**\nfolder_path = '/path/train/2/surface_volume'\n\n# Create new folders for saving the split images\noutput_folder_part1 = '/path/basesplit/2a'\noutput_folder_part2 = '/path/basesplit/2b'\n\nos.makedirs(output_folder_part1, exist_ok=True)\nos.makedirs(output_folder_part2, exist_ok=True)\n\n# Process each image one at a time\nfor filename in os.listdir(folder_path):\n    if filename.endswith('.tif'):  # Specify the file extension of your images\n        img_path = os.path.join(folder_path, filename)\n        img = cv2.imread(img_path)\n\n        # Split the image into two parts CONTROL where to SLICE (Here slice at 6000 pixels height)\n        split_pixels = 6000\n        height, width, channels = img.shape\n        img_part1 = img[:split_pixels, :, :]\n        img_part2 = img[split_pixels:, :, :]\n\n        # Save the split images to the respective folders with the same name as the original image\n        output_path_part1 = os.path.join(output_folder_part1, filename)\n        output_path_part2 = os.path.join(output_folder_part2, filename)\n        cv2.imwrite(output_path_part1, img_part1)\n        cv2.imwrite(output_path_part2, img_part2)\n\n        print(f'Saved split images of {filename} to {output_folder_part1} and {output_folder_part2}')\n\nprint(f'Split and saved {len(os.listdir(folder_path))} images to {output_folder_part1}, {output_folder_part2}')\n```"
  },
  "source": "meta"
}