function Gmat = formGmat(g, B) %Usage: Gmat = formGmat(g,B); %Inputs: g is the input image row % B is the kernel size(BxB) % %Output Gmat: The matrix for convolution with image row %g could be row or column vector if (size(g,1)==1) %g is a row vector gp = g; elseif (size(g,2)==1) %g is a column vector gp = g'; else disp('Error: g must be a column or row vector') exit(1); end A = max(size(g,1) ,size(g,2)) ; g_augment = [ gp zeros(1,B-1)]'; for i = 1:B Gmattmp(1:A+B-1,i) = circshift(g_augment,i-1); end Gmat = Gmattmp(B:A,1:B);