4 from scipy.signal
import savgol_filter
9 ds = gdal.Open(inname, gdal.GA_ReadOnly)
11 print(
"Could not open file ", inname)
13 raster_count = ds.RasterCount
14 x_size = ds.RasterXSize
15 y_size = ds.RasterYSize
18 max_channel = ds.RasterCount
19 if len(sys.argv) == 5:
20 min_channel = int(sys.argv[3])
21 max_channel = int(sys.argv[4])
23 num_channels = max_channel - min_channel
25 values = np.empty((raster_count, y_size, x_size), dtype=np.float32)
26 for i
in range(0, num_channels):
27 values[i] = np.array(ds.GetRasterBand(i + 1).ReadAsArray()).astype(np.float32)
34 values = values.reshape(values.shape[0], -1)
35 means = values.mean(axis=0)
36 mins = values.min(axis=0)
38 vmax = np.amax(values)
39 values = ((values - mins) / (means - mins))
45 values = values * vmax / 2.
47 values = values.reshape(shape)
51 values = savgol_filter(values, 11, 2, axis=0)
54 driver = gdal.GetDriverByName(
"GTiff")
55 ds = driver.Create(outname, x_size, y_size, raster_count, gdal.GDT_UInt16)
56 for i
in range(0, num_channels):
57 ds.GetRasterBand(i + 1).WriteArray(values[i])