def tryImageShiftGaussian(self, dx=2, dy=3, cx=23, cy=13): da = np.zeros([40,40]) da[cy,cx] = 50 da += rnd.poisson(2, da.shape) db = np.zeros([40,40]) db[cy+dy,cx+dx] = 65 db += rnd.poisson(2, db.shape) sx = max(dx,10) sy = max(dy,10) r = roi.rect(cx-2*sx,cy-2*sy,4*sx,4*sy,0) shift = img.findshift(da, db, r) print shift self.assertAlmostEquals(-dy, shift[0], places=0) self.assertAlmostEquals(-dx, shift[1], places=0)
def tryImageShift(self, dx=2, dy=3, cx=23, cy=13): da = np.zeros([40,40]) da[cy,cx] = 50 da += rnd.poisson(2, da.shape) db = np.zeros([40,40]) db[cy+dy,cx+dx] = 65 db += rnd.poisson(2, db.shape) sx = max(dx,5) sy = max(dy,5) r = roi.rectangle(point=[cx-2*sx,cy-2*sy],lengths=[4*sx,4*sy],angle=0) shift = img.findshift(da, db, r) print shift self.assertAlmostEquals(-dy, shift[0], places=0) self.assertAlmostEquals(-dx, shift[1], places=0)
def testCorrelate2D(self): print 'test correlate2' da = np.zeros([8,8], np.float) da[3,3] = 20 db = da.copy() ada = sig.correlate(da,db) print ada da += rnd.poisson(2, size=da.shape) db = np.zeros([8,8], np.float) db[5,6] = 20 db += rnd.poisson(2, size=db.shape) ada = sig.correlate(da,db) print ada
def tryImageShiftGaussian(self, dx=2, dy=3, cx=23, cy=13): da = np.zeros([40, 40]) da[cy, cx] = 50 da += rnd.poisson(2, da.shape) db = np.zeros([40, 40]) db[cy + dy, cx + dx] = 65 db += rnd.poisson(2, db.shape) sx = max(dx, 10) sy = max(dy, 10) r = roi.rectangle(point=[cx - 2 * sx, cy - 2 * sy], lengths=[4 * sx, 4 * sy], angle=0) shift = img.findshift(da, db, r) print shift self.assertAlmostEquals(-dy, shift[0], places=0) self.assertAlmostEquals(-dx, shift[1], places=0)
def testCorrelate2D(self): import os if os.name != 'java': return print 'test correlate2' da = np.zeros([8, 8], np.float) da[3, 3] = 20 db = da.copy() ada = np.correlate(da, db) print ada da += rnd.poisson(2, size=da.shape) db = np.zeros([8, 8], np.float) db[5, 6] = 20 db += rnd.poisson(2, size=db.shape) ada = np.correlate(da, db) print ada
def testCorrelate2D(self): import os if os.name != 'java': return print 'test correlate2' da = np.zeros([8,8], np.float) da[3,3] = 20 db = da.copy() ada = np.correlate(da,db) print ada da += rnd.poisson(2, size=da.shape) db = np.zeros([8,8], np.float) db[5,6] = 20 db += rnd.poisson(2, size=db.shape) ada = np.correlate(da,db) print ada
def testRandom(self): import os if os.name == 'java': import jarray ja = jarray.array([1, 2], 'i') else: ja = np.array([1, 2]) print(np.asIterable(ja)) print(rnd.rand()) print(rnd.rand(1)) print(rnd.rand(2, 4)) print(rnd.randn()) print(rnd.randn(1)) print(rnd.randn(2, 4)) for i in range(10): print(i, rnd.randint(1)) print(rnd.randint(2)) print(rnd.randint(5, size=[2, 4])) print(rnd.random_integers(1)) print(rnd.random_integers(5, size=[2, 4])) print(rnd.exponential(1.1)) print(rnd.exponential(1.1, [2, 4])) print(rnd.poisson(1.1)) print(rnd.poisson(1.1, [2, 4])) a = np.ones([2, 3]) print(rnd.poisson(1.2, a.shape)) rnd.seed() print(rnd.rand(2, 3)) rnd.seed() print(rnd.rand(2, 3)) rnd.seed(12343) print(rnd.rand(2, 3)) rnd.seed(12343) print(rnd.rand(2, 3)) a = rnd.rand(200, 300) print(a.mean(), a.std())
def testRandom(self): import os if os.name == 'java': import jarray ja = jarray.array([1,2], 'i') else: ja = np.array([1,2]) print(np.asIterable(ja)) print(rnd.rand()) print(rnd.rand(1)) print(rnd.rand(2,4)) print(rnd.randn()) print(rnd.randn(1)) print(rnd.randn(2,4)) for i in range(10): print(i, rnd.randint(1)) print(rnd.randint(2)) print(rnd.randint(5, size=[2,4])) print(rnd.random_integers(1)) print(rnd.random_integers(5, size=[2,4])) print(rnd.exponential(1.1)) print(rnd.exponential(1.1, [2,4])) print(rnd.poisson(1.1)) print(rnd.poisson(1.1, [2,4])) a = np.ones([2,3]) print(rnd.poisson(1.2, a.shape)) rnd.seed() print(rnd.rand(2,3)) rnd.seed() print(rnd.rand(2,3)) rnd.seed(12343) print(rnd.rand(2,3)) rnd.seed(12343) print(rnd.rand(2,3)) a = rnd.rand(200,300) print(a.mean(), a.std())