Separable kernel constituent vectors
GPU image processing operations can often be renderered substantially faster when using a separable kernel. Separable kernels are the result of tensor product between constituent vectors and have rank 1. The constituent vectors can be found by singular value decomposition, anyway in this article we’ll present an alternative approach.
The key observation is that all their rows and columns are multiple of the constituent vectors i.e. all of their elements are of the form \( m_{i,j} = a_i k \) where \( k \) is a multiplicative constant for the row or the column being considered.
\[v_1 \left[ \begin{array}{ccc} 3\\4\\1 \end{array} \right] \bigotimes v_2 \left[ \begin{array}{ccc} 2&8&3 \end{array} \right] = m \left[ \begin{array}{ccc} 6&24&9\\ 8&32&12\\ 2&8&3 \end{array} \right]\]The first step in reconstructing the constituent vectors is therefore to find
the greatest common divisor
in a row (the same reasoning will apply for columns). Dividing all elements by
the gcd
will reduce them in the form \( a_i \).
After performing the same computations for columns an additional observation has to be made: we’re searching constituent vectors for the original known matrix, that means we’re interested in having \( x_i \cdot y_j = m_{i,j}\). In a case like the following the algorithm we’re using won’t work
\[v_1 \left[ \begin{array}{ccc} 6\\12 \end{array} \right] \bigotimes v_2 \left[ \begin{array}{ccc} 6&27 \end{array} \right] = m \left[ \begin{array}{ccc} 36&72\\ 162&324 \end{array} \right]\]since it will yield
\[v_1 \left[ \begin{array}{ccc} 1\\2 \end{array} \right] v_2 \left[ \begin{array}{ccc} 2&9 \end{array} \right]\]a scale factor of \( \frac{m_{i,j}}{x_i \cdot y_j} \) is needed on one of the constituent candidates.
Finally the python algorithm to compute the constituent vectors follows
Constituent vectors found:
v1: [ 2.16840434e-19 7.36113251e-19 2.00096327e-18 4.35535655e-18
7.59099013e-18 1.05940801e-17 1.18390866e-17 1.05940801e-17
7.59099013e-18 4.35535655e-18 2.00096327e-18 7.36113251e-19
2.16840434e-19]
v2: [ 5.41466909e+15 1.83813027e+16 4.99655611e+16 1.08756536e+17
1.89552745e+17 2.64542166e+17 2.95630915e+17 2.64542166e+17
1.89552745e+17 1.08756536e+17 4.99655611e+16 1.83813027e+16
5.41466909e+15]