def test_SplatWorldAdjoint(self, disp=False): # Random input images reg = common.RandImage(self.sz, nSig=1.0, gSig=0.0, mType=ca.MEM_HOST, sp=self.imSp) # adjust hJ's grid so that voxels don't align perfectly spfactor = 0.77382 small = common.RandImage(self.sz, nSig=1.0, gSig=0.0, mType=ca.MEM_HOST, sp=self.imSp * spfactor) tmpsmall = ca.Image3D(small.grid(), ca.MEM_HOST) ca.SetMem(tmpsmall, 0) # compute < I(Phi(x)), J(x) > ca.ResampleWorld(tmpsmall, reg) smallIP = ca.Dot(tmpsmall, small) # compute < I(y), |DPhi^{-1}(y)| J(Phi^{-1}(y)) > tmpreg = ca.Image3D(reg.grid(), ca.MEM_HOST) ca.SetMem(tmpreg, 0) ca.SplatWorld(tmpreg, small) regIP = ca.Dot(tmpreg, reg) #print "a=%f b=%f" % (phiIdotJ, IdotphiJ) self.assertLess(abs(smallIP - regIP), 2e-6)
def test_SplatAdjoint(self, disp=False): hI = common.RandImage(self.sz, nSig=1.0, gSig=0.0, mType=ca.MEM_HOST, sp=self.imSp) hJ = common.RandImage(self.sz, nSig=1.0, gSig=0.0, mType=ca.MEM_HOST, sp=self.imSp) hPhi = common.RandField(self.sz, nSig=5.0, gSig=4.0, mType=ca.MEM_HOST, sp=self.imSp) tmp = ca.Image3D(self.grid, ca.MEM_HOST) # compute < I(Phi(x)), J(x) > ca.ApplyH(tmp, hI, hPhi) phiIdotJ = ca.Dot(tmp, hJ) # compute < I(y), |DPhi^{-1}(y)| J(Phi^{-1}(y)) > ca.Splat(tmp, hPhi, hJ) IdotphiJ = ca.Dot(tmp, hI) #print "a=%f b=%f" % (phiIdotJ, IdotphiJ) self.assertLess(abs(phiIdotJ - IdotphiJ), 2e-6)
def test_AddMasked(self, disp=False): SetMem(self.hIm, 0.0) SetMem(self.dIm, 0.0) hIm2 = common.RandImage(self.sz, nSig=1.0, gSig=0.0, mType=MEM_HOST, sp=self.imSp) dIm2 = hIm2.copy() dIm2.toType(MEM_DEVICE) Add(self.hIm, self.hRandIm, hIm2, self.hRandMask) Add(self.dIm, self.dRandIm, dIm2, self.dRandMask) self.TestIm(self.hIm, self.dIm, name='AddMasked', disp=disp)
def RunTest(): # number of iterations nIters = 2000 #nIters = 0 disp = True dispEvery = 1000 if GetNumberOfCUDADevices() > 0: mType = MEM_DEVICE else: print "No CUDA devices found, running on CPU" mType = MEM_HOST # data fidelity modifier DataFidC = 20.0 # TV modifier TVC = 1.0 TVPow = 1.0 UseMask = True # regularization term to avoid zero denominator Beta = 1e-5 stepI = 0.001 imagedir = './Images/' # # Run lena images # Data = common.LoadPNGImage(imagedir + 'lena_orig.png', mType) imSz = Data.size() sz = imSz.tolist()[0:2] if True: I0 = Data.copy() else: I0 = common.RandImage(nSig=1.0, gSig=5.0, mType=mType) Mask = None if UseMask: bdr = 10 MaskArr = np.zeros(sz) MaskArr[bdr:-bdr, bdr:-bdr] = 1.0 Mask = common.ImFromNPArr(MaskArr, mType) (I, energy) = \ RunROFTV(Data=Data, \ I0 = I0, \ DataFidC=DataFidC, \ TVC=TVC, \ TVPow=TVPow, \ stepI=stepI, \ Beta=Beta, \ nIters=nIters, \ dispEvery=dispEvery, \ disp=disp, \ Mask=Mask) print 'final energy: {ttl:n} = {im:n} + {tv:n}'\ .format(ttl=energy[2][-1], \ im=energy[0][-1], \ tv=energy[1][-1])
def randImSetUp(self): self.hRandIm = \ common.RandImage(self.sz, nSig=1.0, gSig=0.0, mType = MEM_HOST, sp = self.imSp) self.dRandIm = self.hRandIm.copy() self.dRandIm.toType(MEM_DEVICE)