Esempio n. 1
0
                        )
                    return self.res
                self.res -= alpha * self.__p__
                self.reinitialise_cgls()
                self.re_init_at_iteration = i

            self.__r__ -= alpha * q
            s = tigre.Atb(self.__r__,
                          self.geo,
                          self.angles,
                          gpuids=self.gpuids)
            s_norm = np.linalg.norm(s)

            gamma1 = s_norm * s_norm
            beta = gamma1 / self.__gamma__
            if self.log_parameters:
                self.parameter_history["alpha"][i] = alpha
                self.parameter_history["beta"][i] = beta
                self.parameter_history["gamma"][i] = self.__gamma__
                self.parameter_history["q_norm"][i] = q_norm
                self.parameter_history["s_norm"][i] = s_norm

            self.__gamma__ = gamma1
            self.__p__ = s + beta * self.__p__
        if self.verbose:
            print("Average time taken for each iteration for CGLS:" +
                  str(sum(avgtime) / len(avgtime)) + "(s)")


cgls = decorator(CGLS, name="cgls")
Esempio n. 2
0
            alpha = self._gamma / (q_norm * q_norm)
            self.res += alpha * self._p

            aux = self.proj - Ax(self.res, self.geo, self.angles, 'ray-voxel')
            self.l2l[i] = np.linalg.norm(aux.ravel(), 2)

            if i > 0 and self.l2l[i] > self.l2l[i - 1]:
                print('re-initialization was called at iter:' + str(i))
                self.res -= alpha * self._p
                self.initialise_cgls()

            self._r -= alpha * q

            s = Atb(self._r, self.geo, self.angles)
            s_norm = np.linalg.norm(s.ravel(), 2)

            gamma1 = s_norm * s_norm
            beta = gamma1 / self._gamma
            if self.log_parameters:
                self.parameter_history['alpha'][i] = alpha
                self.parameter_history['beta'][i] = beta
                self.parameter_history['gamma'][i] = self._gamma
                self.parameter_history['q_norm'][i] = q_norm
                self.parameter_history['s_norm'][i] = s_norm

            self._gamma = gamma1
            self._p = s + beta * self._p


cgls = decorator(CGLS)
Esempio n. 3
0
class SART(IterativeReconAlg):
    __doc__ = (
        "SART_CBCT solves Cone Beam CT image reconstruction using Oriented Subsets\n"
        "Simultaneous Algebraic Reconstruction Techique algorithm\n"
        "SART(PROJ,GEO,ALPHA,NITER) solves the reconstruction problem\n"
        "using the projection data PROJ taken over ALPHA angles, corresponding\n"
        "to the geometry described in GEO, using NITER iterations. \n"
    ) + IterativeReconAlg.__doc__

    def __init__(self, proj, geo, angles, niter, **kwargs):
        kwargs.update(dict(blocksize=1))
        IterativeReconAlg.__init__(self, proj, geo, angles, niter, **kwargs)


sart = decorator(SART, name='sart')


class SIRT(IterativeReconAlg):
    __doc__ = (
        "SART_CBCT solves Cone Beam CT image reconstruction using Oriented Subsets\n"
        "Simultaneous Algebraic Reconxtruction Techique algorithm\n"
        "SIRT(PROJ,GEO,ALPHA,NITER) solves the reconstruction problem\n"
        "using the projection data PROJ taken over ALPHA angles, corresponding\n"
        "to the geometry descrived in GEO, using NITER iterations.\n"
    ) + IterativeReconAlg.__doc__

    def __init__(self, proj, geo, angles, niter, **kwargs):
        kwargs.update(dict(blocksize=angles.shape[0]))
        IterativeReconAlg.__init__(self, proj, geo, angles, niter, **kwargs)
Esempio n. 4
0
                if i == 1:
                    tic = time.clock()
                    print('Esitmated time until completetion (s): ' +
                          str((self.niter - 1) * (tic - toc)))
            getattr(self, self.dataminimizing)()

            x_rec_old = copy.deepcopy(x_rec)
            x_rec = im3ddenoise(self.res, self.__numiter_tv__, 1. / lambdaForTv)
            t_old = t
            t = (1 + np.sqrt(1 + 4 * t ** 2)) / 2
            self.res = x_rec + (t_old - 1) / t * (x_rec - x_rec_old)

            self.error_measurement(res_prev, i)


