def __call__(self, L, P, psf_only=False): # compute utils.convolve2d(L, P, output=self._J) utils.dx(self._J, output=self._dxJ) utils.dy(self._J, output=self._dyJ) utils.dx(L, output=self._dxL) utils.dy(L, output=self._dyL) utils.dx_b(self._dxJ, output=self._dxxJ) utils.dy_b(self._dyJ, output=self._dyyJ) utils.dx_b(self._dyJ, output=self._dxyJ) # enegery for data compatibility R = self._J - self.I0 dxR = self._dxJ - self._dxI0 dyR = self._dyJ - self._dyI0 dxxR = self._dxxJ - self._dxxI0 dyyR = self._dyyJ - self._dyyI0 dxyR = self._dxyJ - self._dxyI0 E = self.w0 * utils.norm2(R) E += self.w1 * utils.norm2(dxR) E += self.w1 * utils.norm2(dyR) #~ E += self.w2 * utils.norm2(dxxR) #~ E += self.w2 * utils.norm2(dyyR) #~ E += self.w2 * utils.norm2(dxyR) if not psf_only: # energy for global prior E += self.lambda1 * utils.global_prior(self._dxL, self.a, self.b) E += self.lambda1 * utils.global_prior(self._dyL, self.a, self.b) # energy for local prior E += self.lambda2 * utils.local_prior(self._dxL, self._dxI0, self.M) E += self.lambda2 * utils.local_prior(self._dyL, self._dyI0, self.M) return E/self.I0.size
def grad_L(self, L, P): # compute utils.convolve2d(L, P, output=self._J) utils.dx(self._J, self._dxJ) utils.dy(self._J, self._dyJ) utils.dx(L, self._dxL) utils.dy(L, self._dyL) utils.dx_b(self._dxJ, self._dxxJ) utils.dy_b(self._dyJ, self._dyyJ) utils.dx_b(self._dyJ, self._dxyJ) R = self._J - self.I0 dxR = self._dxJ - self._dxI0 dyR = self._dyJ - self._dyI0 dxxR = self._dxxJ - self._dxxI0 dyyR = self._dyyJ - self._dyyI0 dxyR = self._dxyJ - self._dxyI0 # enegery for data compatibility dxP = utils.dx(P) dyP = utils.dy(P) dxxP = utils.dx_b(dxP) dyyP = utils.dy_b(dyP) dxyP = utils.dx_b(dyP) dL = np.zeros(L.shape) dL += self.w0 * utils.grad_L(P, R) dL += self.w1 * utils.grad_L(dxP, dxR) dL += self.w1 * utils.grad_L(dyP, dyR) #~ dL += self.w2 * utils.grad_L(dxxP, dxxR) #~ dL += self.w2 * utils.grad_L(dyyP, dyyR) #~ dL += self.w2 * utils.grad_L(dxyP, dxyR) dL += self.lambda1 * utils.grad_global_prior_x(self._dxL, self.a, self.b) dL += self.lambda1 * utils.grad_global_prior_y(self._dyL, self.a, self.b) dL += self.lambda2 * utils.grad_local_prior_x(self._dxL, self._dxI0, self.M) dL += self.lambda2 * utils.grad_local_prior_y(self._dyL, self._dyI0, self.M) return (dL - dL.mean()) / self.I0.size
def grad_L(self, L, P): # compute utils.convolve2d(L, P, output=self._J) utils.dx(self._J, self._dxJ) utils.dy(self._J,self._dyJ) utils.dx(L, self._dxL) utils.dy(L, self._dyL) utils.dx_b(self._dxJ, self._dxxJ) utils.dy_b(self._dyJ, self._dyyJ) utils.dx_b(self._dyJ, self._dxyJ) R = self._J - self.I0 dxR = self._dxJ - self._dxI0 dyR = self._dyJ - self._dyI0 dxxR = self._dxxJ - self._dxxI0 dyyR = self._dyyJ - self._dyyI0 dxyR = self._dxyJ - self._dxyI0 # enegery for data compatibility dxP = utils.dx(P) dyP = utils.dy(P) dxxP = utils.dx_b(dxP) dyyP = utils.dy_b(dyP) dxyP = utils.dx_b(dyP) dL = np.zeros(L.shape) dL += self.w0 * utils.grad_L(P, R) dL += self.w1 * utils.grad_L(dxP, dxR) dL += self.w1 * utils.grad_L(dyP, dyR) #~ dL += self.w2 * utils.grad_L(dxxP, dxxR) #~ dL += self.w2 * utils.grad_L(dyyP, dyyR) #~ dL += self.w2 * utils.grad_L(dxyP, dxyR) dL += self.lambda1 * utils.grad_global_prior_x(self._dxL, self.a, self.b) dL += self.lambda1 * utils.grad_global_prior_y(self._dyL, self.a, self.b) dL += self.lambda2 * utils.grad_local_prior_x(self._dxL, self._dxI0, self.M) dL += self.lambda2 * utils.grad_local_prior_y(self._dyL, self._dyI0, self.M) return (dL - dL.mean()) /self.I0.size
def __call__(self, L, P, psf_only=False): # compute utils.convolve2d(L, P, output=self._J) utils.dx(self._J, output=self._dxJ) utils.dy(self._J, output=self._dyJ) utils.dx(L, output=self._dxL) utils.dy(L, output=self._dyL) utils.dx_b(self._dxJ, output=self._dxxJ) utils.dy_b(self._dyJ, output=self._dyyJ) utils.dx_b(self._dyJ, output=self._dxyJ) # enegery for data compatibility R = self._J - self.I0 dxR = self._dxJ - self._dxI0 dyR = self._dyJ - self._dyI0 dxxR = self._dxxJ - self._dxxI0 dyyR = self._dyyJ - self._dyyI0 dxyR = self._dxyJ - self._dxyI0 E = self.w0 * utils.norm2(R) E += self.w1 * utils.norm2(dxR) E += self.w1 * utils.norm2(dyR) #~ E += self.w2 * utils.norm2(dxxR) #~ E += self.w2 * utils.norm2(dyyR) #~ E += self.w2 * utils.norm2(dxyR) if not psf_only: # energy for global prior E += self.lambda1 * utils.global_prior(self._dxL, self.a, self.b) E += self.lambda1 * utils.global_prior(self._dyL, self.a, self.b) # energy for local prior E += self.lambda2 * utils.local_prior(self._dxL, self._dxI0, self.M) E += self.lambda2 * utils.local_prior(self._dyL, self._dyI0, self.M) return E / self.I0.size
def __init__(self, I0, w0, lambda1=1e-3, lambda2=10., a=1.0, b=3.0, cutoff=1e-6, t=5): self.w0 = w0 self.w1 = self.w0 / 2 self.w2 = self.w1 / 4 self.t = t self.lambda1 = lambda1 self.lambda2 = lambda2 self.a = a self.b = b self.cutoff = cutoff self.I0 = I0 self.I0_sum = self.I0.sum(0).sum(0) self._dxI0 = utils.dx(self.I0) self._dyI0 = utils.dy(self.I0) self._dxxI0 = utils.dx_b(self._dxI0) self._dyyI0 = utils.dy_b(self._dyI0) self._dxyI0 = utils.dx_b(self._dyI0) self._dxL = np.zeros(self.I0.shape) self._dyL = np.zeros(self.I0.shape) self._dxxL = np.zeros(self.I0.shape) self._dyyL = np.zeros(self.I0.shape) self._dxyL = np.zeros(self.I0.shape) self._J = np.zeros(self.I0.shape) self._dxJ = np.zeros(self.I0.shape) self._dyJ = np.zeros(self.I0.shape) self._dxxJ = np.zeros(self.I0.shape) self._dyyJ = np.zeros(self.I0.shape) self._dxyJ = np.zeros(self.I0.shape) self._M = None self._simplex_normal = None
def __init__(self, I0, w0, lambda1=1e-3, lambda2=10., a=1.0, b=3.0, cutoff = 1e-6, t=5): self.w0 = w0 self.w1 = self.w0/2 self.w2 = self.w1/4 self.t = t self.lambda1 = lambda1 self.lambda2 = lambda2 self.a = a self.b = b self.cutoff = cutoff self.I0 = I0 self.I0_sum = self.I0.sum(0).sum(0) self._dxI0 = utils.dx(self.I0) self._dyI0 = utils.dy(self.I0) self._dxxI0 = utils.dx_b(self._dxI0) self._dyyI0 = utils.dy_b(self._dyI0) self._dxyI0 = utils.dx_b(self._dyI0) self._dxL = np.zeros(self.I0.shape) self._dyL = np.zeros(self.I0.shape) self._dxxL = np.zeros(self.I0.shape) self._dyyL = np.zeros(self.I0.shape) self._dxyL = np.zeros(self.I0.shape) self._J = np.zeros(self.I0.shape) self._dxJ = np.zeros(self.I0.shape) self._dyJ = np.zeros(self.I0.shape) self._dxxJ = np.zeros(self.I0.shape) self._dyyJ = np.zeros(self.I0.shape) self._dxyJ = np.zeros(self.I0.shape) self._M = None self._simplex_normal = None