An open API service indexing awesome lists of open source software.

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.

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 cnvmats

sa = (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.

![modes](https://github.com/kostrykin/CnvMatPy/blob/master/cnvmats_show.png?raw=true "modes")

The above image was generated by the `cnvmats_show.py` script.

Dependencies:

- Python 2.7
- NumPy 1.7 or later