Generating Natural Images with Direct Patch Distributions Matching

Ariel Elnekave, Yair Weiss

Introduction

Generating realistic images often relies on a fundamental "patch-based" philosophy: an output image is considered realistic if its local windows (patches) are statistically similar to those found in a real training image. Traditionally, this has been achieved through two primary avenues: nearest-neighbor searches or adversarial training. However, both approaches carry significant trade-offs in terms of computational complexity and stability.

This paper introduces Generative Patch Distribution Matching (GPDM), a training-free algorithm that generates high-quality images by directly matching the statistical distribution of local patches between a source and a target. By utilizing the Sliced Wasserstein Distance (SWD), GPDM achieves results comparable to state-of-the-art Generative Adversarial Networks (GANs) and nearest-neighbor methods, but at a fraction of the computational cost and without the risk of "mode collapse."

The Problem: Efficiency and Diversity

Historically, patch-based synthesis relied on Bidirectional Similarity (BDS). This method requires finding the nearest neighbor for every patch in the generated image, a process that scales quadratically ($O(M^2)$) with the number of patches.

More recently, Single-Image GANs (such as SinGAN) replaced explicit matching with adversarial training. While effective, GANs are notoriously slow—often requiring an hour of training per image—and are prone to instability. Furthermore, they frequently suffer from "mode collapse," where the generator produces only a limited subset of patches, failing to capture the full diversity of the source image. GPDM addresses these issues by asking whether we can explicitly match patch distributions efficiently without the overhead of neural network training.

Methodology

The core of GPDM is the minimization of the Sliced Wasserstein Distance (SWD) via gradient descent directly on image pixels. The process follows three main pillars:

  1. The Multi-Scale Pyramid: GPDM operates from coarse to fine resolutions. It begins with a low-resolution "initial guess" (such as noise or a blurred image) and optimizes it to match the target patch distribution at that scale. The result is then upsampled and used as the starting point for the next resolution level.
  2. The SWD Trick: Calculating the standard Wasserstein (Earth Mover's) distance between high-dimensional patch distributions is computationally expensive ($O(M^{2.5})$). However, for 1D distributions, the distance is trivial to compute by simply sorting the values. SWD leverages this by projecting high-dimensional patches onto random 1D lines, sorting them, and computing the distance in the projected space.
  3. Direct Optimization: Because the sorting operation is differentiable, the authors use standard optimizers like Adam to update pixel values. This approach requires only a few convolutions and a sort operation per iteration, resulting in a complexity of $O(M \log M)$.

Key Insights

Distribution vs. Similarity

One of the paper's critical insights is that ensuring every output patch has a "friend" in the source (similarity) is insufficient for high-quality synthesis. One must also ensure the frequency of those patches matches (distribution). This prevents the algorithm from repeating the same "best" patch multiple times, a common failure mode in nearest-neighbor methods.

Mathematical Rigor

The authors provide mathematical proof that common similarity measures like Bidirectional Similarity (BDS) and Relaxed Earth Mover's Distance (REMD) are not true metrics; they can be zero even when two distributions are significantly different. In contrast, SWD is a true metric—it is zero if and only if the distributions are identical.

Results and Performance

GPDM was evaluated on several generative tasks, including image reshuffling, retargeting, style transfer, and texture synthesis, using datasets like Places50 and SIGD16.

  • Speed: GPDM demonstrates a massive leap in efficiency. For a high-resolution image ($1024 \times 678$), GPDM takes approximately 60 seconds on a GPU. In comparison, GPNN (nearest neighbor) takes ~1900 seconds, and SinGAN requires roughly an hour of training.
  • Quality and Diversity: In reshuffling tests, GPDM achieved lower (better) SIFID scores than SinGAN and comparable scores to GPNN. Crucially, GPDM maintained higher diversity in its outputs compared to GAN-based approaches, effectively avoiding mode collapse.
  • Versatility: The algorithm is highly flexible. By simply changing the initial guess and the target patch distribution, GPDM can handle diverse tasks like changing aspect ratios (retargeting) or transferring artistic styles.

Limitations and Future Work

Despite its advantages, GPDM is not without limitations. As a non-convex optimization method, it can occasionally get stuck in local minima, leading to visual artifacts such as broken structures in complex scenes. Additionally, "perfect" distribution matching can sometimes be a hindrance in image editing tasks where the user intends to change the distribution (e.g., adding an object). The authors propose extensions, such as using masks for weighted patches or "Batched GPDM," to mitigate these issues.

Future research may involve integrating SWD-based patch matching into larger neural architectures, potentially combining the rapid optimization of GPDM with the structural priors inherent in deep learning models.

Summary updated

BibTeX
@inproceedings{elnekave2022generating,
  author = {Ariel Elnekave and Yair Weiss},
  title = {{Generating Natural Images with Direct Patch Distributions Matching}},
  booktitle = {European Conference on Computer Vision},
  year = {2022},
  doi = {10.1007/978-3-031-19790-1\_33},
}
Figure