Esempio n. 1
0
def shape_multiply(arr, scale, oddOnly=False, adjustFunction=None):
    '''Works like tile except that it keeps all like elements clumped
       Essentially a non-interpolating, multi-dimensional image up-scaler
       Similar to scipy.ndimage.zoom but without interpolation'''
    arr = np.asanyarray(arr)
    scale = coerce_to_target_length(scale, arr.ndim)
    if oddOnly:
        assert all([i%2 == 1 for i in scale]), \
            'All elements of scale must be odd integers greater than 0!'
    t = np.tile(arr, scale)
    t.shape = zipflat(scale, arr.shape)
    t = _transpose_interleaved(t)
    if adjustFunction != None:
        t = adjustFunction(t, arr, scale)
    new_shape = [sh * sc for sh, sc in zip(arr.shape, scale)]
    return t.reshape(new_shape)
Esempio n. 2
0
def _transpose_interleaved(arr):
    '''Helper function for shape_multiply and shape_divide
       Transposes an array so that all odd axes are first, i.e.:
       [1, 3, 5, 7, ..., 0, 2, 4, ...]'''
    return arr.transpose(*zipflat(range(1, arr.ndim, 2),
                                  range(0, arr.ndim, 2)))