Thursday, 17 December 2015

image processing - Generate the Convolution Matrix of 2D Kernel for Convolution Shape of `same`


I want to find a convolution matrix for a certain 2D kernel $ H $.
For example, for image Img of size $ m \times n $ , I want (in MATALB):



T * Img = reshape(conv2(Img, H, 'same'), [], 1);

Where T is the convolution matrix and same means the Convolution Shape (Output Size) matched the input size.


Theoretically, H should be converted to a toeplitz matrix, I'm using the MATLAB function convmtx2():


T = convmtx2(H, m, n);

Yet T is of size $ (m+2) (n+2) \times (mn) $ as MATLAB's convmtx2 generates a convolution matrix which matches Convolution Shape of full.


Is there a way to generate the Convolution Matrix which matches using conv2() with the same convolution shape parameter?



Answer



I cannot test this on my computer because I do not have the convtmx2 function, here is what the MATLAB help says:



http://www.mathworks.com/help/toolbox/images/ref/convmtx2.html


T = convmtx2(H,m,n) returns the convolution matrix T for the matrix H. If X is an m-by-n matrix, then reshape(T*X(:),size(H)+[m n]-1) is the same as conv2(X,H).


This would get the same resulting convolution of conv2(X,H) but then you would still have to pull out the correct piece of the convolution.


No comments:

Post a Comment

readings - Appending 内 to a company name is read ない or うち?

For example, if I say マイクロソフト内のパートナーシップは強いです, is the 内 here read as うち or ない? Answer 「内」 in the form: 「Proper Noun + 内」 is always read 「ない...