Generative Visual Manipulation on the Natural Image Manifold

Jun-Yan Zhu, Philipp Krähenbühl, Eli Shechtman, Alexei A. Efros

Introduction

Today, visual communication is sadly one-sided. We all perceive information in the visual form (through photographs, paintings, sculpture, etc.), but only a chosen few are talented enough to effectively express themselves visually. This imbalance manifests itself even in the most mundane tasks. Consider an online shopping scenario: a user looking for shoes has found a pair that mostly suits her but she would like them to be a little taller, or wider, or in a different color. How can she communicate her preference to the shopping website? If the user is also an artist, then a few minutes with an image editing program will allow her to transform the shoe into what she wants, and then use image-based search to find it. However, for most of us, even a simple image manipulation in Photoshop presents insurmountable difficulties. One reason is the lack of “safety wheels” in image editing: any less-than-perfect edit immediately makes the image look completely unrealistic. To put another way, classic visual manipulation paradigm does not prevent the user from “falling off” the manifold of natural images.

Understanding and modeling the natural image manifold has been a long-standing open research problem. But in the last two years, there has been rapid advancement, fueled largely by the development of the generative adversarial networks . In particular, several recent papers have shown visually impressive results sampling random images drawn from the natural image manifold. However, two reasons prevent these advances from being useful in practical applications at this time. First, the generated images, while good, are still not quite photo-realistic (plus there are practical issues in making them high resolution). Second, these generative models are set up to produce images by sampling a latent vector-space, typically at random. So, these methods are not able to create and manipulate visual content in a user-controlled fashion.

In this paper, we use the generative adversarial neural network to learn the manifold of natural images, but we do not employ it for image generation. Instead, we use it as a constraint on the output of various image manipulation operations, to make sure the results lie on the learned manifold at all times. This idea enables us to reformulate several editing operations, specifically color and shape manipulations, in a natural and data-driven way. The model automatically adjusts the output keeping all edits as realistic as possible (Figure 1).

We show three applications based on our system: (1) Manipulating an existing photo based on an underlying generative model to achieve a different look (shape and color); (2) “Generative transformation” of one image to look more like another; (3) Generate a new image from scratch based on user’s scribbles and warping UI.

All manipulations are performed straightforwardly through gradient-based optimization, resulting in a simple and fast image editing tool. We hope that this work inspires further research in data-driven generative image editing, and thus release the code and data at our website.

Prior Work

Image editing and user interaction: Image editing is a well-established area in computer graphics where an input image is manipulated to achieve a certain goal specified by the user. Examples of basic editing include changing the color properties of an image either globally or locally . More advanced editing methods such as image warping or structured image editing intelligently reshuffle the pixels in an image following user’s edits. While achieving impressive results in the hands of an expert, when these types of methods fail, they produce results that look nothing like a real image. Common artifacts include unrealistic colors, exaggerated stretching, obvious repetitions, and over-smoothing. This is because they rely on low-level principles (e.g., the similarity of color, gradients or patches) and do not capture higher-level information about natural images.

Image morphing: There are several techniques for producing a smooth visual transition between two input images. Traditional morphing methods combine an intensity blend with a geometric warp that requires a dense correspondence. In Regenerative Morphing the output sequence is regenerated from small patches sampled from the source images. Thus, each frame is constrained to look similar to the two sources. Exploring Photobios presented an alternative way to transition between images, by finding the shortest path in a large image collection based on pairwise image distances. Here we extend this idea and produce a morph that is both close to the two sources and stays on, or close to, the natural image manifold.

Natural image statistics: Generative models of local image statistics have long been used as a prior for image restoration problems such as image denoising and deblurring. A common strategy is to learn local filter or patch models, such as Principal Components, Independent Components, Mixture of Gaussians or wavelet bases . Some methods attempt to capture full-image likelihoods through dense patch overlap, though the basic building block is still small patches that do not capture global image structures and long-range relations. Zhu et al. recently showed that discriminative deep neural networks learn a much stronger prior that captures both low-level statistics, as well as higher order semantic or color-balance clues. This deep prior can be directly used for a limited set of editing operations (e.g. compositing). However, it does not extend to the diversity of editing operations considered in this work.

