Exemple #1
0
def _dist_recon(tomo, center, recon, algorithm, args, kwargs, ncore, nchunk):
    axis_size = recon.shape[0]
    ncore, nchunk = mproc.get_ncore_nchunk(axis_size, ncore, nchunk)

    chnks = np.round(np.linspace(0, axis_size, ncore+1)).astype(np.int)
    mulargs = []
    for i in range(ncore):
        mulargs.append(algorithm(tomo[chnks[i]:chnks[i+1]],
                       center[chnks[i]:chnks[i+1]], recon[chnks[i]:chnks[i+1]],
                       *args, **kwargs))
    e = cf.ThreadPoolExecutor(ncore)
    thrds = [e.submit(args[0], *args[1:]) for args in mulargs]
    for t in thrds:
        t.result()
    return recon
Exemple #2
0
def remove_ring(rec, center_x=None, center_y=None, thresh=300.0,
                thresh_max=300.0, thresh_min=-100.0, theta_min=30,
                rwidth=30, int_mode='WRAP', ncore=None, nchunk=None, out=None):
    """
    Remove ring artifacts from images in the reconstructed domain.
    Descriptions of parameters need to be more clear for sure.

    Parameters
    ----------
    arr : ndarray
        Array of reconstruction data
    center_x : float, optional
        abscissa location of center of rotation
    center_y : float, optional
        ordinate location of center of rotation
    thresh : float, optional
        maximum value of an offset due to a ring artifact
    thresh_max : float, optional
        max value for portion of image to filter
    thresh_min : float, optional
        min value for portion of image to filer
    theta_min : int, optional
        Features larger than twice this angle (degrees) will be considered
        a ring artifact. Must be less than 180 degrees.
    rwidth : int, optional
        Maximum width of the rings to be filtered in pixels
    int_mode : str, optional
        'WRAP' for wrapping at 0 and 360 degrees, 'REFLECT' for reflective
        boundaries at 0 and 180 degrees.
    ncore : int, optional
        Number of cores that will be assigned to jobs.
    nchunk : int, optional
        Chunk size for each core.
    out : ndarray, optional
        Output array for result. If same as arr, process
        will be done in-place.

    Returns
    -------
    ndarray
        Corrected reconstruction data
    """

    rec = dtype.as_float32(rec)

    if out is None:
        out = rec.copy()
    else:
        out = dtype.as_float32(out)

    dz, dy, dx = rec.shape

    if center_x is None:
        center_x = (dx - 1.0)/2.0
    if center_y is None:
        center_y = (dy - 1.0)/2.0

    if int_mode.lower() == 'wrap':
        int_mode = 0
    elif int_mode.lower() == 'reflect':
        int_mode = 1
    else:
        raise ValueError("int_mode should be WRAP or REFLECT")

    if not 0 <= theta_min < 180:
        raise ValueError("theta_min should be in the range [0 - 180)")

    args = (center_x, center_y, dx, dy, dz, thresh_max, thresh_min,
            thresh, theta_min, rwidth, int_mode)

    axis_size = rec.shape[0]
    ncore, nchunk = mproc.get_ncore_nchunk(axis_size, ncore, nchunk)
    with cf.ThreadPoolExecutor(ncore) as e:
        for offset in range(0, axis_size, nchunk):
            slc = np.s_[offset:offset+nchunk]
            e.submit(extern.c_remove_ring, out[slc], *args)
    return out
