Flow-Based Image Editing
Flow-based image editing reuses a pretrained text-conditioned flow model for tasks it was never trained on. Nothing is retrained. Each method changes only where sampling starts or how predicted velocities are combined. Time runs from (pure noise) to (clean image), and a noisy image is
where is a clean image with pixel values in . Project 3 Part A applies these tools with the PixNerd model at .The one-step estimate extrapolates to the clean image with one velocity, . Euler sampling takes steps with and shortens the last step to end at . All creative applications use the guided velocity with , where uses the prompt and the empty prompt.
Image-to-image editing, inspired by SDEdit, noises a real image to a starting time , , and runs Euler sampling from to . A smaller adds more noise and gives a larger edit. Project 3 uses . Starting from a drawing or painting projects it onto the natural-image manifold. Text-guided editing runs the same procedure with a prompt that describes the change.
Visual anagrams (Geng, Park, Owens, CVPR 2024) make one image that shows prompt upright and prompt upside down. At every Euler step,
where CFG returns the guided velocity and flip rotates the image by (both axes reversed). Hybrid images (Factorized Diffusion) combine frequency bands of two guided velocities,
with the guided velocities for prompts . The low-pass filter is a Gaussian blur with kernel size and pixels.
Time Direction and Guidance Scale
Project 3 and the flow lecture put noise at and the clean image at , so editing integrates forward in . The diffusion slides run the other way, including the lecture’s visual-anagram slide. There is noise, is clean, and the network predicts noise instead of a velocity. 10.3.1. Diffusion Models uses the same diffusion convention. Project 3’s guidance weight relates to the lecture’s CFG scale by . So means , and means plain conditional sampling.
Intuition
A flow model trained on photos knows one operation. Given a noisy image and a time, it predicts which way to move toward a natural image that fits the prompt. Image editing starts this process from a noisy copy of an existing image instead of pure noise. The starting time sets how much of the input survives. At the input and the noise have equal weight, so the model keeps most of the image and cleans up details. At the input has weight against noise of weight . Only large, high-contrast shapes survive, and the model invents everything else. In Project 3’s Campanile sweep, leaves only a pale vertical shape against blue, and the clock face and belfry arches return only at . The name SDEdit refers to the stochastic differential equations of diffusion models. Project 3 runs the same idea with a deterministic flow.
The same view explains projection onto the manifold. A crayon drawing is not a natural image, and the model saw only noisy natural images in training. Noise hides the drawing’s flat colors and hard outlines but keeps its layout and palette. The model treats the result as a noisy photo, so its velocities lead to a realistic image with the drawing’s composition. The figure sketches image space in one dimension. The dotted line is the path from the noise sample to , and is its point at time .
\usepackage{tikz}
\usepackage{amsmath}
\begin{document}
\definecolor{near}{HTML}{2F80ED}
\definecolor{far}{HTML}{D9483B}
\definecolor{mid}{HTML}{8A8A8A}
\begin{tikzpicture}[x=9cm, y=1.3cm, >=latex]
\draw[->, mid] (0,-2.4) -- (1.08,-2.4) node[right, black] {$t$};
\draw[mid] (0,-2.35) -- (0,-2.45) node[below, black] {$0$ (noise)};
\draw[mid] (1,-2.35) -- (1,-2.45) node[below, black] {$1$ (clean)};
\draw[mid] (0.15,-2.35) -- (0.15,-2.45) node[above, far] at (0.15,-2.35) {$t_s = 0.15$};
\draw[mid] (0.6,-2.35) -- (0.6,-2.45) node[above, near] at (0.6,-2.35) {$t_s = 0.6$};
\draw[line width=4pt, mid!45] (1,1.8) -- (1,2.4);
\draw[line width=4pt, mid!45] (1,0.3) -- (1,0.6);
\draw[line width=4pt, mid!45] (1,-1.2) -- (1,-0.8);
\node[mid, align=left, anchor=west] at (1.03,0.6) {\small natural\\ \small images};
\filldraw (0,-1.5) circle (1.5pt) node[left] {$\epsilon$};
\filldraw (1,2.2) circle (1.8pt) node[right] {$x_{\text{orig}}$};
\draw[dotted, thick] (0,-1.5) -- (1,2.2);
\node[rotate=28, mid] at (0.32,0.25) {\small $x_t = (1-t)\,\epsilon + t\,x_{\text{orig}}$};
\filldraw[near] (0.6,0.72) circle (1.8pt) node[below right] {$x_{t_s}$};
\draw[->, thick, near] (0.6,0.72) -- (0.7,1.15) -- (0.8,1.5) -- (0.9,1.8) -- (1,2.0);
\filldraw[near] (1,2.0) circle (1.8pt);
\node[near, anchor=east] at (0.78,1.95) {\small small edit};
\filldraw[far] (0.15,-0.945) circle (1.8pt) node[below right] {$x_{t_s}$};
\draw[->, thick, far] (0.15,-0.945) -- (0.35,-0.7) -- (0.55,-0.75) -- (0.75,-0.9) -- (1,-1.0);
\filldraw[far] (1,-1.0) circle (1.8pt);
\node[far] at (0.62,-1.25) {\small large edit: a different image};
\node[mid] at (0.5,2.75) {\small Euler steps $x_{t+h} = x_t + h\,v_\theta(x_t, t, c)$ from $t_s$ to $1$};
\end{tikzpicture}
\end{document}The lecture frames guidance as sampling from and asks what happens with creative choices of the condition . Its further examples are models trained with new kinds of condition. They generate video from a first frame and audio, depth from video pixels, and in-between frames from a start and an end frame. Others generate new views from an image and a camera pose. The editing methods in this note instead reuse a text-to-image model unchanged.
Properties
(One-Step Estimate Is a Mean) The one-step estimate approximates the average of all clean images consistent with , so it is blurry at small .
Training fits to with squared error, so the ideal model predicts . Solving for gives . Taking the conditional expectation and rearranging gives
At small many clean images fit , and their average is a blur, like the averaged colors in 8.3. Image Colorization. Euler sampling recomputes the velocity after every small step. The set of consistent images shrinks as grows, so the final image stays sharp. Project 3’s comparison of Gaussian blur, the one-step estimate and Euler sampling on the same noisy input shows this difference.
(What Survives Noising) Wide, high-contrast shapes survive at smaller than small, faint details, because noise averages out over large regions.
In the image enters with weight , and the noise has standard deviation per pixel. Averaging the noise over a block of independent pixels divides its standard deviation by . Take a feature of width pixels whose value differs from its surroundings by on the scale. With blocks of size , the feature stands out roughly when exceeds twice the averaged noise, . Solving for gives the rough threshold
Below the threshold the feature is lost in the noise, and the model must regenerate it. The edit keeps what survives and invents the rest.
(Realism Versus Faithfulness) The starting time trades realism of the output against faithfulness to the input, and drawings show the trade-off most clearly.
In Project 3 a house drawing becomes a portrait at and a figure under a peaked shape at to . It returns as a drawing by . A flower drawing becomes a recognizable flower at and returns to flat circles by . At large the noisy input is close to the drawing, and sampling stays near the drawing. The useful range for projection is narrow and depends on the input. Text-guided editing shows the same trade-off. With the prompt “a photograph of a rocket on a launch pad”, the prompt wins at low and the Campanile wins at high . At to the result keeps the tower’s framing with a rocket’s surface.
(Why Flipping Is Allowed) A flipped noisy image is a valid model input at the same time , because a rotation only permutes pixels.
Rotating gives . The rotated noise is again independent per pixel, so the second branch sees an ordinary noisy image at time . Its velocity lives in the rotated frame. Flipping it back moves each prediction to the pixel it belongs to before averaging. The rotation is its own inverse, so one function does both flips. Any view that permutes pixels keeps these properties. A view that blurs or resizes the image changes the noise statistics and breaks the method. The name follows from this. An anagram rearranges letters into a new word, and a visual anagram rearranges pixels into a new picture.
\usepackage{tikz}
\usepackage{amsmath}
\begin{document}
\definecolor{pone}{HTML}{2F80ED}
\definecolor{ptwo}{HTML}{D9483B}
\definecolor{mid}{HTML}{8A8A8A}
\begin{tikzpicture}[>=latex, net/.style={draw, fill=mid!12, rounded corners, align=center, minimum height=0.9cm}]
\draw (0,0) grid[step=0.5] (1,1);
\node at (0.25,0.75) {$a$}; \node at (0.75,0.75) {$b$};
\node at (0.25,0.25) {$c$}; \node at (0.75,0.25) {$d$};
\node at (0.5,1.3) {$x_t$};
\node[net, draw=pone, text=pone] (c1) at (3.6,1.6) {CFG velocity\\ prompt $p_1$};
\draw[->, thick, pone] (1.1,0.6) -- (c1.west);
\node[pone] (v1) at (7.3,1.6) {$v_1$};
\draw[->, thick, pone] (c1) -- (v1);
\draw[->, thick, ptwo] (1.1,0.4) -- (1.9,-1.4);
\node[ptwo, left] at (1.45,-0.6) {\small flip};
\draw[ptwo] (2.0,-2.0) grid[step=0.5] (3.0,-1.0);
\node at (2.25,-1.25) {$d$}; \node at (2.75,-1.25) {$c$};
\node at (2.25,-1.75) {$b$}; \node at (2.75,-1.75) {$a$};
\node[net, draw=ptwo, text=ptwo] (c2) at (4.8,-1.5) {CFG velocity\\ prompt $p_2$};
\draw[->, thick, ptwo] (3.1,-1.5) -- (c2.west);
\node[ptwo] (v2) at (7.3,-1.5) {$v_2$};
\draw[->, thick, ptwo] (c2) -- node[above] {\small flip} (v2);
\node[draw, rounded corners] (avg) at (9.0,0.15) {$v = \tfrac{1}{2}(v_1 + v_2)$};
\draw[->, thick, pone] (v1) -- (avg);
\draw[->, thick, ptwo] (v2) -- (avg);
\node[mid, align=left, anchor=north] at (9.6,-0.4) {\small then Euler step\\ \small $x_{t+h} = x_t + h\,v$};
\end{tikzpicture}
\end{document}(Combining Velocities) Both illusions add velocities, so every Euler step moves the image toward agreement with both prompts.
Averaging gives each prompt half of every step. The image is pulled toward a state where the upright view fits and the rotated view fits . The hybrid method gives each prompt control of one frequency band instead. The low-pass filter is linear, so . With the hybrid method reduces to ordinary guided sampling. With different prompts, sets the coarse layout seen from far away. Prompt sets the fine detail seen up close, as in classical hybrid images. Project 3 warns that both illusions may need several runs before one works well.
(Reading the Blur Parameters) With at , the low-pass band holds patterns of about six cycles or fewer across the image.
A Gaussian with standard deviation pixels has the frequency response , with in cycles per pixel (2.2. Fourier Transform in Images). It falls to one half at . That is a period of about pixels, or cycles across pixels. So controls only patterns with periods longer than about pixels. The kernel size has half-width , so truncating the Gaussian at the kernel edge discards a negligible part of it.
Examples
(Medium) What Survives at Each Starting Time
Model the Campanile in a photo with two features. The tower is about pixels wide and differs from the sky by on the scale. The clock face is about pixels wide with a weaker contrast, . These sizes and contrasts are assumptions chosen for illustration.
Use the threshold to find when each feature survives noising, and compare with Project 3's sweep. How many Euler steps and network evaluations does an edit from take? For the tower, , so at the tower sits right at the threshold. Averaged over a block, the noise has standard deviation . The tower adds a signal of , about twice that. For the clock face, . Project 3 reports the same pattern. At only a pale vertical shape survives, and the clock face returns at . Details below the threshold at small are new inventions of the model.
From with , the remaining time is . The sampler takes full steps to and one shortened step of , so steps in all. Classifier-free guidance evaluates the model twice per step, with the prompt and with the empty prompt. The edit therefore costs network evaluations.
(Hard) Flip Bookkeeping and an Invalid View
Take a toy image. At one step, the guided velocity for on is , and the guided velocity for on is :
(a) Compute , and the Euler update with . (b) A student replaces the rotation with a box blur as the second view. Explain why the method breaks. (a) A rotation reverses both rows and columns, so the top-left entry of moves to the bottom-right. This gives The Euler update adds to . Averaging with directly would mix velocities that were predicted for different pixels.
(b) The model expects noise with variance per pixel. A box blur averages independent noise values with weight each. The noise variance drops to of its value. The blurred input looks like an image at a later time with less noise, so the predicted velocity does not match time . A box blur also removes some frequencies completely, so it has no inverse to map the velocity back. A rotation permutes pixels, which keeps the noise independent with unchanged variance and has an exact inverse.