Пример #1
0
def resample2d_numpy(image,size,timer=None):
    start_timer(timer,"resample2d bilinear numpy")

    (N,M) = image.shape[-2:];
    (n,m) = size;

    xs = np.linspace(1,M-1,m)[None,:];
    ys = np.linspace(1,N-1,n)[:,None];

    yminus,iminus= np.modf(ys-0.5);
    yplus, iplus = np.modf(ys+0.5);
    xminus,jminus= np.modf(xs-0.5);
    xplus, jplus = np.modf(xs+0.5);     

    I = to_np(image.reshape((-1,M*N)))
    
    LD = (iminus*M + jminus).astype(np.uint64); # x-,y-
    LU = (iplus *M + jminus).astype(np.uint64); # x-,y+
    RD = (iminus*M + jplus).astype(np.uint64);  # x+,y-
    RU = (iplus *M + jplus).astype(np.uint64);  # x+,y+

    I_bilin = (1-xminus)*(1-yminus)*I[:,LD] \
             +(1-xminus)*yplus     *I[:,LU] \
             +xplus     *yplus     *I[:,RD] \
             +xplus*(1-yminus)     *I[:,RU];    

    new_shape = image.shape[:-2]+(n,m)
    end_timer(timer)
    return I_bilin.reshape(new_shape)
Пример #2
0
def downscale(Ft,nx,timer=None):
    start_timer(timer,"downscale")
    
    ct=dct(Ft,norm='ortho')[:nx];
    result = idct(ct,norm='ortho');

    end_timer(timer)
    return result
Пример #3
0
def upscale(ft,nX,timer=None):
    start_timer(timer,"upscale")

    ct=dct(ft,norm='ortho');
    result = idct(ct,n=nX,norm='ortho');

    end_timer(timer)
    return result
Пример #4
0
def resample2d_sequence(sequence, size, timer=None):
    """Resample a squence of 2d-arrays to size"""
    start_timer(timer,"resample2d_sequence")

    scaled_sequence = resample2d(sequence,size,timer)

    end_timer(timer)
    return scaled_sequence
Пример #5
0
def input_map(image, operations, timer=None):
    start_timer(timer,"input_map")
    features = []
    for F in operations:
        start_timer(timer,F['type'])
        features.append(apply_input_map(image,F).reshape(-1))
        end_timer(timer)
    end_timer(timer)
    return features
Пример #6
0
    def forward(self, image, state):
        start_timer(self.timer,"forward")
        
        self.check_dtypes(image, state)

        input_stack = self.input_map(to_np(image))       # np
        x_input     = to_bh(bh.concatenate(input_stack)) # np -> bh
        x_state     = self.state_map(to_bh(state))       # bh
        start_timer(self.timer,"tanh")
        new_state   = bh.tanh(x_input+x_state)      # bh
        end_timer(self.timer) # /tanh
        end_timer(self.timer) # /forward
        return new_state
Пример #7
0
 def state_map(self, state):
     start_timer(self.timer,"state_map")
     new_state = self.weight_hh.sparse_dense_mv(state)
     end_timer(self.timer)
     return new_state
Пример #8
0
def resample2d_skt(image, size, timer=None):
    start_timer(timer,"resample2d skimage")
    res = skt.resize(image, size, mode="reflect", anti_aliasing=True).astype(image.dtype)
    end_timer(timer)
    return res
Пример #9
0
def lstsq(A,B,timer=None):
    start_timer(timer,"lstsq")
    X,b,c,s = sp.linalg.lstsq(A,B)
    end_timer(timer)
    return X,b,c,s
Пример #10
0
def eigh(A, timer=None):
    start_timer(timer,"eigh")
    lambdas, U = sp.linalg.eigh(A)
    end_timer(timer)
    return lambdas, U
Пример #11
0
def svd(A,timer=None):
    start_timer(timer,"svd")
    U, s, Vh = sp.linalg.svd(A)
    end_timer(timer)
    return U, s, Vh