Skip to main content

Provide good support for deep learning and computer vision tasks by creating a tiled output from an input raster dataset.

Project description

Split Raster

Provide good support for deep learning and computer vision tasks by creating a tiled output from an input raster dataset.

Find more details:

Use the packages

Requirements

  • Python >= 3.10
  • Core Dependencies: numpy, tqdm, scikit-image, torch.

Installation

pip install splitraster

Try Sample code

The sample image can be found in the GitHub repo.

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:

Successfully installed splitraster-0.4.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.

conda install -c conda-forge gdal

Sample Code:

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'.

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}.")
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}.")

END

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

splitraster-0.4.1.tar.gz (68.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

splitraster-0.4.1-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file splitraster-0.4.1.tar.gz.

File metadata

  • Download URL: splitraster-0.4.1.tar.gz
  • Upload date:
  • Size: 68.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for splitraster-0.4.1.tar.gz
Algorithm Hash digest
SHA256 f91e87ee587c6a07649e88c8b5489d767957e33573e1845800b6364b22a8b23e
MD5 ef367cd79382888eddad4885cee7caba
BLAKE2b-256 acbba08efd2ece47cec023f28c90aedd21cd906ea4f9ef7e0b14347cf66dab57

See more details on using hashes here.

Provenance

The following attestation bundles were made for splitraster-0.4.1.tar.gz:

Publisher: python-CD.yml on cuicaihao/split_raster

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file splitraster-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: splitraster-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for splitraster-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 92ea66633f29dbf1e1ac83f49ca179ab1318ff59806fdcd8655d13a1daf80004
MD5 200434770d0f448275e596123bccdb27
BLAKE2b-256 f372d1e5b2309743f8f500be413134487aa28024a63ea5788567fa436216bdb3

See more details on using hashes here.

Provenance

The following attestation bundles were made for splitraster-0.4.1-py3-none-any.whl:

Publisher: python-CD.yml on cuicaihao/split_raster

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page