Neural generative models: There is a large body of work on neural network based models for image generation. Early classes of probabilistic models of images include restricted Boltzmann machines (e.g., ) and their deep variants , auto-encoders and more recently, stochastic neural networks and deterministic networks . Generative adversarial networks (GAN), proposed by Goodfellow et al. , learn a generative network jointly with a second discriminative adversarial network in a mini-max objective. The discriminator tries to distinguish between the generated samples and natural image samples, while the generator tries to fool the discriminator producing highly realistic looking images. Unfortunately, in practice, GAN does not yield a stable training objective, so several modifications have been proposed recently, such as a multi-scale generation and a convolution-deconvolution architecture with batch normalization . While the above methods attempt to generate an image starting from a random vector, they do not provide tools to change the generation process with intuitive user controls. In this paper, we remedy this by learning a generative model that can be easily controlled via a few intuitive user edits.

Learning the Natural Image Manifold

GAN as a manifold approximation: We use GAN to approximate an ideal manifold for two reasons: first, it produces high-quality samples (see Figure 2 (a) for example). Though lacking visual details sometimes, the model can synthesize appealing samples with a plausible overall structure. Second, the Euclidean distance in the latent space often corresponds to a perceptually meaningful visual similarity (see Figure 2 (b) for examples). Therefore, we argue that GAN is a powerful generative model for modeling the image manifold.

Approach

Figure 1 illustrates the overview of our approach. Given a real photo, we first project it onto our approximation of the image manifold by finding the closest latent feature vector zz of the GAN to the original image. Then, we present a real-time method for gradually and smoothly updating the latent vector zz so that it generates the desired image that both satisfies the user’s edits (e.g., a scribble or a warp; more details in Section 5) and stays close to the natural image manifold. Unfortunately, in this transformation, the generative model usually looses some of the important low-level details of the input image. Therefore, we propose a dense correspondence method that estimates both per-pixel color and shape changes from the edits applied to the generative model. We then transfer these changes to the original photo using an edge-aware interpolation technique and produce the final manipulated result.

Our goal is to reconstruct the original photo xRx^{R} using the generative model GG by minimizing the reconstruction error, where L(x1,x2)=C(x1)C(x2)2\mathcal{L}(x_{1},x_{2})=\|\mathcal{C}(x_{1})-\mathcal{C}(x_{2})\|^{2} in some differentiable feature space C\mathcal{C}. If C(x)=x\mathcal{C}(x)=x, then the reconstruction error is simply pixel-wise Euclidean error. Previous work suggests that using deep neural network activations leads to a reconstruction of perceptually meaningful details. We found that a weighted combination of raw pixels and conv4 features (×0.002\times 0.002) extracted from AlexNet trained on ImageNet to perform best.

Projection via optimization: As both the feature extractor C\mathcal{C} and the generative model GG are differentiable, we can directly optimize the above objective using L-BFGS-B . However, the cascade of C(G(z))\mathcal{C}(G(z)) makes the problem highly non-convex, and as a result, the reconstruction quality strongly relies on a good initialization of zz. We can start from multiple random initializations and output the solution with the minimal cost. However, the number of random initializations required to obtain a stable reconstruction is prohibitively large (more than 100), which makes real-time processing impossible. We instead train a deep neural network to minimize equation 2 directly.

Projection via a feedforward network: We train a feedforward neural network P(x;θP)P(x;\theta_{P}) that directly predicts the latent vector zz from a xx. The training objective for the predictive model PP is written as follows:

where xnRx^{R}_{n} denotes the nn-th image in the dataset. The architecture of the model PP is equivalent to the discriminator DD of the adversarial networks, and only varies in the final number of network outputs. Objective 3 is reminiscent of an auto-encoder pipeline, with a encoder PP and decoder GG. However, the decoder GG is fixed throughout the training. While the optimization problem 2 is the same as the learning objective 3, the learning-based approach often performs better and does not fall into local optima. We attribute this behavior to the regularity in the projection problem and the limited capacity of the network PP. Projections of similar images will share similar network parameters and produce a similar result. In some sense, the loss for one image provides information for many more images that share a similar appearance . However, the learned inversion is not always perfect, and can often be improved further by a few additional steps of optimization.