Exemple #3
0
def remove_ring(rec, center_x=None, center_y=None, thresh=300.0,
                thresh_max=300.0, thresh_min=-100.0, theta_min=30,
                rwidth=30, int_mode='WRAP', ncore=None, nchunk=None, out=None):
    """
    Remove ring artifacts from images in the reconstructed domain.
    Descriptions of parameters need to be more clear for sure.

    Parameters
    ----------
    arr : ndarray
        Array of reconstruction data
    center_x : float, optional
        abscissa location of center of rotation
    center_y : float, optional
        ordinate location of center of rotation
    thresh : float, optional
        maximum value of an offset due to a ring artifact
    thresh_max : float, optional
        max value for portion of image to filter
    thresh_min : float, optional
        min value for portion of image to filer
    theta_min : int, optional
        minimum angle in degrees (int) to be considered ring artifact
    rwidth : int, optional
        Maximum width of the rings to be filtered in pixels
    int_mode : str, optional
        'WRAP' for wrapping at 0 and 360 degrees, 'REFLECT' for reflective
        boundaries at 0 and 180 degrees.
    ncore : int, optional
        Number of cores that will be assigned to jobs.
    nchunk : int, optional
        Chunk size for each core.
    out : ndarray, optional
        Output array for result. If same as arr, process
        will be done in-place.

    Returns
    -------
    ndarray
        Corrected reconstruction data
    """

    rec = dtype.as_float32(rec)

    if out is None:
        out = rec.copy()
    else:
        out = dtype.as_float32(out)

    dz, dy, dx = rec.shape

    if center_x is None:
        center_x = (dx - 1.0)/2.0
    if center_y is None:
        center_y = (dy - 1.0)/2.0

    if int_mode.lower() == 'wrap':
        int_mode = 0
    elif int_mode.lower() == 'reflect':
        int_mode = 1
    else:
        raise ValueError("int_mode should be WRAP or REFLECT")

    args = (center_x, center_y, dx, dy, dz, thresh_max, thresh_min,
            thresh, theta_min, rwidth, int_mode)

    axis_size = rec.shape[0]
    ncore, nchunk = mproc.get_ncore_nchunk(axis_size, ncore, nchunk)
    with cf.ThreadPoolExecutor(ncore) as e:
        for offset in range(0, axis_size, nchunk):
            slc = np.s_[offset:offset+nchunk]
            e.submit(extern.c_remove_ring, out[slc], *args)
    return out
Exemple #4
0
def remove_ring(rec, center_x=None, center_y=None, thresh=300.0,
                thresh_max=300.0, thresh_min=-100.0, theta_min=30,
                rwidth=30, ncore=None, nchunk=None, out=None):
    """
    Remove ring artifacts from images in the reconstructed domain.
    Descriptions of parameters need to be more clear for sure.

    Parameters
    ----------
    arr : ndarray
        Array of reconstruction data
    center_x : float, optional
        abscissa location of center of rotation
    center_y : float, optional
        ordinate location of center of rotation
    thresh : float, optional
        maximum value of an offset due to a ring artifact
    thresh_max : float, optional
        max value for portion of image to filter
    thresh_min : float, optional
        min value for portion of image to filer
    theta_min : int, optional
        minimum angle in degrees (int) to be considered ring artifact
    rwidth : int, optional
        Maximum width of the rings to be filtered in pixels
    ncore : int, optional
        Number of cores that will be assigned to jobs.
    nchunk : int, optional
        Chunk size for each core.
    out : ndarray, optional
        Output array for result.  If same as arr, process will be done in-place.

    Returns
    -------
    ndarray
        Corrected reconstruction data
    """

    rec = dtype.as_float32(rec)
    
    if out is None:
        out = rec.copy()
    else:
        out = dtype.as_float32(out)

    dz, dy, dx = rec.shape

    if center_x is None:
        center_x = (dx - 1.0)/2.0
    if center_y is None:
        center_y = (dy - 1.0)/2.0

    args = (center_x, center_y, dx, dy, dz, thresh_max, thresh_min,
            thresh, theta_min, rwidth)
    
    axis_size = rec.shape[0]
    ncore, nchunk = mproc.get_ncore_nchunk(axis_size, ncore, nchunk)
    
    chnks = np.round(np.linspace(0, axis_size, ncore+1)).astype(np.int)
    mulargs = []
    for i in range(ncore):
        mulargs.append(extern.c_remove_ring(out[chnks[i]:chnks[i+1]],
                       *args))
    e = cf.ThreadPoolExecutor(ncore)
    thrds = [e.submit(args[0], *args[1:]) for args in mulargs]
    for t in thrds:
        t.result()
    return out