rasterio/docs/recipes/filter.py
James McBride 938e8c624f Added recipe for generating a KMZ from a raster.
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.
2016-04-07 13:22:18 -07:00

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)