Does Matlab have an off-the-shelf function to generate a 2D circular convolution matrix?

8 visualizaciones (últimos 30 días)
Given a blur kernel B (size: m x n) and the size of a 2D image ( size: h x w ), I am trying to generate a sparse matrix M such that when multiplying the vectorized image (size: hw x 1), it actually performs 2D circular convolution and generate a vectorized filtered image Y (size: hw x 1).
I notice that function
convmxt2
has a similar functionality but the size is not what I want.
  2 comentarios
Rik
Rik el 22 de Sept. de 2020
I doubt this is even mathematically possible for an arbitrary input.
Your title seems to ask a completely unrelated question.
Bruno Luong
Bruno Luong el 22 de Sept. de 2020
Editada: Bruno Luong el 22 de Sept. de 2020
To be sure what you meant by "circular convolution". When people talk about circular, meaning the convolution is wrap-around the head and the tail of the 1D signal, like they live in the clock. In case of 2D it's like your image is defined on a torus (and not a flat image).
If you talk about the kernel that is axisymmetric it's called "radial based" kernel.
If your kenel is separated, meaning the 2D convolution can be equivalently performed by 2 successive 1D convolutions the you can use CONVMTX with KRON. But this is very inefficient way to perform convolution in term of memory and runtime.
If not, you can build such matrix no problem. However you'll get a huge matrix, and it can be dense or sparse depending on your kernel. So you might explain the characteristic of your kernel so we can help you to the right path.

Iniciar sesión para comentar.

Respuestas (1)

Matt J
Matt J el 22 de Sept. de 2020
Editada: Matt J el 22 de Sept. de 2020
You can use func2mat from
Bfourier=fft2(B,h,w);
trunc=@(x)x.*(abs(x)>1e-10); %strip away non-sparse round-off errors
fun=@(X)trunc(ifft2(fft2(X,h,w).*Bfourier));
M=func2mat(fun,zeros(h,w));
but as Bruno mentioned, it may be an inefficient approach if B is separable.

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by