0
0
Prompt Engineering / GenAIml~10 mins

Inpainting and outpainting in Prompt Engineering / GenAI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to load an image and prepare a mask for inpainting.

Prompt Engineering / GenAI
from PIL import Image
image = Image.open('input.jpg')
mask = Image.new('L', image.size, [1])
Drag options to blanks, or click blank then click option'
A0
B255
C128
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 255 instead of 0 for the initial mask value.
Confusing mask color values.
2fill in blank
medium

Complete the code to apply inpainting using OpenCV.

Prompt Engineering / GenAI
import cv2
image = cv2.imread('input.jpg')
mask = cv2.imread('mask.png', 0)
inpainted = cv2.inpaint(image, mask, [1], cv2.INPAINT_TELEA)
Drag options to blanks, or click blank then click option'
A10
B0
C3
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 radius which disables inpainting.
Using too large radius causing blurring.
3fill in blank
hard

Fix the error in the code to perform outpainting by extending the image canvas.

Prompt Engineering / GenAI
import numpy as np
from PIL import Image
image = Image.open('input.jpg')
width, height = image.size
new_width = width + 100
new_height = height + 50
new_image = Image.new('RGB', (new_width, new_height), [1])
new_image.paste(image, (50, 25))
Drag options to blanks, or click blank then click option'
A(255, 0, 0)
B(0, 0, 0)
C(128, 128, 128)
D(255, 255, 255)
Attempts:
3 left
💡 Hint
Common Mistakes
Using black background causing harsh edges.
Using a single integer instead of a tuple for color.
4fill in blank
hard

Fill both blanks to create a mask dictionary for inpainting and outpainting regions.

Prompt Engineering / GenAI
masks = {
    'inpainting': [1],
    'outpainting': [2]
}
Drag options to blanks, or click blank then click option'
A{'region': 'center', 'mask': mask_inpaint}
B{'region': 'border', 'mask': mask_outpaint}
C{'region': 'edges', 'mask': mask_outpaint}
D{'region': 'center', 'mask': mask_outpaint}
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping inpainting and outpainting masks.
Using the same mask for both regions.
5fill in blank
hard

Fill all three blanks to define a function that applies inpainting or outpainting based on mode.

Prompt Engineering / GenAI
def apply_painting(image, mask, mode):
    if mode == 'inpainting':
        method = [1]
    elif mode == 'outpainting':
        method = [2]
    else:
        raise ValueError('Invalid mode')
    return cv2.inpaint(image, mask, 3, method)  # radius fixed at 3

result = apply_painting(img, mask, [3])
Drag options to blanks, or click blank then click option'
Acv2.INPAINT_TELEA
Bcv2.INPAINT_NS
C'inpainting'
D'outpainting'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same method for both modes.
Passing mode as a variable instead of string.