fista = decorator(FISTA, name='FISTA')


class ISTA(FISTA):
    __doc__ = FISTA.__doc__

    def __int__(self, proj, geo, angles, niter, **kwargs):
        FISTA.__init__(self, proj, geo, angles, niter, **kwargs)

    def run_main_iter(self):
        """
        Goes through the main iteration for the given configuration.
        :return: None
        """
        Quameasopts = self.Quameasopts
        lambdaForTv = 2 * self.__bm__ * self.lmbda
Esempio n. 5
0

class ASD_POCS(initASD_POCS):
    __doc__ = initASD_POCS.__doc__
    
    def __init__(self, proj, geo, angles, niter, **kwargs):
        
        if "blocksize" in kwargs and kwargs['blocksize']>1:
            print('Warning: blocksize is set to 1, please use an OS version of the algorithm for blocksize > 1')
        kwargs.update(dict(blocksize=1))
        kwargs.update(dict(regularisation="minimizeTV"))
        
        initASD_POCS.__init__(self, proj, geo, angles, niter, **kwargs)
       

asd_pocs = decorator(ASD_POCS, name="asd_pocs")


class AwASD_POCS(initASD_POCS):  
    __doc__ = ("    AwASD_POCS is the Adaptive Weighted TV (edge preserving) version of ASD_POCS\n\n"
               "        :extra kwargs delta: (float)\n"
               "            Control amount of smoothing at edges of the image\n"
               "            Default delta = -0.005\n") + initASD_POCS.__doc__

    def __init__(self, proj, geo, angles, niter, **kwargs):

        if "blocksize" in kwargs and kwargs['blocksize']>1:
            print('Warning: blocksize is set to 1, please use an OS version of the algorithm for blocksize > 1')
        kwargs.update(dict(blocksize=1))
        kwargs.update(dict(regularisation="minimizeAwTV"))
        self.delta = np.float32(-0.005) if "delta" not in kwargs else kwargs["delta"] 
Esempio n. 6
0
            #            tic = time.process_time()
            den = Ax(self.res,
                     self.geo,
                     self.angles,
                     "interpolated",
                     gpuids=self.gpuids)
            # toc = time.process_time()
            # print('Ax time: {}'.format(toc-tic))
            den[den == 0.0] = np.inf
            auxmlem = self.proj / den
            # auxmlem[auxmlem == np.nan] = 0.
            # auxmlem[auxmlem == np.inf] = 0.

            # update
            # tic = time.process_time()
            img = Atb(auxmlem,
                      self.geo,
                      self.angles,
                      backprojection_type="matched",
                      gpuids=self.gpuids) / self.W
            # toc = time.process_time()
            # print('Atb time: {}'.format(toc-tic))
            # img[img == np.nan] = 0.
            # img[img == np.inf] = 0.

            self.res = self.res * img
            self.res[self.res < 0.0] = 0.0


mlem = decorator(MLEM, name="mlem")
            for item in self.__dict__:
                if type(getattr(self, item)) == np.ndarray:
                    if np.isnan(getattr(self, item)).any():
                        raise ValueError('nan found for ' + item + ' at iteraton ' + str(i))

            aux = self.proj - Ax(self.res, self.geo, self.angles, 'ray-voxel')
            self.l2l[i] = np.linalg.norm(aux.ravel(), 2)
            if i > 0 and self.l2l[i] > self.l2l[i - 1]:
                print('re-initialization was called at iter:' + str(i))
                self.res -= alpha * self.__p__
                self.reinitialise_cgls()

            self.__r__ -= alpha * q
            s = Atb(self.__r__, self.geo, self.angles)
            s_norm = np.linalg.norm(s.ravel(), 2)

            gamma1 = s_norm * s_norm
            beta = gamma1 / self.__gamma__
            if self.log_parameters:
                self.parameter_history['alpha'][i] = alpha
                self.parameter_history['beta'][i] = beta
                self.parameter_history['gamma'][i] = self.__gamma__
                self.parameter_history['q_norm'][i] = q_norm
                self.parameter_history['s_norm'][i] = s_norm

            self.__gamma__ = gamma1
            self.__p__ = s + beta * self.__p__


