def external_update(self, u, f, uf, f0, u0): # overload the update function CsSolver.checkmax(self.st['sensemap']) tmpuf = u * self.st['sensemap'] tmpuf = numpy.transpose(tmpuf, (1, 2, 3, 0)) tmp_shape = tmpuf.shape tmpuf = numpy.reshape(tmpuf, tmp_shape[0:2] + (numpy.prod(tmp_shape[2:4]), ), order='F') tmpuf = self.CsTransform.forwardbackward(tmpuf) tmpuf = numpy.reshape(tmpuf, tmp_shape, order='F') tmpuf = numpy.transpose(tmpuf, (3, 0, 1, 2)) tmpuf = tmpuf * self.st['sensemap'].conj() # tmpuf=self.st['sensemap'].conj()*( # self.CsTransform.forwardbackward( # u*self.st['sensemap'])) if self.st['senseflag'] == 1: tmpuf = CsSolver.CombineMulti(tmpuf, -1) print('start of ext_update') # checkmax(u) # checkmax(tmpuf) # checkmax(self.u0) # checkmax(uf) fact = numpy.sum((self.u0 - tmpuf)**2) / numpy.sum((u0)**2) fact = numpy.abs(fact.real) fact = numpy.sqrt(fact) print('fact', fact) # fact=1.0/(1.0+numpy.exp(-(fact-0.5)*self.thresh_scale)) tmpuf = CsSolver.Normalize(tmpuf) * numpy.max(numpy.abs(u0[:])) uf = uf + (u0 - tmpuf) * 1.0 #*fact uf = CsSolver.Normalize(uf) * numpy.max(numpy.abs(u0[:])) CsSolver.checkmax(tmpuf) CsSolver.checkmax(u0) CsSolver.checkmax(uf) # for jj in range(0,u.shape[-1]): # u[...,jj] = u[...,jj]*self.st['sn']# rescale the final image intensity print('end of ext_update') murf = uf return (f, uf, murf, u)
def kernel(self, f_internal, st, mu, LMBD, gamma, nInner, nBreg): self.st['sensemap'] = self.st['sensemap'] * self.st['mask'] tse = self.f.tse # tse=numpy.abs(numpy.mean(self.st['sensemap'],-1)) tse = CsSolver.appendmat(tse, self.st['Nd'][1]) #tse=Normalize(tse) tse = numpy.transpose(tse, (0, 1, 3, 2)) self.ttse = CsSolver.Normalize(tse) self.tse0 = CsSolver.CombineMulti(tse, -1) self.filter = numpy.ones(tse.shape) dpss = numpy.kaiser(tse.shape[1], 1.0) * 10.0 for ppp in range(0, tse.shape[1]): self.filter[:, ppp, :, :] = self.filter[:, ppp, :, :] * dpss[ppp] print('tse.shape', tse.shape) # L= numpy.size(f)/st['M'] # image_dim=st['Nd']+(L,) # # if numpy.ndim(f) == 1:# preventing row vector # f=numpy.reshape(f,(numpy.shape(f)[0],1),order='F') # f0 = numpy.copy(f) # deep copy to prevent scope f0 to f ## u = numpy.zeros(image_dim,dtype=numpy.complex64) f0 = numpy.copy(f_internal) f = numpy.copy(f_internal) # u0=self.data2rho(f_internal, # self.f.dim_x, # self.st['Nd'][0], # self.st['Nd'][1], # self.f.ncoils, # self.CsTransform # ) # doing spatial transform u0 = self.fun1(f_internal) pdf = self.f.pdf pdf = CsSolver.appendmat(pdf, self.st['Nd'][1]) pdf = numpy.transpose(pdf, (0, 1, 3, 2)) # u0 = scipy.fftpack.fftn(u0,axes=(1,)) # u0 = scipy.fftpack.fftshift(u0,axes=(1,)) # #u0[:,:,u0.shape[2]/2,:] = u0[:,:,u0.shape[2]/2,:]/pdf[:,:,u0.shape[2]/2,:] # u0 = u0#/pdf # u0 = scipy.fftpack.ifftshift(u0,axes=(1,)) # u0 = scipy.fftpack.ifftn(u0,axes=(1,)) # print('self.f.pdf.shape',self.f.pdf.shape) # for pj in range(0,4): # matplotlib.pyplot.imshow(self.f.pdf[:,:,pj].real) # matplotlib.pyplot.show() u0 = self.fun2(u0) u0 = self.fun3(u0) u0 = u0 * self.st['sensemap'].conj() u0 = CsSolver.CombineMulti(u0, -1) #u0 = u0*self.filter uker = self.create_laplacian_kernel() uker = CsSolver.appendmat(uker, u0.shape[3]) self.u0 = u0 u = numpy.copy(self.tse0) print('u0.shape', u0.shape) (xx, bb, dd) = self.make_split_variables(u) uf = numpy.copy(u) # only used for ISRA, written here for generality murf = numpy.copy(u) # initial values # #=============================================================================== #u_stack = numpy.empty(st['Nd']+(nBreg,),dtype=numpy.complex) for outer in numpy.arange(0, nBreg): for inner in numpy.arange(0, nInner): # update u print('iterating', [inner, outer]) #=============================================================== # update u # simple k-space deconvolution to guess initial u u = self.update_u(murf, u, uker, xx, bb) c = numpy.max(numpy.abs(u[:])) # Rough coefficient # to correct threshold of nonlinear shrink #=================================================================== # # update d #=================================================================== #=================================================================== # Shrinkage: remove tiny values "in somewhere sparse!" # dx+bx should be sparse! #=================================================================== # shrinkage #=================================================================== dd = self.update_d(u, dd) xx = self.shrink( dd, bb, c * 1.0 / LMBD / numpy.sqrt(numpy.prod(st['Nd']))) #=============================================================== #=================================================================== # # update b #=================================================================== bb = self.update_b(bb, dd, xx) # if outer < nBreg: # do not update in the last loop (f, uf, murf, u) = self.external_update(u, f, uf, f0, u0) # update outer Split_bregman u = CsSolver.Normalize(u) for pp in range(0, u0.shape[2]): matplotlib.pyplot.subplot( numpy.sqrt(u0.shape[2]) + 1, numpy.sqrt(u0.shape[2]) + 1, pp) matplotlib.pyplot.imshow(numpy.sum(numpy.abs(u[..., pp, :]), -1), norm=norm, interpolation='nearest') matplotlib.pyplot.show() # return (u, uf)