Simonxie's Workshop

Multi-Resolution Image Blending

2024/09/23
loading

UC-Berkeley 24FA CV Project 2:
Fun with Sobel, Gaussian Filters and Image Pyramids/Stacks; Blend Images by Band-Pass Filters.

Roadmap

This project involves three parts:

  1. Image Derivatives
  2. Image Filtering & Hybrid: A Reproduction of Paper (SIGGRAPH 2006)
  3. Multi-Resolution Blending: A Reproduction of Paper

Part I: Image Derivatives

Finite Difference Operators

  1. The simplest way to compute derivatives on images is by convolving the image with finite difference operators (FODs). Take \(D_x = \begin{bmatrix}1 & -1 \end{bmatrix}\) as an example, for each pixel in the resulting image (excepting those on the edge), they are equal to the original pixel minus its neighbor to the right. This operator is hence sensitive to vertical gradients.

    Similarly, \(D_y = \begin{bmatrix}1 \\ -1 \end{bmatrix}\) is sensitive to horizontal gradients.

  2. Here is an example of convolving the image with FOD operator:

  3. Furthermore, we can binarize the image. An appropriate threshold will filter all the edges from this gradient image.

  4. Here is an example of binarizing the gradient image:

    Details: Suppose pixel \(\in [0, 1]\).

    The threshold is np.logical_or(im > 0.57, im < 0.43)

Derivative of Gaussian Filter

  1. From the upper result, we notice that it's rather noisy. This is usually introduced by those high-frequency components in the image, which doesn't contribute to edges but literally causes a change in gradient. Hence, we introduce Gaussian Filters to get rid of those noises.

  2. Here is an example of implementing Gaussian Filters before calculating image gradients:

    The threshold is: np.logical_or(im > 0.52, im < 0.42)

  3. As the difference, implementing Gaussian filters can remove those sparkling noises in the picture. (Especially for the lawn, the effect is obvious). However, the tradeoff is that some edges are weakened. Take a look at those houses further away, their edges are simply omitted because there isn't a strong gradient at all.

  4. Since convolution operation is commutative, i.e. \[ Img * Gaus * D_x = Img * (Gaus * D_x) \] we can introduce Derivative of Gaussian Filter, defined as \(Gaus * D_x\) or \(Gaus * D_y\). We can verify that convolving the image with Gaus & Dx is equivalent to convolving it with DoG filter.

Part II: Image Filtering

A Reproduction of Paper (SIGGRAPH 2006)

Image Sharpening

  1. By Furrier Transform, we can observe that Gaussian Filter is essentially a Low-Pass Filter. Therefore, if we subtract the low-frequency component of an image from its original version, we can get those High-Frequency Components, which includes all edges, textures, etc.

  2. We may blend these high frequency components with the original image itself by formula \(a * Image + (1-a) * HighFreq\). This will implement the process of Image Sharpening

  3. For evaluation, we will also blur the image first, and then sharpen it again to see what will happen. Here are some results:

    From the results, we may observe that sharpening may make the image look "sharper", but doesn't actually bring all the tiny textures back. Also, this may introduce reconstruction errors, where some lines seems thicker than their original version, which is introduced by gaussian filters.

    This is because that the gaussian filters have already removed high-frequency components from the picture. If we re-sharpen it, we are actually enhancing the high-frequency components of the blurry image, which is not the high-frequency component of the original image. Hence error is introduced.

Hybrid Images

  1. Here is a fun fact about frequency: High frequency of the signal may dominate perception when you are close to a image, but only low frequency of signal can be seen at a distance.

  2. Hence, we may come up with some cool ideas: what about blending the high frequency of one signal with the low frequency of another signal, to get a image that look like A seeing from a distance but seems like B seeing closely?

  3. From previous sections, we have already known how to extract the high/low frequency components from a image. Hence, lets blend them together!

  4. Here are some results:

  5. More Results

  6. Failure Result Example

    Explanation: It's a "perceptual" failure. In our cognition, the surface texture of the bread is not like a steak's, while the steak's color isn't yellow as well. Hence they don't "blend" together very well. Also, the HP Filter is not good at extracting the tiny textures on the steak. This also contributed to failure.

Part III: Multi-Resolution Blending

A Reproduction of Paper

Intuitive: if we simply implement alpha-blending on images, the results will look strange with unnatural transitions. How can we come up with a method to blend them together better?

image-20240923142418940

Gaussian and Laplacian Stacks

  1. First, we introduce the Gaussian and Laplacian stack. This is to represent the image's different frequency components in a hierarchal way. For each level of image, we blur it and push it into stack.

    Image cited from CS180 FA24, UC Berkeley, Alexei Efros.

Multi-Resolution Blending

  1. Here are some results (Gaussian Stacks & Laplacian Stacks):

  2. Also, for the convenience of blending, we also implement a Gaussian Stack on a mask.

  3. Everything has been prepared! We may simply blend images together, according to the mask value.

    And here comes the juicy ora-pple! (Need to collapse the Laplacian Stack by adding all layers together)

  4. Here are some of more results:

    Sun-Moon:

    Coca-Pepsi:

CATALOG
  1. 1. Roadmap
  2. 2. Part I: Image Derivatives
    1. 2.1. Finite Difference Operators
    2. 2.2. Derivative of Gaussian Filter
  3. 3. Part II: Image Filtering
    1. 3.1. Image Sharpening
    2. 3.2. Hybrid Images
  4. 4. Part III: Multi-Resolution Blending
    1. 4.1. Gaussian and Laplacian Stacks
    2. 4.2. Multi-Resolution Blending