cgls = decorator(CGLS, name='cgls')
Esempio n. 8
0
from tigre.algorithms.iterative_recon_alg import decorator


class SART(IterativeReconAlg):
    __doc__ = ("SART_CBCT solves Cone Beam CT image reconstruction using Oriented Subsets\n"
               "Simultaneous Algebraic Reconstruction Techique algorithm\n"
               "SART(PROJ,GEO,ALPHA,NITER) solves the reconstruction problem\n"
               "using the projection data PROJ taken over ALPHA angles, corresponding\n"
               "to the geometry described in GEO, using NITER iterations. \n") + IterativeReconAlg.__doc__

    def __init__(self, proj, geo, angles, niter, **kwargs):
        kwargs.update(dict(blocksize=1))
        IterativeReconAlg.__init__(self, proj, geo, angles, niter, **kwargs)


sart = decorator(SART, name='sart')


class SIRT(IterativeReconAlg):
    __doc__ = ("SART_CBCT solves Cone Beam CT image reconstruction using Oriented Subsets\n"
               "Simultaneous Algebraic Reconxtruction Techique algorithm\n"

               "SIRT(PROJ,GEO,ALPHA,NITER) solves the reconstruction problem\n"
               "using the projection data PROJ taken over ALPHA angles, corresponding\n"
               "to the geometry descrived in GEO, using NITER iterations.\n") + IterativeReconAlg.__doc__

    def __init__(self, proj, geo, angles, niter, **kwargs):
        kwargs.update(dict(blocksize=angles.shape[0]))
        IterativeReconAlg.__init__(self, proj, geo, angles, niter, **kwargs)

Esempio n. 9
0
class SART(IterativeReconAlg):
    __doc__ = (
        "SART_CBCT solves Cone Beam CT image reconstruction using Oriented Subsets\n"
        "Simultaneous Algebraic Reconstruction Techique algorithm\n"
        "SART(PROJ,GEO,ALPHA,NITER) solves the reconstruction problem\n"
        "using the projection data PROJ taken over ALPHA angles, corresponding\n"
        "to the geometry described in GEO, using NITER iterations. \n"
    ) + IterativeReconAlg.__doc__

    def __init__(self, proj, geo, angles, niter, **kwargs):
        kwargs.update(dict(blocksize=1))
        IterativeReconAlg.__init__(self, proj, geo, angles, niter, **kwargs)


sart = decorator(SART, name='sart')


class SIRT(IterativeReconAlg):
    __doc__ = (
        "SIRT_CBCT solves Cone Beam CT image reconstruction using Oriented Subsets\n"
        "Simultaneous Algebraic Reconxtruction Techique algorithm\n"
        "SIRT(PROJ,GEO,ALPHA,NITER) solves the reconstruction problem\n"
        "using the projection data PROJ taken over ALPHA angles, corresponding\n"
        "to the geometry descrived in GEO, using NITER iterations.\n"
    ) + IterativeReconAlg.__doc__

    def __init__(self, proj, geo, angles, niter, **kwargs):
        kwargs.update(dict(blocksize=angles.shape[0]))
        IterativeReconAlg.__init__(self, proj, geo, angles, niter, **kwargs)
Esempio n. 10
0
            c = np.dot(dg_vec.reshape(-1,), dp_vec.reshape(-1,)) / max(
                dg * dp, 1e-6
            )  # reshape ensures no copy is made.
            if (c < -0.99 and dd <= self.epsilon) or self.beta < 0.005 or n_iter > self.niter:
                if self.verbose:
                    print(
                        "\n"
                        "     Stop criteria met: \n"
                        "     c = " + str(c) + "\n"
                        "     beta = " + str(self.beta) + "\n"
                        "     iter = " + str(n_iter) + "\n"
                    )
                stop_criteria = True


asd_pocs = decorator(ASD_POCS, name="asd_pocs")


class AwASD_POCS(ASD_POCS):  # noqa: D101, N801
    __doc__ = ASD_POCS.__doc__

    def __init__(self, proj, geo, angles, niter, **kwargs):

        kwargs.update(dict(regularisation="minimizeAwTV"))
        if "blocksize" not in kwargs: 
            kwargs.update(dict(blocksize=1))
        else:
            self.blocksize = 1
        if "delta" not in kwargs:
            self.delta = np.array([-0.005], dtype=np.float32)[0]
        ASD_POCS.__init__(self, proj, geo, angles, niter, **kwargs)
