Commits

Sam Preston  committed 5df4295

working on test of gamma=0 in elastic registration respecting nullspace of L

  • Participants
  • Parent commits dd1a831

Comments (0)

Files changed (1)

File Examples/ElastReg.py

             Mul_I(scratchV, diff)
 
             diffOp.applyInverseOperator(gU, scratchV)
+            MulC_I(gU, -1.0)
 
             # u =  u*(1-VFC*ustep) + (-2.0*ustep)*gU
-            MulC_Add_MulC_I(u, (1-VFC*ustep[scale]),
-                                   gU, 2.0*ustep[scale])
+            # MulC_Add_MulC_I(u, (1-VFC*ustep[scale]),
+            #                        gU, 2.0*ustep[scale])
+
+            # u =  u - ustep*(VFC*u + 2.0*gU)
+            MulC_I(gU, 2.0)
+
+            # subtract average if gamma is zero (result of nullspace
+            # of L for K(L(u)))
+            if fluidParams[2] == 0:
+                av = SumComp(u)
+                av /= scratchI.nVox()
+                SubC(scratchV, u, av)
+            # continue computing gradient
+            MulC_I(scratchV, VFC)
+            Add_I(gU, scratchV)
+            MulC_I(gU, ustep[scale])
+            # apply gradient
+            Sub_I(u, gU)
 
             # compute energy
             energy[0].append(Sum2(diff))
     I1 = common.LoadPNGImage(imagedir + 'lena_orig.png', mType)
 
     (Idef, u, energy) = \
-           ElastReg(I0, \
-                    I1, \
-                    scales = [2,1], \
-                    nIters = [1000,1000], \
-                    ustep = [0.1, 0.1], \
-                    fluidParams = [0.5, 0.5, 0.001], \
-                    VFC = 0.2, \
+           ElastReg(I0, 
+                    I1, 
+                    scales = [2,1], 
+                    nIters = [1000,1000], 
+                    ustep = [0.1, 0.1], 
+                    # fluidParams = [0.5, 0.5, 0.001], 
+                    fluidParams = [0.5, 0.5, 0.0], 
+                    VFC = 0.2, 
                     plotEvery = 500)