Does Matlab have an off-the-shelf function to generate a 2D circular convolution matrix?
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Rik
il 22 Set 2020
I doubt this is even mathematically possible for an arbitrary input.
Your title seems to ask a completely unrelated question.
Bruno Luong
il 22 Set 2020
Modificato: Bruno Luong
il 22 Set 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.
Risposte (1)
Matt J
il 22 Set 2020
Modificato: Matt J
il 22 Set 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.
0 Commenti
Vedere anche
Categorie
Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!