Esempio n. 11
0
                        'Esitmated time until completetion (s): {:.4f}'.format(
                            (self.niter - 1) * (tic - toc)))


#            tic = time.process_time()
            den = Ax(self.res,
                     self.geo,
                     self.angles,
                     'interpolated',
                     gpuids=self.gpuids)
            # toc = time.process_time()
            # print('Ax time: {}'.format(toc-tic))
            den[den == 0.] = np.inf
            auxmlem = self.proj / den
            # auxmlem[auxmlem == np.nan] = 0.
            # auxmlem[auxmlem == np.inf] = 0.

            # update
            # tic = time.process_time()
            img = Atb(auxmlem, self.geo, self.angles,
                      gpuids=self.gpuids) / self.W
            # toc = time.process_time()
            # print('Atb time: {}'.format(toc-tic))
            # img[img == np.nan] = 0.
            # img[img == np.inf] = 0.

            self.res = self.res * img
            self.res[self.res < 0.] = 0.

mlem = decorator(MLEM, name='mlem')
Esempio n. 12
0
class SART(IterativeReconAlg):  # noqa: D101
    __doc__ = (
        "SART_CBCT solves Cone Beam CT image reconstruction using Oriented Subsets\n"
        "Simultaneous Algebraic Reconstruction Techique algorithm\n"
        "SART(PROJ,GEO,ALPHA,NITER) solves the reconstruction problem\n"
        "using the projection data PROJ taken over ALPHA angles, corresponding\n"
        "to the geometry described in GEO, using NITER iterations. \n"
    ) + IterativeReconAlg.__doc__

    def __init__(self, proj, geo, angles, niter, **kwargs):
        kwargs.update(dict(blocksize=1))
        IterativeReconAlg.__init__(self, proj, geo, angles, niter, **kwargs)


sart = decorator(SART, name="sart")


class SIRT(IterativeReconAlg):  # noqa: D101
    __doc__ = (
        "SIRT_CBCT solves Cone Beam CT image reconstruction using Oriented Subsets\n"
        "Simultaneous Algebraic Reconxtruction Techique algorithm\n"
        "SIRT(PROJ,GEO,ALPHA,NITER) solves the reconstruction problem\n"
        "using the projection data PROJ taken over ALPHA angles, corresponding\n"
        "to the geometry descrived in GEO, using NITER iterations.\n"
    ) + IterativeReconAlg.__doc__

    def __init__(self, proj, geo, angles, niter, **kwargs):
        kwargs.update(dict(blocksize=angles.shape[0]))
        IterativeReconAlg.__init__(self, proj, geo, angles, niter, **kwargs)
Esempio n. 13
0
            if dg > self.rmax*dp and dd > self.epsilon:
                dtvg = dtvg*self.alpha_red

            self.beta *= self.beta_red
            c = np.dot(dg_vec.reshape(-1,), dp_vec.reshape(-1,))/max(dg*dp, 1e-6)
            if (c < -0.99 and dd <= self.epsilon) or self.beta < 0.005 or n_iter > self.niter:
                if self.verbose:
                    print("\n"
                          "     Stop criteria met: \n"
                          "     c = " + str(c) + "\n"
                          "     beta = " + str(self.beta) + "\n" 
                          "     iter = " + str(n_iter)) + "\n"
                stop_criteria = True


asd_pocs = decorator(ASD_POCS, name='asd_pocs')


class AwASD_POCS(ASD_POCS):
    __doc__ = ASD_POCS.__doc__

    def __init__(self, proj, geo, angles, niter, **kwargs):

        kwargs.update(dict(regularisation='minimizeAwTV'))

        if 'delta' not in kwargs:
            self.delta = np.array([-0.005], dtype=np.float32)[0]
        ASD_POCS.__init__(self, proj, geo, angles, niter, **kwargs)


