How to use the kymatio.scattering2d.filter_bank.filter_bank function in kymatio

To help you get started, we’ve selected a few kymatio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kymatio / kymatio / kymatio / scattering2d / frontend / tensorflow_frontend.py View on Github external
self.M, self.N = self.shape
        if not self.backend:
            from ..backend.tensorflow_backend import backend # is imported like a module and not a class?
            self.backend = backend
        elif self.backend.name[0:10] != 'tensorflow':
            raise RuntimeError('This backend is not supported.')

        if 2 ** self.J > self.shape[0] or 2 ** self.J > self.shape[1]:
            raise RuntimeError('The smallest dimension should be larger than 2^J')
        self.M_padded, self.N_padded = compute_padding(self.M, self.N, self.J)
        # pads equally on a given side if the amount of padding to add is an even number of pixels, otherwise it adds an extra pixel
        self.pad = self.backend.Pad(
            [(self.M_padded - self.M) // 2, (self.M_padded - self.M + 1) // 2, (self.N_padded - self.N) // 2,
             (self.N_padded - self.N + 1) // 2], [self.M, self.N], pre_pad=self.pre_pad)
        self.unpad = self.backend.unpad
        filters = filter_bank(self.M_padded, self.N_padded, self.J, self.L)
        self.phi, self.psi = filters['phi'], filters['psi']
github kymatio / kymatio / kymatio / scattering2d / frontend / numpy_frontend.py View on Github external
self.M, self.N = self.shape
        if not self.backend:
            from ..backend.numpy_backend import backend # is imported like a module and not a class?
            self.backend = backend
        elif self.backend.name[0:5] != 'numpy':
            raise RuntimeError('This backend is not supported.')

        if 2 ** self.J > self.shape[0] or 2 ** self.J > self.shape[1]:
            raise RuntimeError('The smallest dimension should be larger than 2^J')
        self.M_padded, self.N_padded = compute_padding(self.M, self.N, self.J)
        # pads equally on a given side if the amount of padding to add is an even number of pixels, otherwise it adds an extra pixel
        self.pad = self.backend.Pad(
            [(self.M_padded - self.M) // 2, (self.M_padded - self.M + 1) // 2, (self.N_padded - self.N) // 2,
             (self.N_padded - self.N + 1) // 2], [self.M, self.N], pre_pad=self.pre_pad)
        self.unpad = self.backend.unpad
        filters = filter_bank(self.M_padded, self.N_padded, self.J, self.L)
        self.phi, self.psi = filters['phi'], filters['psi']
github kymatio / kymatio / kymatio / scattering2d / scattering2d.py View on Github external
def build(self):
        self.M, self.N = self.shape
        self.modulus = Modulus()
        self.M_padded, self.N_padded = compute_padding(self.M, self.N, self.J)
        # pads equally on a given side if the amount of padding to add is an even number of pixels, otherwise it adds an extra pixel
        self.pad = Pad([(self.M_padded - self.M) // 2, (self.M_padded - self.M+1) // 2, (self.N_padded - self.N) // 2, (self.N_padded - self.N + 1) // 2], [self.M, self.N], pre_pad=self.pre_pad)
        self.subsample_fourier = SubsampleFourier()
        # Create the filters
        filters = filter_bank(self.M_padded, self.N_padded, self.J, self.L)
        self.Psi = convert_filters(filters['psi'])
        self.Phi = convert_filters([filters['phi'][j] for j in range(self.J)])
github kymatio / kymatio / kymatio / scattering2d / frontend / torch_frontend.py View on Github external
def create_and_register_filters(self):
        """ This function run the filterbank function that
            will create the filters as numpy array, and then, it
            saves those arrays as module's buffers."""

        # Create the filters
        filters = filter_bank(self.M_padded, self.N_padded, self.J, self.L)
        n = 0
        self.phi, self.psi = filters['phi'], filters['psi']
        for c, phi in self.phi.items():
            if isinstance(c, int):
                self.phi[c] = torch.from_numpy(self.phi[c]).unsqueeze(-1) # add a trailing singleton dimension to mark
                # it as non-complex
                self.register_buffer('tensor' + str(n), self.phi[c])
                n += 1

        for j in range(len(self.psi)):
            for k, v in self.psi[j].items():
                if isinstance(k, int):
                    self.psi[j][k] = torch.from_numpy(v).unsqueeze(-1) # add a trailing singleton dimension to mark it
                    # as non-complex
                    self.register_buffer('tensor' + str(n), self.psi[j][k])
                    n += 1
github kymatio / kymatio / examples / 2d / plot_filters.py View on Github external
"""

from colorsys import hls_to_rgb
import matplotlib.pyplot as plt
import numpy as np
from kymatio.scattering2d.filter_bank import filter_bank
from kymatio.scattering2d.utils import fft2


###############################################################################
# Initial parameters of the filter bank
# -------------------------------------
M = 32
J = 3
L = 8
filters_set = filter_bank(M, M, J, L=L)

###############################################################################
# Imshow complex images
# ---------------------
# Thanks to https://stackoverflow.com/questions/17044052/mathplotlib-imshow-complex-2d-array


def colorize(z):
    n, m = z.shape
    c = np.zeros((n, m, 3))
    c[np.isinf(z)] = (1.0, 1.0, 1.0)
    c[np.isnan(z)] = (0.5, 0.5, 0.5)

    idx = ~(np.isinf(z) + np.isnan(z))
    A = (np.angle(z[idx]) + np.pi) / (2*np.pi)
    A = (A + 0.5) % 1.0
github kymatio / kymatio / kymatio / scattering2d / frontend / base_frontend.py View on Github external
def create_filters(self):
        filters = filter_bank(self.M_padded, self.N_padded, self.J, self.L)
        self.phi, self.psi = filters['phi'], filters['psi']