Beispiel #1
0
def test_render_hat():
    N = 100
    H = 48
    W = 64
    x = 30
    y = 20
    size = 3.0
    BORDER = 0.2
    slows = []
    t1 = time.time()
    for i in range(N):
        img = util.render_hat_ma(H, W, x, y, size, BORDER)
        slows.append(img)
    t2 = time.time()
    print "slows took", (t2-t1)/N*1e6, "us per render"

    fasts = []
    t1 = time.time()
    for i in range(N):
        img = util.render_hat_ma_fast(H, W, x, y, size, BORDER)
        fasts.append(img)
    t2 = time.time()
    print "fasts took", (t2-t1)/N*1e6, "us per render"

    for s, f in zip(slows, fasts):
        assert_allclose(s, f)
Beispiel #2
0
def test_render_hat():
    N = 100
    H = 48
    W = 64
    x = 30
    y = 20
    size = 3.0
    BORDER = 0.2
    slows = []
    t1 = time.time()
    for i in range(N):
        img = util.render_hat_ma(H, W, x, y, size, BORDER)
        slows.append(img)
    t2 = time.time()
    print "slows took", (t2 - t1) / N * 1e6, "us per render"

    fasts = []
    t1 = time.time()
    for i in range(N):
        img = util.render_hat_ma_fast(H, W, x, y, size, BORDER)
        fasts.append(img)
    t2 = time.time()
    print "fasts took", (t2 - t1) / N * 1e6, "us per render"

    for s, f in zip(slows, fasts):
        assert_allclose(s, f)
Beispiel #3
0
    def render(self, phi, theta):
        """
        Returns a template where max intensity is 
        1.0, min is 0.0, float32. The center of the 
        returned image is the center of the diode array

        """
        
        s = max(self.front_size, self.back_size)
        T_D = self.length + 4*s
        template = np.ma.zeros((2, T_D, 
                             T_D), dtype=np.float32)
        D, W, H = template.shape
        
        front_pos, back_pos = util.compute_pos(self.length, 
                                               W/2., H/2., phi, theta)
        
        def pos_to_int(p):
            return np.rint(p).astype(int)

        front_pos = pos_to_int(front_pos)
        back_pos = pos_to_int(back_pos)
        for i, size, pos in [(0, self.front_size, front_pos), 
                             (1, self.back_size, back_pos)]:
            template[i] = util.render_hat_ma_fast(H, W, pos[1], pos[0], 
                                                  size, self.border, 
                                                  self.nocare_border)

        t =  np.sum(template, axis=0) 
        t[t > 0.1] = 1.0

        return t