# Split Raster
Provide good support for deep learning and computer vision tasks by creating a tiled output from an input raster dataset.
## Use the packages
```bash
pip install splitraster
```
## Try Sample code
The sample image can be found in the GitHub repo.
```python
from splitraster import io
input_image_path = "./data/raw/RGB.png"
gt_image_path = "./data/raw/GT.png"
save_path = "../data/processed/RGB"
crop_size = 256
repetition_rate = 0.5
overwrite = False
n = io.split_image(input_image_path, save_path, crop_size,
repetition_rate=repetition_rate, overwrite=overwrite)
print(f"{n} tiles sample of {input_image_path} are added at {save_path}")
save_path_gt = "./data/processed/GT"
n = io.split_image(gt_image_path, save_path_gt, crop_size,
repetition_rate=repetition_rate, overwrite=overwrite)
print(f"{n} tiles sample of {gt_image_path} are added at {save_path_gt}")
```
Possible results:
```bash
Successfully installed splitraster-0.1.0
❯ python test.py
Input Image File Shape (H, W, D):(1000, 1000, 3)
crop_size=256, stride=128
Padding Image File Shape (H, W, D):(1024, 1024, 3)
There are 49 files in the ./data/processed/RGB
New image name will start with 50
Generating: 100%|█████████████████████████████████████████████████████████████| 49/49 [00:00<00:00, 50.65img/s]
49 tiles sample of ./data/raw/RGB.png are added at ./data/processed/RGB
Input Image File Shape (H, W, D):(1000, 1000)
crop_size=256, stride=128
Padding Image File Shape (H, W, D):(1024, 1024)
There are 49 files in the ./data/processed/GT
New image name will start with 50
Generating: 100%|████████████████████████████████████████████████████████████| 49/49 [00:00<00:00, 139.72img/s]
49 tiles sample of ./data/raw/GT.png are added at ./data/processed/GT
```
You can also work with Remote Sensing (GeoTIFF) Satellite images such as Multispectral Images which have more bands or channels. All the codes will be the same, but with a small difference. Replace the `io` with the `geo` module.
This feature also needs you to install the `gdal` package with the following command in your python environment.
This package is not in the required packages due to many users may not use this function.
```bash
conda install -c conda-forge gdal
```
Sample Code:
```Python
from splitraster import geo
input_image_path = "./data/raw/Input.tif"
gt_image_path = "./data/raw/GT.tif"
save_path = "../data/processed/Input"
crop_size = 256
repetition_rate = 0.5
overwrite = False
n = geo.split_image(input_image_path, save_path, crop_size,
repetition_rate=repetition_rate, overwrite=overwrite)
print(f"{n} tiles sample of {input_image_path} are added at {save_path}")
```
## Random Sampling Code
The basic implementation is still the same as the above. Just replace the 'split_image' method to 'rand_crop_image'.
```python
from splitraster import io
input_image_path = "./data/raw/RGB.png"
gt_image_path = "./data/raw/GT.png"
input_save_path = "./data/processed/Rand/RGB"
gt_save_path = "./data/processed/Rand/GT"
n = io.random_crop_image(input_image_path, input_save_path, gt_image_path, gt_save_path, crop_size=256, crop_number=20, img_ext='.png', label_ext='.png', overwrite=True)
print(f"{n} sample paris of {input_image_path, gt_image_path} are added at {input_save_path, gt_save_path}.")
```
```python
from splitraster import geo
input_tif_image_path = "./data/raw/TIF/RGB5k.tif"
gt_tif_image_path = "./data/raw/TIF/GT5k.tif"
input_save_image_path = "./data/processed/Rand/RGB_TIF"
gt_save_image_path = "./data/processed/Rand/GT_TIF"
n = geo.random_crop_image(input_tif_image_path, input_save_image_path, gt_tif_image_path, gt_save_image_path, crop_size=500, crop_number=20, overwrite=True)
print(f"{n} sample paris of {input_tif_image_path, gt_tif_image_path} are added at {input_save_image_path, gt_save_image_path}.")
```
Future Update:
- [x] Add Random Sampling feature.
- [ ] Create a GUI with Qt and generate an executable file
- [ ] Add Sample Balancing feature.
Raw data
{
"_id": null,
"home_page": "https://github.com/cuicaihao/split_raster",
"name": "splitraster",
"maintainer": null,
"docs_url": null,
"requires_python": "<3.13,>=3.7",
"maintainer_email": null,
"keywords": "split raster tiling",
"author": "Chris Cui",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/f5/aa/16eedade6c114f057da32d95157302a7a4fb7bcb6b8656f93ed183191ba7/splitraster-0.3.5.tar.gz",
"platform": "any",
"description": "# Split Raster\n\nProvide good support for deep learning and computer vision tasks by creating a tiled output from an input raster dataset.\n\n## Use the packages\n\n```bash\npip install splitraster\n```\n\n## Try Sample code\n\nThe sample image can be found in the GitHub repo.\n\n```python\n\nfrom splitraster import io\n\ninput_image_path = \"./data/raw/RGB.png\"\ngt_image_path = \"./data/raw/GT.png\"\n\nsave_path = \"../data/processed/RGB\"\ncrop_size = 256\nrepetition_rate = 0.5\noverwrite = False\n\nn = io.split_image(input_image_path, save_path, crop_size,\n repetition_rate=repetition_rate, overwrite=overwrite)\nprint(f\"{n} tiles sample of {input_image_path} are added at {save_path}\")\n\nsave_path_gt = \"./data/processed/GT\"\nn = io.split_image(gt_image_path, save_path_gt, crop_size,\n repetition_rate=repetition_rate, overwrite=overwrite)\nprint(f\"{n} tiles sample of {gt_image_path} are added at {save_path_gt}\")\n\n\n```\n\nPossible results:\n\n```bash\nSuccessfully installed splitraster-0.1.0\n\u276f python test.py\nInput Image File Shape (H, W, D):(1000, 1000, 3)\ncrop_size=256, stride=128\nPadding Image File Shape (H, W, D):(1024, 1024, 3)\nThere are 49 files in the ./data/processed/RGB\nNew image name will start with 50\nGenerating: 100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 49/49 [00:00<00:00, 50.65img/s]\n49 tiles sample of ./data/raw/RGB.png are added at ./data/processed/RGB\nInput Image File Shape (H, W, D):(1000, 1000)\ncrop_size=256, stride=128\nPadding Image File Shape (H, W, D):(1024, 1024)\nThere are 49 files in the ./data/processed/GT\nNew image name will start with 50\nGenerating: 100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 49/49 [00:00<00:00, 139.72img/s]\n49 tiles sample of ./data/raw/GT.png are added at ./data/processed/GT\n```\n\nYou can also work with Remote Sensing (GeoTIFF) Satellite images such as Multispectral Images which have more bands or channels. All the codes will be the same, but with a small difference. Replace the `io` with the `geo` module.\n\nThis feature also needs you to install the `gdal` package with the following command in your python environment.\nThis package is not in the required packages due to many users may not use this function.\n\n```bash\nconda install -c conda-forge gdal\n```\n\nSample Code:\n\n```Python\nfrom splitraster import geo\ninput_image_path = \"./data/raw/Input.tif\"\ngt_image_path = \"./data/raw/GT.tif\"\n\nsave_path = \"../data/processed/Input\"\ncrop_size = 256\nrepetition_rate = 0.5\noverwrite = False\n\nn = geo.split_image(input_image_path, save_path, crop_size,\n repetition_rate=repetition_rate, overwrite=overwrite)\nprint(f\"{n} tiles sample of {input_image_path} are added at {save_path}\")\n```\n\n## Random Sampling Code\n\nThe basic implementation is still the same as the above. Just replace the 'split_image' method to 'rand_crop_image'.\n\n```python\nfrom splitraster import io\ninput_image_path = \"./data/raw/RGB.png\"\ngt_image_path = \"./data/raw/GT.png\"\n\ninput_save_path = \"./data/processed/Rand/RGB\"\ngt_save_path = \"./data/processed/Rand/GT\"\n\nn = io.random_crop_image(input_image_path, input_save_path, gt_image_path, gt_save_path, crop_size=256, crop_number=20, img_ext='.png', label_ext='.png', overwrite=True)\n\nprint(f\"{n} sample paris of {input_image_path, gt_image_path} are added at {input_save_path, gt_save_path}.\")\n\n```\n\n```python\nfrom splitraster import geo\ninput_tif_image_path = \"./data/raw/TIF/RGB5k.tif\"\ngt_tif_image_path = \"./data/raw/TIF/GT5k.tif\"\n\ninput_save_image_path = \"./data/processed/Rand/RGB_TIF\"\ngt_save_image_path = \"./data/processed/Rand/GT_TIF\"\n\nn = geo.random_crop_image(input_tif_image_path, input_save_image_path, gt_tif_image_path, gt_save_image_path, crop_size=500, crop_number=20, overwrite=True)\n\nprint(f\"{n} sample paris of {input_tif_image_path, gt_tif_image_path} are added at {input_save_image_path, gt_save_image_path}.\")\n\n```\n\nFuture Update:\n\n- [x] Add Random Sampling feature.\n- [ ] Create a GUI with Qt and generate an executable file\n- [ ] Add Sample Balancing feature.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Provide good support for deep learning and computer vision tasks by creating a tiled output from an input raster dataset.",
"version": "0.3.5",
"project_urls": {
"Homepage": "https://github.com/cuicaihao/split_raster"
},
"split_keywords": [
"split",
"raster",
"tiling"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a1fdf4fdf6099a9bebb59c08f1a6d319f0ed672cdba3e4b846a45fde94bba614",
"md5": "6ed16f13bf994e65d5c02c4dcad06684",
"sha256": "4479921887ea06629b6edebee66972f8daec7ef83e19fef49eef612e60acbb3f"
},
"downloads": -1,
"filename": "splitraster-0.3.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6ed16f13bf994e65d5c02c4dcad06684",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<3.13,>=3.7",
"size": 8286,
"upload_time": "2024-03-23T03:54:22",
"upload_time_iso_8601": "2024-03-23T03:54:22.803518Z",
"url": "https://files.pythonhosted.org/packages/a1/fd/f4fdf6099a9bebb59c08f1a6d319f0ed672cdba3e4b846a45fde94bba614/splitraster-0.3.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f5aa16eedade6c114f057da32d95157302a7a4fb7bcb6b8656f93ed183191ba7",
"md5": "bded19c2ff7e76809dfe2862c3ac9133",
"sha256": "57453306ae537d0595a9e657b909364112a1262633edbdc07721005f0d0c4d8e"
},
"downloads": -1,
"filename": "splitraster-0.3.5.tar.gz",
"has_sig": false,
"md5_digest": "bded19c2ff7e76809dfe2862c3ac9133",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<3.13,>=3.7",
"size": 10061,
"upload_time": "2024-03-23T03:54:24",
"upload_time_iso_8601": "2024-03-23T03:54:24.366234Z",
"url": "https://files.pythonhosted.org/packages/f5/aa/16eedade6c114f057da32d95157302a7a4fb7bcb6b8656f93ed183191ba7/splitraster-0.3.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-23 03:54:24",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "cuicaihao",
"github_project": "split_raster",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "numpy",
"specs": [
[
">=",
"1.19.0"
]
]
},
{
"name": "tqdm",
"specs": [
[
">=",
"4.40.0"
]
]
},
{
"name": "scikit-image",
"specs": [
[
">=",
"0.18.0"
]
]
}
],
"tox": true,
"lcname": "splitraster"
}