View difference between Paste ID: 4QjHUf37 and bG54iWXm
SHOW: | | - or go back to the newest paste.
1
import numpy
2
import scipy.ndimage.interpolation
3
4
exposures = [0, 1, 10, 20, 25]
5
num_samples = 10
6
7
values2d = numpy.arange((20), dtype = numpy.float32).reshape(5, 2, 2)
8
input_values = numpy.array([[10, 11], [12, 13]])
9
10
vmin2d, vmax2d = values2d.min(axis = 0), values2d.max(axis = 0)
11
uniform_values2d = numpy.zeros((num_samples, 2, 2))
12
uniform_exposures2d = numpy.zeros((num_samples, 2, 2))
13
for i in xrange(2):
14
    for j in xrange(2):
15
        uniform_values2d[:, i, j] = numpy.linspace(vmin2d[i, j],
16
                vmax2d[i, j], num_samples)
17
        uniform_exposures2d[:, i, j] = numpy.interp(uniform_values2d[:, i, j],
18
                values2d[:, i, j], exposures)
19
indices2d = (num_samples - 1) * (input_values - vmin2d) / (vmax2d - vmin2d)
20
21
map_input = numpy.zeros((3, 2, 2))
22
map_input[:1] = indices2d
23
map_input[1:] = numpy.indices((2, 2))
24
exposure_estimate2d = scipy.ndimage.interpolation.map_coordinates(
25
        uniform_exposures2d, map_input, order = 1, cval = -1)
26
27-
print uniform_values2d
27+
print "Initial values:\n",values2d
28-
print indices2d
28+
print "\nUniformly-sampled:\n",uniform_values2d
29-
print exposure_estimate2d
29+
print "\nMapped to exposure-time indices:\n",indices2d
30
print "\nEstimated exposure times:\n",exposure_estimate2d