Split Raster Images for Remote Sensing (GeoTIFF) and GIS

If you are working with Remote Sensing images, you can use this package to split the images into small tiles.

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. We provide an optional dependency extra for this:

uv pip install "splitraster[geo]"

or via pip:

pip install "splitraster[geo]"

Or if you are using conda:

conda install -c conda-forge gdal

Try Sample code

Sample Code:

from splitraster import geo
input_image_path = "./tests/data/raw/TIF/RGB5k.tif"
gt_image_path = "./tests/data/raw/TIF/GT5k.tif"

save_path = "./tests/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

from splitraster import geo
input_tif_image_path = "./tests/data/raw/TIF/RGB5k.tif"
gt_tif_image_path = "./tests/data/raw/TIF/GT5k.tif"

input_save_image_path = "./tests/data/processed/Rand/RGB_TIF"
gt_save_image_path = "./tests/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}.")