Giter Site home page Giter Site logo

separate_kernel's Introduction

Separate 2D convolution kernels

Separating a 2D kernel (matrix M) into two 1D kernels (column vector C and row vector R) allows for faster execution of the convolution operation.

Here is an example of a 2D kernel separated into two 1D kernels: Plot

Installation

  • Clone the repository
  • Go to the root level of the repository (where setup.py is located)
  • Execute pip install .

How to use it

Example of how to use the package:

import numpy as np

from separate_kernel import separate_kernel

M = np.array([[1, 2, 1], [2, 4, 2], [1, 2, 1]])
res = separate_kernel(M, symmetric_kernel=True)

print(f'1st 1D filter: {res.col_vec.flatten()}.T')
print(f'2nd 1D filter: {res.row_vec.flatten()}')
print(f'Multiplying 1st and 2nd 1D filter gives original 2D filter:')
print(res.col_vec @ res.row_vec)

This outputs:

1st 1D filter: [1. 2. 1.].T
2nd 1D filter: [1. 2. 1.]
Multiplying 1st and 2nd 1D filter gives original 2D filter:
[[1. 2. 1.]
 [2. 4. 2.]
 [1. 2. 1.]]

Notes

For a 2D kernel to be separable the rank of the matrix M must be 1. For a separable kernel the equation M = C * R holds. The method uses nonlinear least squares to minimize the residuals C * R - M. Therefore, even if a kernel can not be perfectly separated, still an approximation will be output.

Also, SVD could be used to compute C and R, as in the case of separability there is only one nonzero singular value and the corresponding singular vectors represent (scaled versions of) C and R.

separate_kernel's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.