Commit dc50c753 by inhuszar

### Masking and Neumann boundary on the dissimilarity term

parent 3486ff21
 ... ... @@ -35,6 +35,7 @@ from numbers import Integral, Real # TIRL IMPORTS from tirl import settings as ts from tirl.optimisation.optimiser import Optimiser from tirl.regularisers.diffusion import DiffusionRegulariser from tirl.transformations.nonlinear.displacement import TxDisplacementField ... ... @@ -252,17 +253,35 @@ class GNOptimiserDiffusion(Optimiser): invchain = chain.inverse() target = self.costs[0].target edgemask = np.zeros(target.vshape) for dim in range(target.vdim): slicer = (Ellipsis, [0, -1], *(slice(None),) * (target.vdim - 1 - dim)) edgemask[slicer] = 1 else: edge = np.flatnonzero(edgemask) del edgemask while True: niter += 1 # Obtain cost differential S = self.costs[0].source - target S.order = VOXEL_MAJOR S = S.data.reshape(numel, -1, 1) # Apply mask on the dissimilarity vector (S) combined_mask = self.costs[0].combine_masks( target_mask=target.mask, source_mask=self.costs[0].source.mask ) S = S * combined_mask.ravel()[:, np.newaxis, np.newaxis] # If the transformation parameters are vectors in physical space, # then so should be the cost differentials. I.e. if the tx is # absolute, map the derivatives. dS = self.costs[0].dx().reshape(-1, ndim) # rel dS = dS.reshape((numel, -1, ndim)) dS[edge, ...] = 0 # Neumann # Note: dx() already applied the mask! # dS = dS * combined_mask.ravel()[:, np.newaxis, np.newaxis] SdS = np.mean(S * dS, axis=1) SdS = SdS.T.ravel() dSTdS = dS[..., np.newaxis] @ dS[..., np.newaxis, :] ... ...
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!