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