Example #1
0
 def exp2(self, jacobian=False, add_identity=False, alpha=None):
     """Exponentiate both forward and inverse transforms"""
     v = self.fdata()
     if alpha:
         v = v * alpha
     if jacobian:
         grid, jac = spatial.exp_forward(v,
                                         steps=self.steps,
                                         jacobian=True,
                                         displacement=True)
         igrid, ijac = spatial.exp_forward(v,
                                           steps=self.steps,
                                           jacobian=True,
                                           inverse=True,
                                           displacement=True)
         if add_identity:
             grid = self.add_identity(grid)
             igrid = self.add_identity(igrid)
         return grid, igrid, jac, ijac
     else:
         grid = spatial.exp_forward(v,
                                    steps=self.steps,
                                    jacobian=False,
                                    displacement=True)
         igrid = spatial.exp_forward(v,
                                     steps=self.steps,
                                     jacobian=False,
                                     inverse=True,
                                     displacement=True)
         if add_identity:
             grid = self.add_identity(grid)
             igrid = self.add_identity(igrid)
         return grid, igrid
Example #2
0
 def exp2(self, v=None, jacobian=False, add_identity=False,
         cache_result=False, recompute=True):
     """Exponentiate both forward and inverse transforms"""
     if v is None:
         v = self.dat.dat
     if jacobian:
         grid, jac = spatial.exp_forward(v, steps=self.steps,
                                         jacobian=True,
                                         displacement=True)
         igrid, ijac = spatial.exp_forward(v, steps=self.steps,
                                           jacobian=True, inverse=True,
                                           displacement=True)
         if cache_result:
             self._cache = grid
             self._icache = igrid
         if add_identity:
             grid = self.add_identity(grid)
             igrid = self.add_identity(igrid)
         return grid, igrid, jac, ijac
     else:
         if recompute or self._cache is None:
             grid = spatial.exp_forward(v, steps=self.steps,
                                        jacobian=False,
                                        displacement=True)
         else:
             grid = self._cache
         if recompute or self._icache is None:
             igrid = spatial.exp_forward(v, steps=self.steps,
                                         jacobian=False, inverse=True,
                                         displacement=True)
         else:
             igrid = self._icache
         if cache_result:
             self._cache = grid
             self._icache = igrid
         grid = self.add_identity(grid)
         igrid = self.add_identity(igrid)
         return grid, igrid
Example #3
0
 def exp(self, jacobian=False, add_identity=False, alpha=None):
     """Exponentiate forward transform"""
     v = self.fdata()
     if alpha:
         v = v * alpha
     grid = spatial.exp_forward(v,
                                steps=self.steps,
                                jacobian=jacobian,
                                displacement=True)
     if jacobian:
         grid, jac = grid
     if add_identity:
         grid = self.add_identity(grid)
     return (grid, jac) if jacobian else grid
Example #4
0
 def iexp(self, jacobian=False, add_identity=False, alpha=None):
     """Exponentiate inverse transform"""
     v = self.fdata()
     if alpha:
         v = v * alpha
     igrid = spatial.exp_forward(v,
                                 steps=self.steps,
                                 jacobian=jacobian,
                                 inverse=True,
                                 displacement=True)
     if jacobian:
         igrid, ijac = igrid
     if add_identity:
         igrid = self.add_identity(igrid)
     return (igrid, ijac) if jacobian else igrid
Example #5
0
 def iexp(self, v=None, jacobian=False, add_identity=False,
         cache_result=False, recompute=True):
     """Exponentiate inverse transform"""
     if v is None:
         v = self.dat.dat
     if jacobian:
         recompute = True
     if recompute or self._icache is None:
         igrid = spatial.exp_forward(v, steps=self.steps,
                                     jacobian=jacobian, inverse=True,
                                     displacement=True)
     else:
         igrid = self._icache
     if cache_result:
         self._icache = igrid[0] if jacobian else igrid
     if add_identity:
         if jacobian:
             igrid = (self.add_identity(igrid[0]), igrid[1])
         else:
             igrid = self.add_identity(igrid)
     return igrid