6 num_sets = len(sys.argv) - 1
8 mins = np.empty((num_sets), dtype=np.float32)
9 means = np.empty((num_sets), dtype=np.float32)
10 maxs = np.empty((num_sets), dtype=np.float32)
13 for i
in range(0, num_sets):
14 ds = gdal.Open(inputs[i], gdal.GA_ReadOnly)
16 raster_count = ds.RasterCount
17 x_size = ds.RasterXSize
18 y_size = ds.RasterYSize
19 num_channels = raster_count - 1
21 values = np.empty((raster_count, y_size, x_size), dtype=np.float32)
22 for j
in range(0, num_channels):
23 values[j] = np.array(ds.GetRasterBand(j + 1).ReadAsArray()).astype(np.float32)
25 mins[i] = np.amin(values)
26 means[i] = np.mean(values)
27 maxs[i] = np.amax(values)
33 all_min = np.amin(mins)
34 print(
"Calculated minimum value over data sets: ", all_min)
35 all_mean = np.mean(means)
36 print(
"Calculated mean value over data sets: ", all_mean)
37 all_max = np.amax(maxs)
38 print(
"Calculated maximum value over data sets: ", all_max)
39 denominator = all_mean - all_min
42 for i
in range(0, num_sets):
43 ds = gdal.Open(inputs[i], gdal.GA_ReadOnly)
45 raster_count = ds.RasterCount
46 x_size = ds.RasterXSize
47 y_size = ds.RasterYSize
48 num_channels = raster_count - 1
50 values = np.empty((raster_count, y_size, x_size), dtype=np.float32)
51 for j
in range(0, num_channels):
52 values[j] = np.array(ds.GetRasterBand(j + 1).ReadAsArray()).astype(np.float32)
55 values = ((values - all_min) / denominator)
56 values = values * (all_max / 2.)
57 values = values.astype(np.int)
59 driver = gdal.GetDriverByName(
"GTiff")
60 filename, file_extension = os.path.splitext(inputs[i])
61 ds = driver.Create(filename +
"_normed" + file_extension, x_size, y_size, raster_count, gdal.GDT_UInt16)
62 for j
in range(0, num_channels):
63 ds.GetRasterBand(j + 1).WriteArray(values[j])