Example #1
0
def add_salt_pepper(tomo, prob=0.01, val=None):
    """
    Add salt and pepper noise.

    Parameters
    ----------
    tomo : ndarray
        3D tomographic data.
    prob : float, optional
        Independent probability that each element of a pixel might be
        corrupted by the salt and pepper type noise.
    val : float, optional
        Value to be assigned to the corrupted pixels.

    Returns
    -------
    ndarray
        3D tomographic data after salt and pepper noise added.
    """
    tomo = dtype.as_ndarray(tomo)
    dx, dy, dz = tomo.shape
    ind = np.random.rand(dx, dy, dz) < prob
    if val is None:
        val = tomo.max()
    tomo[ind] = val
    return tomo
Example #2
0
def add_salt_pepper(tomo, prob=0.01, val=None):
    """
    Add salt and pepper noise.

    Parameters
    ----------
    tomo : ndarray
        3D tomographic data.
    prob : float, optional
        Independent probability that each element of a pixel might be
        corrupted by the salt and pepper type noise.
    val : float, optional
        Value to be assigned to the corrupted pixels.

    Returns
    -------
    ndarray
        3D tomographic data after salt and pepper noise added.
    """
    tomo = dtype.as_ndarray(tomo)
    dx, dy, dz = tomo.shape
    ind = np.random.rand(dx, dy, dz) < prob
    if val is None:
        val = tomo.max()
    tomo[ind] = val
    return tomo
Example #3
0
def add_gaussian(tomo, mean=0, std=None):
    """
    Add Gaussian noise.

    Parameters
    ----------
    tomo : ndarray
        3D tomographic data.
    mean : float, optional
        Mean of the Gaussian distribution.
    std : float, optional
        Standard deviation of the Gaussian distribution.

    Returns
    -------
    ndarray
        3D tomographic data after Gaussian noise added.
    """
    tomo = dtype.as_ndarray(tomo)
    if std is None:
        std = tomo.max() * 0.05
    dx, dy, dz = tomo.shape
    tomo += std * np.random.randn(dx, dy, dz) + mean
    return tomo
Example #4
0
def add_gaussian(tomo, mean=0, std=None):
    """
    Add Gaussian noise.

    Parameters
    ----------
    tomo : ndarray
        3D tomographic data.
    mean : float, optional
        Mean of the Gaussian distribution.
    std : float, optional
        Standard deviation of the Gaussian distribution.

    Returns
    -------
    ndarray
        3D tomographic data after Gaussian noise added.
    """
    tomo = dtype.as_ndarray(tomo)
    if std is None:
        std = tomo.max() * 0.05
    dx, dy, dz = tomo.shape
    tomo += std * np.random.randn(dx, dy, dz) + mean
    return tomo