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

6 次查看(过去 30 天)
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 个评论
Rik
Rik 2020-9-22
I doubt this is even mathematically possible for an arbitrary input.
Your title seems to ask a completely unrelated question.
Bruno Luong
Bruno Luong 2020-9-22
编辑:Bruno Luong 2020-9-22
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.

请先登录,再进行评论。

回答(1 个)

Matt J
Matt J 2020-9-22
编辑:Matt J 2020-9-22
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.

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by