2
$\begingroup$

I am trying to decompose a Sobel filter into two vectors (column and a row) using Matlab.

If our Sobel filter is

A = [1 0 -1; 2 0 -2; 1 0 -1]

we can get the U, S, V matrices in Matlab with

[U, S, V] = svd(A)

Which returns

U =

   -0.4082    0.9129   -0.0000
   -0.8165   -0.3651   -0.4472
   -0.4082   -0.1826    0.8944


S =

    3.4641         0         0
         0    0.0000         0
         0         0         0


V =

   -0.7071   -0.7071         0
         0         0   -1.0000
    0.7071   -0.7071         0

Now, according to How to Decompose a Separable Filter?, our row and column vectors should be

sqrt(3.4641)*u1 and sqrt(3.464)*v1.'

but these operations do not return the answer, which should be

[1; 2; 1] and [1 0 -1]

$\endgroup$
6
$\begingroup$

The decomposition of a separable filter is not unique, since $u v' = (u a) (v a^{-1})'$

The solution you are expecting is found by using a $-\sqrt{2}$ factor, namely -U(:,1) .* S(1,1) ./ sqrt(2) and -sqrt(2)*V(:,1).

$\endgroup$
3
$\begingroup$

The SVD solution is a bit of an overkill. If a matrix is a product of two vectors, it shall be of rank one (or less, but that is trivial then). Therefore, the matrix should have at least self-evident vector on rows OR on columns. Here, due to the integer entries, $[1,\,2,\,1]$ or $[-1,\,0,\,1]$ easily pop-up. And once one is chosen, the other follows easily. Here are other SE.DSP posts on this topic:

As already said by @Bob, the decomposition is not unique. Why not $[3,\,6,\,3]$ or $[2,\,0,\,-2]$? Possibly because of some subconscious notion of simplicity. And this notion can be complicated.

Indeed, because of rounding errors, floating point, a matrix is rarely of rank one, at least numerically. A little $1e^{-17}$ can break a rank one matrix. Therefore, there still are works on appropriately telling whether a matrix is separable (wrt errors), and the question may involved quite complex optimization issues, see: Nonconvex Matrix Factorization from Rank-One Measurements, or the 2021 preprint Rank-one matrix estimation: analytic time evolution of gradient descent dynamics.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.