Skip to content

Represent convolution/correlation matrices in Python 2.7 without the need to actually compute them.

Notifications You must be signed in to change notification settings

kostrykin/cnvmats.py

Repository files navigation

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:

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

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

Dependencies:

  • Python 2.7
  • NumPy 1.7 or later

About

Represent convolution/correlation matrices in Python 2.7 without the need to actually compute them.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages