コード例 #1
0
def shearlets(matrix):
    #  hyperparameter settings (including level at which to threshold)
    sigma = 30
    scales = 2
    thresholdingFactor = shearletThresholdFactor
    # Converting 2D matrix into flaot
    matrix = matrix.astype(float)
    X = matrix
    ## create shearlets system
    shearletSystem = pyshearlab.SLgetShearletSystem2D(0, X.shape[0],
                                                      X.shape[1], scales)
    # decomposition, produces shearlet coefficients
    coeffs = pyshearlab.SLsheardec2D(X, shearletSystem)
    # calculating Root Mean Square value of each coeficient vector that is assosiated with a pixel
    # i.e for sherlet system made out of scales = 2, produces coeficient vector of length 17 for each pixel
    # RMS value is worked out on each of these vectors and the multiplied by the vector
    # A 1xnShearlets array containing the root mean squares (L2-norm divided by
    # sqrt(X*Y)) of all shearlets stored in shearletSystem["shearlets"]. These values can be used to normalize
    # shearlet coefficients to make them comparable.
    oldCoeffs = coeffs.copy()
    weights = np.ones(coeffs.shape)
    for j in range(len(shearletSystem["RMS"])):
        weights[:, :, j] = shearletSystem["RMS"][j] * np.ones(
            (X.shape[0], X.shape[1]))
    #  Thresholding the coefficients based on the setting in the hyperparameters and RMS weights
    #  Setting coefficients to 0 for value that do not pass the threshold
    coeffs = np.real(coeffs)
    zero_indices = np.abs(coeffs) / (thresholdingFactor * weights * sigma) < 1
    coeffs[zero_indices] = 0
    # reconstruction of the signal thresholded coefficients, returning the reconsturcted signal
    Xrec = pyshearlab.SLshearrec2D(coeffs, shearletSystem)
    return Xrec
コード例 #2
0
 def __init__(self,
              iterations,
              stop_factor,
              n_scales,
              patch_size=512,
              stride=384,
              max_workers=8,
              downsampling_factor=1):
     """
     Constructor
     :param iterations: number of iterations
     :type iterations: int
     :param stop_factor: stop factor for thresholding (0<stop_factor<1)
     :type stop_factor: float
     :param n_scales: n_scales for shearlet system, as in shearlab.org
     :type nscales: int
     :param patch_size: size of patch must be >= 512
     :type patch_size: int
     :param stride: stride, i.e., amount by which the window is shifted
     :type stride: int
     :param max_workers: maximum number of processes used for inpainting
     :type max_workers: int
     :param downsampling_factor: specify by which factor the image patches are downsampled before inpainting, must be a power of 2
     :type downsampling_factor: int
     """
     shearlet_system = psl.SLgetShearletSystem2D(
         1, int(patch_size / downsampling_factor),
         int(patch_size / downsampling_factor), n_scales)
     self.patch_size = patch_size
     self.stride = stride
     self.border_size = (self.patch_size - self.stride)
     self.max_workers = max_workers
     self.downsampling_factor = downsampling_factor
     self.stop_factor = stop_factor
     self.iterations = iterations
     self.shearlet_system = shearlet_system
コード例 #3
0
    def __init__(self, space, num_scales):
        """Initialize a new instance.

        Parameters
        ----------
        space : `DiscretizedSpace`
            The space on which the shearlet transform should act. Must be
            two-dimensional.
        num_scales : nonnegative `int`
            The number of scales for the shearlet transform, higher numbers
            mean better edge resolution but more computational burden.

        Examples
        --------
        Create a 2d-shearlet transform:

        >>> space = odl.uniform_discr([-1, -1], [1, 1], [128, 128])
        >>> shearlet_transform = PyShearlabOperator(space, num_scales=2)
        """
        self.shearlet_system = pyshearlab.SLgetShearletSystem2D(
            0, space.shape[0], space.shape[1], num_scales)
        range = space**self.shearlet_system['nShearlets']
        self.mutex = Lock()
        super(PyShearlabOperator, self).__init__(space, range, True)
コード例 #4
0
sigma = 30
scales = 3
thresholdingFactor = 3

# load data
X = img.imread("barbara.jpg")[::4, ::4]
X = X.astype(float)

# add noise
Xnoisy = X + sigma * np.random.randn(X.shape[0], X.shape[1])
toc()

tic()
print("generating shearlet system...")
## create shearlets
shearletSystem = pyshearlab.SLgetShearletSystem2D(0, X.shape[0], X.shape[1],
                                                  scales)

toc()
tic()
print("decomposition, thresholding and reconstruction...")

# decomposition
coeffs = pyshearlab.SLsheardec2D(Xnoisy, shearletSystem)

# thresholding
oldCoeffs = coeffs.copy()
weights = np.ones(coeffs.shape)

for j in range(len(shearletSystem["RMS"])):
    weights[:, :, j] = shearletSystem["RMS"][j] * np.ones(
        (X.shape[0], X.shape[1]))
コード例 #5
0
def shearletSystem(shape):
    scales = 2
    return pyshearlab.SLgetShearletSystem2D(0,
                                            shape[0], shape[1],
                                            scales)