Esempio n. 1
0
 def evaluate_grid_dstn(self, xlo, xhi, ylo, yhi, xstep=1., ystep=1.):
     from mix import c_gauss_2d_grid
     assert(self.D == 2)
     NX = int(round(xhi - xlo + 1))
     NY = int(round(yhi - ylo + 1))
     result = np.zeros((NY, NX))
     rtn = c_gauss_2d_grid(xlo, xstep, NX, ylo, ystep, NY,
                           self.amp, self.mean,self.var, result)
     if rtn == -1:
         raise RuntimeError('c_gauss_2d_grid failed')
     return result
Esempio n. 2
0
 def evaluate_grid_dstn(self, xlo, xhi, ylo, yhi, xstep=1., ystep=1.):
     from mix import c_gauss_2d_grid
     assert (self.D == 2)
     NX = int(round(xhi - xlo + 1))
     NY = int(round(yhi - ylo + 1))
     result = np.zeros((NY, NX))
     rtn = c_gauss_2d_grid(xlo, xstep, NX, ylo, ystep, NY, self.amp,
                           self.mean, self.var, result)
     if rtn == -1:
         raise RuntimeError('c_gauss_2d_grid failed')
     return result
Esempio n. 3
0
 def evaluate_grid_dstn(self, x0, x1, y0, y1, cx, cy):
     '''
     [x0,x1): (int) X values to evaluate
     [y0,y1): (int) Y values to evaluate
     (cx,cy): (float) pixel center of the MoG
     '''
     from mix import c_gauss_2d_grid
     assert(self.D == 2)
     result = np.zeros((y1-y0, x1-x0))
     rtn = c_gauss_2d_grid(x0, x1, y0, y1, cx, cy,
                           self.amp, self.mean,self.var, result)
     if rtn == -1:
         raise RuntimeError('c_gauss_2d_grid failed')
     return Patch(x0, y0, result)
Esempio n. 4
0
            amp = np.array([0.99, 0.01])
            mean = np.array([[0.3, 0.7],[-0.3, -0.7],])
            var = np.array([ [ [ 400., -100. ], [-100., 100.,] ],
                             [ [ 400., -100. ], [-100., 100.,] ], ])
            dx = 1.
            minval = 1e-9
        else:
            break

        print 'args (approx1):', x0, x1, y0, y1, dx, dy, minval, amp, mean, var
        rtn = c_gauss_2d_approx(x0, x1, y0, y1, dx, dy, minval, amp, mean, var, result)
        if rtn == -1:
            raise RuntimeError('c_gauss_2d_approx failed')

        r2 = np.zeros((H,W))
        rtn = c_gauss_2d_grid(x0 - dx, 1, W, y0 - dy, 1, H, amp, mean, var, r2)
        if rtn == -1:
            raise RuntimeError('c_gauss_2d_grid failed')

        print 'Max difference:', np.max(np.abs(r2 - result))

        plt.clf()
        plt.imshow(np.log10(np.maximum(minval * 1e-3, r2)),
                   interpolation='nearest', origin='lower')
        plt.colorbar()
        plt.title('Grid')
        ps.savefig()
        
        plt.clf()
        plt.imshow(np.log10(np.maximum(minval * 1e-3, result)),
                   interpolation='nearest', origin='lower')
Esempio n. 5
0
        elif j == 13:
            var = np.array([ [ [ 4., 4. ], [4., 9.,] ], ])
            minradius = 12
        elif j == 14:
            var = np.array([ [ [ 0.5, -0.6 ], [-0.6, 1.,] ], ])
            minradius = 4
        else:
            break

        print 'args (approx1):', x0, x1, y0, y1, dx, dy, minval, amp, mean, var
        rtn = c_gauss_2d_approx(x0, x1, y0, y1, dx, dy, minval, amp, mean, var, result)
        if rtn == -1:
            raise RuntimeError('c_gauss_2d_approx failed')

        r2 = np.zeros((H,W))
        rtn = c_gauss_2d_grid(x0 - dx, 1, W, y0 - dy, 1, H, amp, mean, var, r2)
        if rtn == -1:
            raise RuntimeError('c_gauss_2d_grid failed')

        print 'Max difference:', np.max(np.abs(r2 - result))

        plt.clf()
        plt.subplot(1,2,1)
        plt.imshow(np.log10(np.maximum(minval * 1e-3, r2)),
                   interpolation='nearest', origin='lower')
        plt.colorbar()
        plt.title('Grid')
        
        plt.subplot(1,2,2)
        plt.imshow(np.log10(np.maximum(minval * 1e-3, result)),
                   interpolation='nearest', origin='lower')