Skip to content

Commit 32ad680

Browse files
authored
Enhance inpainting section in index.html
Updated inpainting section with detailed explanation and code.
1 parent 0a654ad commit 32ad680

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

project-5/index.html

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -679,20 +679,24 @@ <h4>Hand Drawn Image 2</h4>
679679
<div class="subsection">
680680
<h3>1.7.2 – Inpainting</h3>
681681

682-
<h4>Code: inpaint function</h4>
683-
<pre><code># TODO
684-
# def inpaint(original_image, mask, prompt_embeds, uncond_prompt_embeds, timesteps, scale=7, ...):
685-
# ...
686-
# return inpainted_image</code></pre>
682+
Using the techniques above, we can also modify our <code>iterative_denoise_cfg</code> function to edit certain sections of an image. To do so, we first define a mask the same size as the image that is 1 at the pixels where we want to edit, and 0 otherwise. For each loop of the denoising process, we replace <code>x<sub>t</sub></code> with <strong>m</strong><code>x<sub>t</sub></code> + (1 - <strong>m</strong>)forward(<code>x<sub>0</sub>, t</code>), where <strong>m</strong> is the mask and <code>x<sub>0</sub></code> is the original image. This can be accomplished by the following code:
683+
684+
<pre><code>masked_image = image * mask + forward(original_image, t).to(device).half() * (1 - mask)</code></pre>
685+
686+
Once <code>image</code> is replaced by <code>masked_image</code>, we replace all further occurences of <code>image</code> except for the last instance, as the image at each step still needs to be updated. Finally, we let our starting noise be purely random and start with an timestamp index of 0, so that the patch we want to change can be sufficiently denoised. Below are the reuslts on the Campanile image:
687687

688688
<h4>Campanile Inpainting</h4>
689689
<div class="image-row">
690690
<figure>
691-
<img src="images/part1_7_campanile_inpaint_mask.png" alt="Campanile inpaint mask" />
692-
<figcaption>Campanile with inpaint mask overlay</figcaption>
691+
<img src="images/campanile.png" alt="campanile.png" />
692+
<figcaption>Original Campanile</figcaption>
693+
</figure>
694+
<figure>
695+
<img src="images/campanile_mask.png" alt="campanile_mask.png" />
696+
<figcaption>Mask</figcaption>
693697
</figure>
694698
<figure>
695-
<img src="images/part1_7_campanile_inpaint_result.png" alt="Campanile inpaint result" />
699+
<img src="images/campanile_inpaint.png" alt="campanile_inpaint.png" />
696700
<figcaption>Inpainted Campanile</figcaption>
697701
</figure>
698702
</div>

0 commit comments

Comments
 (0)