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

8 ビュー (過去 30 日間)
Lantao Yu
Lantao Yu 2020 年 9 月 21 日
編集済み: Matt J 2020 年 9 月 22 日
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 Center および File ExchangeResizing 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