A hybrid method: The hybrid method takes advantage of both approaches above. Given a real photo xRx^{R}, we first predict P(xR;θP)P(x^{R};\theta_{P}) and then use it as the initialization for the optimization objective (Equation 2). So the learned predictive model serves as a fast bottom-up initialization method for a non-convex optimization problem. Figure 3 shows a comparison of these three methods. See Section 7.4 for a more quantitative evaluation.

2 Manipulating the Latent Vector

where the data term measures deviation from the constraint and the smoothness term enforces moving in small steps on the manifold, so that the image content is not altered too much. We set λs=5\lambda_{s}=5 in our experiments.

Here the last term ED=λDlog(1D(G(z)))E_{D}=\lambda_{D}\cdot\log(1-D(G(z))) optionally captures the visual realism of the generated output as judged by the GAN discriminator DD. This constraint further pushes the image towards the manifold of natural images and slightly improves the visual quality of the result. By default, we turn off this term to increase frame rates.

Gradient descent update: For most constraints Equation 5 is non-convex. We solve it using gradient descent, which allows us to provide the user with a real-time feedback as she manipulates the image. As a result, the objective 5 evolves in real-time as well. For computational reasons, we only perform a few gradient descent updates after changing the constraints vgv_{g}. Each update step takes 5010050-100 ms, which ensures interactive feedback. Figure 4 shows one example of the update of zz. Given an initial red shoe as shown in Figure 4, the user gradually scribbles a black color stroke (i.e., specifies a region is black) on the shoe image (Figure 4 a). Then our update method smoothly changes the image appearance (Figure 4 b) by adding more and more of the user constraints. Once the final result G(z1)G(z_{1}) is computed, a user can see the interpolation sequence between the initial point z0z_{0} and z1z_{1} (Figure 4 c), and select any intermediate result as the new starting point. Please see the supplemental video for more details.

3 Edit Transfer

Give the original photo x0Rx^{R}_{0} (e.g., a black shoe) and its projection on the manifold G(z0)G(z_{0}), and a user modification G(z1)G(z_{1}) by our method (e.g., the generated red shoe). The generated image G(z1)G(z_{1}) captures the roughly change we want, albeit the quality is degraded w.r.t the original image.

