Example #1
0
	def __init__(self,u):
		self.shape = u.shape
		self.nchannels =u.shape[2]

		self.uf = np.zeros( (2,) + self.shape )
		self.ub = np.zeros( (2,) + self.shape )

		for c in range(self.nchannels):
			self.uf[:,:,:,c] = FD.forward_differences(u[:,:,c])
			self.ub[:,:,:,c] = FD.backward_differences(u[:,:,c])
Example #2
0
def compute_tv(u):
	shape = u.shape
	uf = np.zeros( (2,) + shape )
	for c in range(shape[2]):
		uf[:,:,:,c] = FD.forward_differences(u[:,:,c])

	tv=0
	for c in range( shape[2] ):
		tv+=np.sum( uf[1,:,:,c]**2 + uf[0,:,:,c]**2 )**0.5

	return tv
Example #3
0
    def __init__(self, img):
        self.shape = img.shape
        self.nchannels = img.shape[2]

        self.gradX = np.zeros((img.shape[0], img.shape[1], self.nchannels))
        self.gradY = np.zeros((img.shape[0], img.shape[1], self.nchannels))

        self.grad2X = np.zeros((img.shape[0], img.shape[1], self.nchannels))
        self.grad2Y = np.zeros((img.shape[0], img.shape[1], self.nchannels))

        for c in range(self.nchannels):
            fd = FD.forward_differences(img[:, :, c])
            self.gradX[:, :, c] += fd[0]  #dx
            self.gradY[:, :, c] += fd[1]  #dy

            fd2 = FD.forward_differences_second(img[:, :, c])
            self.grad2X[:, :, c] += fd2[0]  #dx
            self.grad2Y[:, :, c] += fd2[1]  #dy
Example #4
0
def compute_gradient(A):
    return FD.forward_differences(A)