Author: eric2i

  • Image Abstraction using Layer-wise Image Vectorization

    LIVE is a solid research work released in June 2022 (accepted by CVPR 2022 oral) regarding image vectorization, the reverse process of image rasterization, which is also an important problem in Computer Graphics.

    At the end of my Digital Image Processing course, I  used this algorithm to generate a vectorized version of my selfie! It is also possible to create a short video to demonstrate the process of this algorithm.

    A vectorized version of my selfie with path=64.

    Besides simple context, LIVE can also be adapted to complex scenic images, such as the following photo I took at the Beijing University of Chemical Technology (BUCT).

    A vectorized version of one BUCT campus image with path=256.
  • Magnetic Field Intensity Around a Uniformly Carrying Cylindrical Surface

    In general, by utilizing Ampère’s Circuital Law, it is straightforward to derive the formula for the magnetic induction intensity around a uniformly current-carrying cylindrical surface, except on the surface of the cylinder itself:

    $$B(r)=\begin{cases}
    0 & if 0 < r < R \\
    \frac{\mu_0 I}{2\pi r} & if r > R \\
    \end{cases}$$

    For the case where \(r=R\), Ampère’s Circuital Law cannot compute the value.

    Instead, we use the Biot-Savart Law, treating the infinitely long cylindrical surface as an infinite straight current. The surrounding field strength formula is then:

    $$B(r)=\frac{\mu_0 I}{2\pi d} $$

    where \(i=\frac{ds}{2\pi R}I\).

    It is intuitive to place the research point on the cylindrical surface at the coordinate origin and use polar coordinates to rewrite the equation. Given that:

    $$ds = \sqrt{\rho^2 + \rho^{‘2}} = 2R\theta$$

    $$d=\rho$$

    Thus, the differential magnetic field \(dB\) is given by:

    $$dB = \frac{\mu_0 I}{4\pi^2 R}d\theta$$

    Integrating from \(-\pi/2\) to \(\pi/2\), we find:

    $$B = \int_{-\pi/2}^{\pi/2}\frac{\mu_0 I}{4\pi^2 R}d\theta = \frac{\mu_0 I}{4\pi R}$$

     

  • Theory of Linear Regression

    Give a dataset $\mathcal{D} = \{(\mathbf{x}, y) | \mathbf{x} \in R^d, y \in R \}$, we can build a *linear* model to *predict* $y$ (label) given only $\mathbf{x}$ (features).

    Formally, a linear model can be written as $\hat{y} = f(x) = \mathbf{x}^T\beta$, where $\beta$ is parameter vector that we can tune and $\hat{y}$ is our prediction.

    To evaluate how good our prediction is, an intuitive and simple metric is squared error: $|y-\hat{y}|^2$.

    If the size of the dataset $|D| = 1$, we can directly find an optimal parameter vector that allows zero error by solving a linear equation!

    $$
    |y-\hat{y}|^2 = 0 \Rightarrow y = \hat{y} \Rightarrow \mathbf{x}^T\beta = y
    $$

    which can be written as:

    $$
    x_1\beta_1 + x_2\beta_2 + \cdots + x_d\beta_d = y
    $$

    where $d$ is the number of dimension of vector $\mathbf{x}$.

    With non-trivial vector $\mathbf{x}$(i.e., $\exists x_i \neq 0$), we can always find a $\beta$ to satisfy the equation above.

    In practice, the size of dataset $\mathcal{D}$ can be arbitrarily large, and in most cases, we can no longer find optimal $\beta$ by solving equations! (A simple example is that the number of distinct equations can be as large as the size of the dataset and even more than the number of unknown variables, which leads to no solution at all in most cases.) However, we can still optimize something we care about statistically!

    The mean squared error (MSE), which evaluates the statistical quality of the linear model, can be written as:

    $$
    \mathcal{L}_{\beta} = \sum_{(\mathbf{x}, y)\in\mathcal{D}}{|y-f(\mathbf{x})|^2} = ||X\beta – \mathcal{y}||^2_2
    $$

    where $\mathcal{L}_\beta$ is the notation for **loss** (intuitively quantifies the distance between prediction and reality, here MSE is a simple yet effective implementation), $X = [\mathbf{x}_1, \cdots, \mathbf{x}_{|D|}]$ and $\mathcal{y} = [y_1, \cdots, y_{|D|}]$, and the subindex $\beta$ denotes our tunable parameters, $||\cdot||_2$ is the L-2 norm.

    Is it possible to find a good enough parameter vector $\beta$ to reduce the loss $\mathcal{L}$? The answer is yes. What’s more, we can find a closed-form solution to vector $\beta$ to minimize the loss $\mathcal{L}$.

    $$
    min_{\beta}||X\beta-\mathcal{y}||^2_2 \Rightarrow \hat{\beta} = (X^TX)^{-1}X^T\mathbf{y}
    $$

    **Proof:**

    Rewrite the objective,

    $$
    \mathcal{L} = ||X\beta-\mathcal{y}||^2_2 = (X\beta-\mathcal{y})^T(X\beta-\mathcal{y}) = (\beta^TX^T-y^T)(X\beta-y) = \beta^TX^TX\beta-2y^TX\beta + y^Ty.
    $$

    Take gradient w.r.t $\beta$,

    $$
    \nabla_{\beta}\mathcal{L}(\beta) = 2X^TX\beta – 2X^Ty
    $$

    Set gradient to zero (first-order optimality condition):

    $$
    2X^TX\beta – 2X^Ty = 0 \Rightarrow 2X^TX\beta = 2X^Ty
    $$

    Assume $X^TX$ is invertible, then

    $$
    \hat{\beta} = (X^TX)^{-1}X^T\mathbf{y}
    $$