Can we instead adjust the original photo and produce a more photo-realistic result x1Rx^{R}_{1} that exhibits the changes in the generated image? A straightforward way is to transfer directly the pixel changes (i.e., x1R=x0R+(G(z1)G(z0))x^{R}_{1}=x^{R}_{0}+(G(z_{1})-G(z_{0})). We tried this approach, and it introduced new artifacts due to the misalignment of the two images. To address this issue, we develop a dense correspondence algorithm to estimate both the geometric and color changes induced by the editing process.

Specifically, given two generated images G(z0)G(z_{0}) and G(z1)G(z_{1}), we can generate any number of intermediate frames \big{[}G((1-\frac{t}{N})\cdot z_{0}+\frac{t}{N}\cdot z_{1})\big{]}_{t=0}^{N}, where consecutive frames only exhibit minor visual variations.

where I(x,y,t)I(x,y,t) denotes the RGB values (r,g,b,1)T(r,g,b,1)^{T} of pixel (x,y)(x,y) in the generated image G((1tN)z0+tNz1)G((1-\frac{t}{N})\cdot z_{0}+\frac{t}{N}\cdot z_{1}). (u,v)(u,v) is the flow vector with respect to the change of tt, and AA denotes a 3×43\times 4 color affine transformation matrix. The data term relaxes the color constancy assumption by introducing a locally affine color transfer model AA while the spatial and color regularization terms encourage smoothness in both the motion and color change. We solve the objective by iteratively estimating the flow (u,v)(u,v) using a traditional optical flow algorithm, and computing the color change AA by solving a system of linear equations . We iterate 33 times. We produce 88 intermediate frames (i.e., N=7N=7).

We estimate the changes between nearby frames, and concatenate these changes frame by frame to obtain long-range changes between any two frames along the interpolation sequence z0z1z_{0}\rightarrow z_{1}. Figure 5 shows a warping sequence after we apply the flow to the initial projection G(z0)G(z_{0}).

Transfer edits to the original photo: After estimating the color and shape changes in the generated image sequence, we apply them to the original photo and produce an interesting transition sequence of photo-realistic images as shown in Figure 5. As the resolution of the flow and color fields are limited to the resolution of the generated image (64×6464\times 64), we upsample those edits using a guided image filter .

User Interface

The user interface consists of the main window showing the current edited photo, a display showing thumbnails of all the candidate results, and a slider bar to explore the interpolation sequence between the original photo and the final result. Please see our supplemental video for more details.

Candidate results: Given the objective (Equation 5) derived with the user guidance, we generate multiple different results by initializing zz as random perturbations of z0z_{0}. We generate 6464 examples and show the best 99 results sorted by the objective cost (Equation 5).

Relative edits: Once a user finishes one edit, she can drag a slider to see all the intermediate results interpolated between the original and the final manipulated photo. We call this “relative edits” as it allows a user to explore more alternatives with a single edit. Similar to relative attributes , a user can express ideas like changing the handle of the handbag to be more red, or making the heel of the shoes slightly higher, without committing to a specific final state.

Our system provides three constraints for editing the photo in different aspects: coloring, sketching and warping. We express all constraints as brush tools. In the following, we explain the usage of each brush and the corresponding constraints.

Coloring brush: The coloring brush allows the user to change the color of a specific region. The user selects a color from a palette and can adjust the brush size. For each pixel marked with this brush we constrain the color fg(I)=Ip=vgf_{g}(I)=I_{p}=v_{g} of a pixel pp to the selected values vgv_{g}.

Sketching brush: The sketching brush allows the user to outline the shape or add fine details. We constrain fg(I)=HOG(I)pf_{g}(I)=HOG(I)_{p} a differentiable HOG descriptor at a certain location pp in the image to be close to the user stroke (i.e. vg=HOG(stroke)pv_{g}=HOG(stroke)_{p}). We chose the HOG feature extractor because it is binned, which makes it robust to sketching inaccuracies.

Warping brush: The warping brush allows the user to modify the shape more explicitly. The user first selects a local region (a window with adjustable size), and then drag it to another location. We then place both a color and sketching constraint on the displaced pixels encouraging the target patch to mimic the appearance of the dragged region.

Figure 8 shows a few examples where we use the coloring and sketching brushed for interactive image generation. Figure 1 shows the result of the warping brush that was used to pull the top line of the shoe up. Figure 6 shows a few more examples.

Implementation Details

Network architecture: We follow the same architecture of deep convolutional generative adversarial networks (DCGAN) . DCGAN mainly builds on multiple convolution, deconvolution and ReLU layers, and eases the min-max training via batch normalization . We train the generator GG to produce a 64×64×364\times 64\times 3 image given a 100100-dimensional random vector. Notice that our method can also use other generative models (e.g. variational auto-encoder or future improvements in this area) to approximate the natural image manifold.

Computational time: We run our system on a Titan X GPU. Each update of the vector zz takes 5010050\sim 100 milliseconds, which allows the real-time image editing and generation. Once an edit is finished, it takes 5105\sim 10 seconds for our edit transfer method to produce high-resolution final result.

Results

We first introduce the statistics of our dataset. We then show three main applications: realistic image manipulation, generative image transformation, and generating a photo from scratch using our brush tools. Finally, we evaluate our image reconstruction methods and perform a human perception study to understand the realism of generated results. Please refer to the supplementary material for more results and comparisons.

Datasets: We experiment with multiple photo collections from various sources as follows: “shoes” dataset , which has 5050K shoes collected from Zappos.com (the shoes are roughly centered, but not well aligned, and roughly facing left, with frontal to side view); “church outdoor” dataset (126126K images) from the LSUN challenge ; “outdoor natural” images (150150K) from the MIT Places dataset ; and two query-based product collections downloaded from Amazon, including “handbags” (138138K) and “shirts” (137137K). The downloaded handbags and shirts are roughly centered but no further alignment has been performed.

Our main application is photo-realistic image manipulation using the brush interactions described in Section 5.1. See Figure 6 for a few examples where the brush edits are depicted on the left (dashed line for the sketch tool, color scribble for the color brush and a red square and an arrow for the warp tool). See the supplementary video for more interactive manipulation demos.

2 Generative Image Transformation

An interesting outcome of the editing process is the sequence of intermediate generated images that can be seen as a new kind of image morphing . We call it “generative transformation”. We use this sequence to transform the shape and color of one image to look like another image automatically, i.e., without any user edits. This manipulation is done by applying the motion+color flow on either of the sources. Figure 7 shows a few “generative transform” examples.

3 Interactive Image Generation

Another byproduct of our method is that if there is no image to begin with and all we have are the user brush strokes, the method would generate a natural image that best satisfies the user constraints. This could be useful for dataset exploration and browsing. The difference with previous sketch-to-image retrieval methods or AverageExplorer is that due to potentially contradicting user constraints, the result may look very different than any single image from the dataset or an average of such images, and more of a realistic hybrid image . See some examples in Figure 8.

4 Evaluation

Image reconstruction evaluation: We evaluate three image reconstruction methods described in Section 4.1: optimization-based, network-based and our hybrid approach that combines the last two. We run these on 500500 test images per category, and evaluate them by the reconstruction error L(x,xR)\mathcal{L}(x,x^{R}) defined in Equation 1. Table 1 shows the mean reconstruction error of these three methods on 55 different datasets. We can see the optimization-based and neural network-based methods perform comparably, where their combination yields better results. See Figure 3 for a qualitative comparison. We include PSNR (in dB) results in the supplementary material.

Class-specific model: So far, we have trained the generative model on a particular class of images. As a comparison, we train a cross-class model on three datasets altogether (i.e. shoes, handbags, and shirts), and observe that the model achieves worse reconstruction error compared to class-specific models (by 10%\sim 10\%). We also have tried to use a class-specific model to reconstruct images from a different class. The mean cross-category reconstruction errors are much worse: shoe model used for shoes: 0.1400.140 vs. shoe model for handbags: 0.3980.398, and for shirts: 0.4510.451. However, we expect a model trained on many categories (e.g. 1,0001,000) to generalize better to novel objects.

Perception study: We perform a small perception study to compare the photorealism of four types of images: real photos, generated samples produced by GAN, our method (shape only), and our method (shape+color). We collect 2020 annotations for 400400 images by asking Amazon Mechanical Turk workers if the images look realistic or not. Real photos: 91.5%91.5\%, DCGAN: 14.3%14.3\%, ours (shape+color): 25.9%25.9\%; ours (shape only): 48.7%48.7\%. DCGAN model alone produces less photo-realistic images, but when combined with our edit transfer, the realism significantly improves.

Discussion and Limitations

We presented a step towards image editing with a direct constraint to stay close to the manifold of real images. We approximate this manifold using the state-of-the-art in deep generative models (DCGAN). We show how to make interactive edits to the generated images and transfer the resulting changes in shape and color back to the original image. Thus, the quality of the generated results (low resolution, missing texture and details) and the types of data that DCGAN applies to (works well on structured datasets such as product images and worse on more general imagery), limits how far we can get with this editing approach. However, our method is not tied to a particular generative model and will improve with the advancement of this field. Our current editing brush tools allow rough changes in color and shape but not texture and more complex structure changes. We leave these for future work.

Acknowledgments This work was supported, in part, by funding from Adobe, eBay, and Intel, as well as a hardware grant from NVIDIA. J.-Y. Zhu is supported by Facebook Graduate Fellowship.

References