Example #1
0
def align_peem_images(files, croi, fromtop=True):
    '''
    Align a set of images using current ROI
    '''
    print "Aligning images"
    shift = []
    if fromtop:
        anchor = files[0]
        lfiles = files[1:]
    else:
        anchor = files[-1]
        lfiles = files[:-1]

    da = peem_load_dataset(anchor)  #@UndefinedVariable
    for f in lfiles:
        print "Processing %s" % basename(f)
        db = peem_load_dataset(f)  #@UndefinedVariable
        s = img.findshift(da, db, croi)
        print "For %s, shift is (%g, %g)" % (basename(f), s[0], s[1])
        shift.append(s)

    if fromtop:
        shift.insert(0, jarray.zeros(2, 'd'))
    else:
        shift.append(jarray.zeros(2, 'd'))
    return shift, da
 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)
Example #3
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)
Example #4
0
 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)