Esempio n. 1
0
def _forwardproject_block_(projections, volume, proj_geom, vol_geom, operation = '+'):
    """
    Use this internal function to compute backprojection of a single block of data.
    """           
    try:
        
        if (operation == '+'):
            projections_ = projections
            
        elif (operation == '*') | (operation == '/'):
            projections_ = numpy.zeros_like(projections)
            
        else: ValueError('Unknown operation type!')    
                
        sin_id = astra.data3d.link('-sino', proj_geom, projections_)        
        vol_id = astra.data3d.link('-vol', vol_geom, volume)    
        
        projector_id = astra.create_projector('cuda3d', proj_geom, vol_geom)
        
        asex.accumulate_FP(projector_id, vol_id, sin_id)
        
        if (operation == '*'):
             projections *= projections_
        elif (operation == '/'):
            
             projections_[projections_ < 1e-10] = numpy.inf        
             projections /= projections_
             
    except:
        print("ASTRA error:", sys.exc_info())
        
    finally:
        astra.algorithm.delete(projector_id)
        astra.data3d.delete(sin_id)
        astra.data3d.delete(vol_id)            
Esempio n. 2
0
def _forwardproject_block_add_(projections,
                               volume,
                               proj_geom,
                               vol_geom,
                               negative=False):
    """
    Additive forwardprojection of a single block. 
    Use negative = True if you want subtraction instead of addition.
    """

    try:
        # We are goint to negate the projections block and not the whole volume:
        if negative:
            projections *= -1

        # If volume is a memmap - create a temporary copy in RAM
        if isinstance(volume, numpy.memmap):
            vol_temp = numpy.ascontiguousarray(volume)

            vol_id = astra.data3d.link('-vol', vol_geom, vol_temp)
        else:
            vol_id = astra.data3d.link('-vol', vol_geom, volume)

        sin_id = astra.data3d.link('-sino', proj_geom, projections)

        projector_id = astra.create_projector('cuda3d', proj_geom, vol_geom)

        # Project!
        asex.accumulate_FP(projector_id, vol_id, sin_id)

        # Negate second time:
        if negative:
            projections *= -1

    except:
        # Always try to delete data3d:
        try:
            astra.algorithm.delete(projector_id)
            astra.data3d.delete(sin_id)
            astra.data3d.delete(vol_id)
        finally:
            info = sys.exc_info()
            traceback.print_exception(*info)

    astra.algorithm.delete(projector_id)
    astra.data3d.delete(sin_id)
    astra.data3d.delete(vol_id)
Esempio n. 3
0
    def _forwardproject_block(self, proj_data, proj_geom, vol_data, vol_geom):
        '''
        Forwardproject a single block of data
        '''
        try:
            sin_id = astra.data3d.link('-sino', proj_geom, proj_data)
            vol_id = astra.data3d.link('-vol', vol_geom, vol_data)

            projector_id = astra.create_projector('cuda3d', proj_geom,
                                                  vol_geom)

            #print('**proj_data', proj_data.sum())
            asex.accumulate_FP(projector_id, vol_id, sin_id)
            #print('**proj_data', proj_data.sum())
        except:
            print("ASTRA error:", sys.exc_info())

        finally:
            astra.data3d.delete(sin_id)
            astra.data3d.delete(vol_id)
            astra.projector.delete(projector_id)

        return proj_data