I have a separable function $f[x,y]$, and I would like to find two functions $g[x]$ and $h[y]$ with
$f[x,y]=g[x] h[y]$
where $g[x]$ doesn't depend on $y$ and $h[y]$ doesn't depend on $x$. Ideally, $g$ and $h$ should have the same magnitude, to prevent overflows/underflows. I have a hackish approach that works, but involves a lot of manual labor.
Background: $f[x,y]$ is a filter kernel I want to apply to an image, and using two separate 1d-filters is much more efficient.
My first approach was to start with $g[x]=f[x,0]$. But that doesn't work for e.g. $f[x,y]=\frac{e^{-\frac{x^2+y^2}{2 \sigma ^2}} x y}{2 \pi \sigma ^6}$
Currently, I have a function that "removes" $x$ or $y$ from $f[x,y]$ using pattern matching:
removeSymbol[f_, s_] := f //. {s^_ + a_ -> a, s^_.*a_ -> a}
but that means I have to manually adjust this pattern for different f's.
Is there a more elegant way to do this? $f[x,y]$ is usually a derivative of a gaussian, e.g.
gaussian[x_,y_] := 1/(2 π σ^2) Exp[-((x^2 + y^2)/(2 σ^2))]
f[x_,y_] := D[gaussian[x,y], x, y]
ffunctions. – Mr.Wizard Jul 10 '12 at 14:51GaussianFilter[image,r,{nx,ny}]would work for you? It might be sufficiently fast that you don't need to separate your kernel. – Sjoerd C. de Vries Jul 10 '12 at 14:55D[gaussian[x,y], x],D[gaussian[x,y], x,x,y]and so on – Niki Estner Jul 10 '12 at 14:58GaussianFilterwhen I'm prototyping an algorithm in Mathematica. But I have to build the filter kernels manually when I write the final version in C. – Niki Estner Jul 10 '12 at 14:59