mirror of
https://github.com/rasterio/rasterio.git
synced 2025-12-08 17:36:12 +00:00
This relies a little less on rasterio than some other recipes, but I thought it would still be nice for someone looking to turn a raster into a KMZ to be directed to rasterio and find an easy code example to follow.
17 lines
419 B
Python
17 lines
419 B
Python
import rasterio
|
|
from scipy.signal import medfilt
|
|
|
|
path = "tests/data/RGB.byte.tif"
|
|
output = "/tmp/filtered.tif"
|
|
|
|
with rasterio.open(path) as src:
|
|
array = src.read()
|
|
profile = src.profile
|
|
|
|
# apply a 5x5 median filter to each band
|
|
filtered = medfilt(array, (1, 5, 5)).astype('uint8')
|
|
|
|
# Write to tif, using the same profile as the source
|
|
with rasterio.open(output, 'w', **profile) as dst:
|
|
dst.write(filtered)
|