Edit and resort image to fix flaws or remove unwanted objects from an image.

Inpainting refers to the process of restoring or repairing an image by filling in missing or damaged parts. It is a valuable technique widely used in image editing and restoration, enabling the removal of flaws and unwanted objects to achieve a seamless and natural-looking final image. Inpainting finds applications in film restoration, photo editing, and digital art, among others.

Init Image

Output Image

Here is a Python example for inpainting. The Image Gen API call will take mask_image (right) and init_image (middle) as shown below.

Init Image

Inpainting Mask

Python
1import requests
2import json
3import os
4import base64
5import time
6import io
7import PIL.Image
8
9def _process_test(url):
10 image = PIL.Image.open("dog.jpg")
11 mask = PIL.Image.open("dogmask.jpg")
12
13 # Create a BytesIO buffer to hold the image data
14 image_buffer = io.BytesIO()
15 image.save(image_buffer, format='JPEG')
16 image_bytes = image_buffer.getvalue()
17 encoded_image = base64.b64encode(image_bytes).decode('utf-8')
18
19 # Create a BytesIO buffer to hold the image data
20 mask_buffer = io.BytesIO()
21 mask.save(mask_buffer, format='JPEG')
22 mask_bytes = mask_buffer.getvalue()
23 encoded_mask = base64.b64encode(mask_bytes).decode('utf-8')
24
25 OCTOAI_TOKEN = os.environ.get("OCTOAI_TOKEN")
26
27 payload = {
28 "prompt": "Face of a yellow cat, high resolution, sitting on a park bench",
29 "negative_prompt": "Blurry photo, distortion, low-res, bad quality",
30 "steps": 4,
31 "width": 1024,
32 "height": 1024,
33 "cfg_scale": 1.4,
34 "checkpoint": "octoai:lcm_sdxl",
35 "init_image": encoded_image,
36 "mask_image": encoded_mask
37 }
38 headers = {
39 "Authorization": f"Bearer {OCTOAI_TOKEN}",
40 "Content-Type": "application/json",
41 "X-OctoAI-Queue-Dispatch": "true"
42 }
43
44 response = requests.post(url, headers=headers, json=payload)
45
46 if response.status_code != 200:
47 print(response.text)
48 print(response.json())
49
50 img_list = response.json()["images"]
51
52 for i, img_info in enumerate(img_list):
53 img_bytes = base64.b64decode(img_info["image_b64"])
54 img = PIL.Image.open(io.BytesIO(img_bytes))
55 img.load()
56 img.save(f"result_image{i}.jpg")
57
58if __name__ == "__main__":
59 _process_test("https://image.octoai.run/generate/sdxl")
Output Image