awasd_pocs = decorator(AwASD_POCS, name='awasd_pocs')
Esempio n. 14
0
                        )
                    return self.res
                self.res -= alpha * self.__p__
                self.reinitialise_cgls()
                self.re_init_at_iteration = i

            self.__r__ -= alpha * q
            s = tigre.Atb(self.__r__,
                          self.geo,
                          self.angles,
                          gpuids=self.gpuids)
            s_norm = np.linalg.norm(s)

            gamma1 = s_norm * s_norm
            beta = gamma1 / self.__gamma__
            if self.log_parameters:
                self.parameter_history['alpha'][i] = alpha
                self.parameter_history['beta'][i] = beta
                self.parameter_history['gamma'][i] = self.__gamma__
                self.parameter_history['q_norm'][i] = q_norm
                self.parameter_history['s_norm'][i] = s_norm

            self.__gamma__ = gamma1
            self.__p__ = s + beta * self.__p__
        if self.verbose:
            print('Average time taken for each iteration for CGLS:' +
                  str(sum(avgtime) / len(avgtime)) + '(s)')


cgls = decorator(CGLS, name='cgls')
Esempio n. 15
0
                    tic = default_timer()
                    print("Esitmated time until completetion (s): " +
                          str((self.niter - 1) * (tic - toc)))
            getattr(self, self.dataminimizing)()

            x_rec_old = copy.deepcopy(x_rec)
            x_rec = im3ddenoise(self.res, self.__numiter_tv__,
                                1.0 / lambdaForTv, self.gpuids)
            t_old = t
            t = (1 + np.sqrt(1 + 4 * t**2)) / 2
            self.res = x_rec + (t_old - 1) / t * (x_rec - x_rec_old)

            self.error_measurement(res_prev, i)


fista = decorator(FISTA, name="FISTA")


class ISTA(FISTA):  # noqa: D101
    __doc__ = FISTA.__doc__

    def __init__(self, proj, geo, angles, niter, **kwargs):
        FISTA.__init__(self, proj, geo, angles, niter, **kwargs)

    def run_main_iter(self):
        """
        Goes through the main iteration for the given configuration.
        :return: None
        """
        Quameasopts = self.Quameasopts
        lambdaForTv = 2 * self.__bm__ * self.lmbda
Esempio n. 16
0
            self.beta *= self.beta_red
            c = np.dot(dg_vec.reshape(-1, ), dp_vec.reshape(-1, )) / max(
                dg * dp, 1e-6)
            if (c < -0.99 and dd <= self.epsilon
                ) or self.beta < 0.005 or n_iter > self.niter:
                if self.verbose:
                    print("\n"
                          "     Stop criteria met: \n"
                          "     c = " + str(c) + "\n"
                          "     beta = " + str(self.beta) + "\n"
                          "     iter = " + str(n_iter)) + "\n"
                stop_criteria = True


asd_pocs = decorator(ASD_POCS, name='asd_pocs')


class AwASD_POCS(ASD_POCS):
    __doc__ = ASD_POCS.__doc__

    def __init__(self, proj, geo, angles, niter, **kwargs):

        kwargs.update(dict(regularisation='minimizeAwTV'))

        if 'delta' not in kwargs:
            self.delta = np.array([-0.005], dtype=np.float32)[0]
        ASD_POCS.__init__(self, proj, geo, angles, niter, **kwargs)


awasd_pocs = decorator(AwASD_POCS, name='awasd_pocs')
Esempio n. 17
0
            c = np.dot(dg_vec.reshape(-1,), dp_vec.reshape(-1,)) / max(
                dg * dp, 1e-6
            )  # reshape ensures no copy is made.
            if (c < -0.99 and dd <= self.epsilon) or self.beta < 0.005 or n_iter > self.niter:
                if self.verbose:
                    print(
                        "\n"
                        "     Stop criteria met: \n"
                        "     c = " + str(c) + "\n"
                        "     beta = " + str(self.beta) + "\n"
                        "     iter = " + str(n_iter) + "\n"
                    )
                stop_criteria = True


asd_pocs = decorator(ASD_POCS, name="asd_pocs")


class AwASD_POCS(ASD_POCS):  # noqa: D101, N801
    __doc__ = ASD_POCS.__doc__

    def __init__(self, proj, geo, angles, niter, **kwargs):

        kwargs.update(dict(regularisation="minimizeAwTV"))

        if "delta" not in kwargs:
            self.delta = np.array([-0.005], dtype=np.float32)[0]
        ASD_POCS.__init__(self, proj, geo, angles, niter, **kwargs)


awasd_pocs = decorator(AwASD_POCS, name="awasd_pocs")