All notes
ImageProc

# Concepts

## Interlacing

Interlacing
Interlacing (also known as interleaving) is a method of encoding a bitmap image such that a person who has partially received it sees a degraded copy of the entire image.
When communicating over a slow communications link, it helps the viewer decide more quickly whether to abort or continue the transmission.
• GIF interlacing stores the lines in the order 0, 8, 16, ...(8n), 4, 12, ...(8n+4), 2, 6, 10, 14, ...(4n+2), 1, 3, 5, 7, 9, ...(2n+1).
• PNG uses the Adam7 algorithm, which interlaces in both the vertical and horizontal direction.
• TGA uses two optional interlacing algorithms, two-way: 0, 2, 4, ...(2n), 1, 3, ...(2n+1) and four-way: 0, 4, 8, ...(4n), 1, 5, ...(4n+1), 2, 6, ...(4n+2), 3, 7, ...(4n+3).
• JPEG, JPEG 2000, and JPEG XR (actually using a frequency decomposition hierarchy rather than interlacing of pixel values)
• PGF (also using a frequency decomposition)

Interlacing has been criticized because it may not be clear to viewers when the image has finished rendering, unlike non-interlaced rendering (such as progressive scan, in which the loaded image is decoded line for line), where progress is apparent (remaining data appears as blank).

The practice is much less common today, as common broadband internet connections allow most images to be downloaded to the user's screen nearly instantaneously.

Wikipedia: Interlaced video. Interlaced video is a technique for doubling the perceived frame rate of a video display without consuming extra bandwidth. The interlaced signal contains two fields of a video frame captured at two different times. This enhances motion perception to the viewer, and reduces flicker by taking advantage of the phi phenomenon.

# Linear operators

A linear shift-invariant operator $K$ is

• linear: $K(\lambda I)=\lambda K(I)$
• shift-invariant: $K(shift(I))=shift(K(I))$
• any linear shift-invariant operation is equivalent to a convolution.
Examples include smoothing, differentiation.

• Wikipedia. An example of a gradient filter to use is
-1
1

However this will shift the image by half a pixel. The following filter
-1
0
1

is more commonly used and does not shift the image.
• CIS. However, this method is sensitive to noise and small fluctuations in image luminance. The effect of noise can be reduced by averaging the gradient calculations over the orthogonal direction, such as the following operators: Roberts, Prewit, .etc.

### Roberts

Wikipedia. $$\begin{bmatrix} +1 & 0 \\ 0 & -1\\ \end{bmatrix} \quad \mbox{and} \quad \begin{bmatrix} 0 & +1 \\ -1 & 0 \\ \end{bmatrix}.$$

### Prewit

Wikipedia. $$\mathbf{G_x} = 1/3 \begin{bmatrix} -1 & 0 & +1 \\ -1 & 0 & +1 \\ -1 & 0 & +1 \end{bmatrix} * \mathbf{A} \quad \mbox{and} \quad \mathbf{G_y} = 1/3 \begin{bmatrix} -1 & -1 & -1 \\ 0 & 0 & 0 \\ +1 & +1 & +1 \end{bmatrix} * \mathbf{A}$$

$$\begin{bmatrix} -1 & 0 & +1 \\ -1 & 0 & +1 \\ -1 & 0 & +1 \end{bmatrix} = \begin{bmatrix} 1\\ 1\\ 1 \end{bmatrix} \begin{bmatrix} -1 & 0 & 1 \end{bmatrix}$$

### sobel

Wikipedia. $$\mathbf{G}_y = 1/4 \begin{bmatrix} -1 & -2 & -1 \\ 0 & 0 & 0 \\ +1 & +2 & +1 \end{bmatrix} * \mathbf{A} \quad \mbox{and} \quad \mathbf{G}_x = 1/4 \begin{bmatrix} -1 & 0 & +1 \\ -2 & 0 & +2 \\ -1 & 0 & +1 \end{bmatrix} * \mathbf{A}$$ where * here denotes the 2-dimensional convolution operation. $$\begin{bmatrix} -1 & 0 & +1 \\ -2 & 0 & +2 \\ -1 & 0 & +1 \end{bmatrix} = \begin{bmatrix} 1\\ 2\\ 1 \end{bmatrix} \begin{bmatrix} -1 & 0 & +1 \end{bmatrix}$$

### Frei-Chen

CIS. $$\mathbf{G}_y = \frac{1}{(2+\sqrt 2)} \begin{bmatrix} -1 & -\sqrt 2 & -1 \\ 0 & 0 & 0 \\ +1 & +\sqrt 2 & +1 \end{bmatrix} * \mathbf{A} \quad \mbox{and} \quad \mathbf{G}_x = \frac{1}{(2+\sqrt 2)} \begin{bmatrix} -1 & 0 & +1 \\ -\sqrt 2 & 0 & +\sqrt 2 \\ -1 & 0 & +1 \end{bmatrix} * \mathbf{A}$$

$$\nabla f=\frac{\partial f}{\partial x}\hat x + \frac{\partial f}{\partial y}\hat y$$ where:

• $\textstyle\frac{\partial f}{\partial x}$ is the gradient in the x direction
• $\textstyle\frac{\partial f}{\partial y}$ is the gradient in the y direction.
• $\hat x$ and $\hat y$ are the unit vectors in x and y direction.
The gradient direction can be calculated by the formula : $\theta = \operatorname{atan2} \left( \frac{\partial f}{\partial y} , \frac{\partial f}{\partial x}\right)$.

Another representation: $$\nabla f = \langle f_x, f_y, f_z \rangle$$

A vector field $V$ defined on a set $S$ is called a gradient field or a conservative field if there exists a real-valued function (a scalar field) $f$ on $S$ such that $$V = \nabla f = \bigg(\frac{\partial f}{\partial x_1}, \frac{\partial f}{\partial x_2}, \frac{\partial f}{\partial x_3}, \dots ,\frac{\partial f}{\partial x_n}\bigg)$$ The associated flow is called the gradient flow, and is used in the method of gradient descent.
The path integral along any closed curve $\gamma (\gamma(0) = \gamma(1))$ in a conservative field is zero: $$\oint_\gamma \langle V(x), \mathrm{d}x \rangle = \oint_\gamma \langle \nabla f(x), \mathrm{d}x \rangle = f(\gamma(1)) - f(\gamma(0))$$ where the angular brackets and comma: $\langle$, $\rangle$ denotes the inner product of two vectors (or the integrand V(x) is a 1-form rather than a vector in the elementary sense).