https://github.com/kostrykin/cnvmats.py
Represent convolution/correlation matrices in Python 2.7 without the need to actually compute them.
https://github.com/kostrykin/cnvmats.py
convolution convolution-matrix correlation-matrix linear-algebra matrices python
Last synced: 4 months ago
JSON representation
Represent convolution/correlation matrices in Python 2.7 without the need to actually compute them.
- Host: GitHub
- URL: https://github.com/kostrykin/cnvmats.py
- Owner: kostrykin
- Created: 2015-05-22T16:15:04.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-04-29T13:55:19.000Z (about 9 years ago)
- Last Synced: 2025-01-02T17:11:57.557Z (5 months ago)
- Topics: convolution, convolution-matrix, correlation-matrix, linear-algebra, matrices, python
- Language: Python
- Homepage:
- Size: 2.18 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# cnvmats.py
This repository contains the `cnvmats` Python 2.7 module. It provides a few classes, whose instances represent convolution and/or correlation matrices, as `A` and `X` in `Ax = Xa = a*x`, respectively. Besides of being multiplied with NumPy arrays, the matrices `A` and `X` can be **transposed** using their `.T` property.
The matrices are instantiated by the `cnvmats.cnvmat` and `cnvmats.cnvmat_tp` functions. Both have a `mode` argument that must be set to either `cnvmats.VALID`, `cnvmats.FULL` or `cnvmats.CIRC`. The convolution is implemented in frequency domain. The point is that the object that `cnvmats.cnvmat` returns **never actually computes the whole matrix**, unless it is told to do so using its `toarray` method.
Here is a simple example that loads an image and applies a box-filter:
```python
import numpy as np
import cv2
import cnvmatssa = (30,30)
x = cv2.imread('lena.png', 0)
a = np.ones(sa) / np.prod(sa)
A = cnvmat(a, x.shape, 'valid')
y = A * x
```The `cnvmats_test.py` file contains tests and further examples.

The above image was generated by the `cnvmats_show.py` script.
Dependencies:
- Python 2.7
- NumPy 1.7 or later