Blame gdk-pixbuf/pixops/pixbuf-transform-math.ltx

Packit a4058c
\documentclass{article}
Packit a4058c
Packit a4058c
\begin{document}
Packit a4058c
Packit a4058c
\title{Some image transform math}
Packit a4058c
\author{Owen Taylor}
Packit a4058c
\date{18 February 2003}
Packit a4058c
\maketitle
Packit a4058c
Packit a4058c
\section{Basics}
Packit a4058c
Packit a4058c
The transform process is composed of three steps;
Packit a4058c
first we reconstruct a continuous image from the 
Packit a4058c
source data \(A_{i,j}\):
Packit a4058c
\[a(u,v) = \sum_{i = -\infty}^{\infty} \sum_{j = -\infty}^{\infty} A_{i,j}F\left( {u - i \atop v - j} \right) \]
Packit a4058c
Then we transform from destination coordinates to source coordinates:
Packit a4058c
\[b(x,y) = a\left(u(x,y) \atop v(x,y)\right)
Packit a4058c
         = a\left(t_{00}x + t_{01}y + t_{02} \atop t_{10}x + t_{11}y + t_{12} \right)\]
Packit a4058c
Finally, we resample using a sampling function \(G\):
Packit a4058c
\[B_{x_0,y_0} = \int_{-\infty}^{\infty}\int_{-\infty}^{\infty} b(x,y)G\left( {x - x_0 \atop y - y_0} \right) dxdy\]
Packit a4058c
Putting all of these together:
Packit a4058c
\[B_{x_0,y_0} = 
Packit a4058c
\int_{-\infty}^{\infty}\int_{-\infty}^{\infty}
Packit a4058c
\sum_{i = -\infty}^{\infty} \sum_{j = -\infty}^{\infty} A_{i,j}
Packit a4058c
F\left( {u(x,y) - i \atop v(x,y) - j} \right)
Packit a4058c
G\left( {x - x_0 \atop y - y_0} \right) dxdy\]
Packit a4058c
We can reverse the order of the integrals and the sums:
Packit a4058c
\[B_{x_0,y_0} = 
Packit a4058c
\sum_{i = -\infty}^{\infty} \sum_{j = -\infty}^{\infty} A_{i,j}
Packit a4058c
\int_{-\infty}^{\infty}\int_{-\infty}^{\infty}
Packit a4058c
F\left( {u(x,y) - i \atop v(x,y) - j} \right)
Packit a4058c
G\left( {x - x_0 \atop y - y_0} \right) dxdy\]
Packit a4058c
Which shows that the destination pixel values are a linear combination of the 
Packit a4058c
source pixel values. But the coefficents depend on \(x_0\) and \(y_0\). 
Packit a4058c
To simplify this a bit, define:
Packit a4058c
\[i_0 = \lfloor u(x_0,y_0) \rfloor = \lfloor {t_{00}x_0 + t_{01}y_0 + t_{02}} \rfloor \]
Packit a4058c
\[j_0 = \lfloor v(x_0,y_0) \rfloor = \lfloor {t_{10}x_0 + t_{11}y_0 + t_{12}} \rfloor \]
Packit a4058c
\[\Delta_u = u(x_0,y_0) - i_0 = t_{00}x_0 + t_{01}y_0 + t_{02} - \lfloor {t_{00}x_0 + t_{01}y_0 + t_{02}} \rfloor \]
Packit a4058c
\[\Delta_v = v(x_0,y_0) - j_0 = t_{10}x_0 + t_{11}y_0 + t_{12} - \lfloor {t_{10}x_0 + t_{11}y_0 + t_{12}} \rfloor \]
Packit a4058c
Then making the transforms \(x' = x - x_0\), \(y' = y - x_0\), \(i' = i - i_0\), \(j' = j - x_0\)
Packit a4058c
\begin{eqnarray*}
Packit a4058c
F(u,v) & = & F\left( {t_{00}x + t_{01}y + t_{02} - i \atop t_{10}x + t_{11}y + t_{12} - j} \right)\\
Packit a4058c
       & = & F\left( {t_{00}(x'+x_0) + t_{01}(y'+y_0) + t_{02} - (i'+i_0) \atop 
Packit a4058c
                      t_{10}(x'+x_0) + t_{11}(y'+y_0) + t_{12} - (j'+j_0)} \right) \\
Packit a4058c
       & = & F\left( {\Delta_u + t_{00}x' + t_{01}y' - i' \atop 
Packit a4058c
                      \Delta_v + t_{10}x' + t_{11}y' - j'} \right)
Packit a4058c
\end{eqnarray*}
Packit a4058c
Using that, we can then reparameterize the sums and integrals and
Packit a4058c
define coefficients that depend only on \((\Delta_u,\Delta_v)\),
Packit a4058c
which we'll call the \emph{phase} at the point \((x_0,y_0)\):
Packit a4058c
\[
Packit a4058c
B_{x_0,y_0} = 
Packit a4058c
\sum_{i = -\infty}^{\infty} \sum_{j = -\infty}^{\infty} A_{i_0+i,j_0+j} C_{i,j}(\Delta_u,\Delta_v)
Packit a4058c
\]
Packit a4058c
\[
Packit a4058c
C_{i,j}(\Delta_u,\Delta_v) =
Packit a4058c
\int_{-\infty}^{\infty}\int_{-\infty}^{\infty}
Packit a4058c
F\left( {\Delta_u + t_{00}x + t_{01}y - i \atop 
Packit a4058c
         \Delta_v + t_{10}x + t_{11}y - j} \right)
Packit a4058c
G\left( {x \atop y} \right) dxdy
Packit a4058c
\]
Packit a4058c
\section{Separability}
Packit a4058c
A frequent special case is when the reconstruction and sampling functions
Packit a4058c
are of the form:
Packit a4058c
\[F(u,v) = f(u)f(v)\]
Packit a4058c
\[G(x,y) = g(x)g(y)\]
Packit a4058c
If we also have a transform that is purely a scale and translation;
Packit a4058c
(\(t_{10} = 0\), \(t_{01} = 0\)), then we can separate 
Packit a4058c
\(C_{i,j}(\Delta_u,\Delta_v)\) into the product of a \(x\) portion
Packit a4058c
and a \(y\) portion:
Packit a4058c
\[C_{i,j}(\Delta_u,\Delta_v) = c_{i}(\Delta_u) c_{j}(\Delta_v)\]
Packit a4058c
\[c_{i}(\Delta_u) = \int_{-\infty}^{\infty} f(\Delta_u + t_{00}x - i)g(x)dx\]
Packit a4058c
\[c_{j}(\Delta_v) = \int_{-\infty}^{\infty} f(\Delta_v + t_{11}y - j)g(y)dy\]
Packit a4058c
Packit a4058c
\section{Some filters}
Packit a4058c
gdk-pixbuf provides 4 standard filters for scaling, under the names ``NEAREST'',
Packit a4058c
``TILES'', ``BILINEAR'', and ``HYPER''. All of turn out to be separable
Packit a4058c
as discussed in the previous section. 
Packit a4058c
For ``NEAREST'' filter, the reconstruction function is simple replication
Packit a4058c
and the sampling function is a delta function\footnote{A delta function is an infinitely narrow spike, such that:
Packit a4058c
\[\int_{-\infty}^{\infty}\delta(x)f(x) = f(0)\]}:
Packit a4058c
\[f(t) = \cases{1, & if \(0 \le t \le 1\); \cr 
Packit a4058c
                0, & otherwise}\]
Packit a4058c
\[g(t) = \delta(t - 0.5)\]
Packit a4058c
For ``TILES'', the reconstruction function is again replication, but we
Packit a4058c
replace the delta-function for sampling with a box filter:
Packit a4058c
\[f(t) = \cases{1, & if \(0 \le t \le 1\); \cr 
Packit a4058c
                0, & otherwise}\]
Packit a4058c
\[g(t) = \cases{1, & if \(0 \le t \le 1\); \cr 
Packit a4058c
                0, & otherwise}\]
Packit a4058c
The ``HYPER'' filter (in practice, it was originally intended to be 
Packit a4058c
something else) uses bilinear interpolation for reconstruction and
Packit a4058c
a box filter for sampling:
Packit a4058c
\[f(t) = \cases{1 - |t - 0.5|, & if \(-0.5 \le t \le 1.5\); \cr 
Packit a4058c
                0, & otherwise}\]
Packit a4058c
\[g(t) = \cases{1, & if \(0 \le t \le 1\); \cr 
Packit a4058c
                0, & otherwise}\]
Packit a4058c
The ``BILINEAR'' filter is defined in a somewhat more complicated way;
Packit a4058c
the definition depends on the scale factor in the transform (\(t_{00}\)
Packit a4058c
or \(t_{01}]\). In the \(x\) direction, for \(t_{00} < 1\), it is
Packit a4058c
the same as for ``TILES'':
Packit a4058c
\[f_u(t) = \cases{1, & if \(0 \le t \le 1\); \cr 
Packit a4058c
                  0, & otherwise}\]
Packit a4058c
\[g_u(t) = \cases{1, & if \(0 \le t \le 1\); \cr 
Packit a4058c
                  0, & otherwise}\]
Packit a4058c
but for \(t_{10} > 1\), we use bilinear reconstruction and delta-function
Packit a4058c
sampling:
Packit a4058c
\[f_u(t) = \cases{1 - |t - 0.5|, & if \(-0.5 \le t \le 1.5\); \cr 
Packit a4058c
                  0, & otherwise}\]
Packit a4058c
\[g_u(t) = \delta(t - 0.5)\]
Packit a4058c
The behavior in the \(y\) direction depends in the same way on \(t_{11}\).
Packit a4058c
\end{document}