Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 255 instead of 0 for the initial mask value.
Confusing mask color values.
✗ Incorrect
The mask for inpainting is usually black (0) where no change is needed and white (255) where inpainting is applied. Here, we start with a black mask.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 radius which disables inpainting.
Using too large radius causing blurring.
✗ Incorrect
The radius parameter controls the neighborhood size for inpainting. A small radius like 3 is typical.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using black background causing harsh edges.
Using a single integer instead of a tuple for color.
✗ Incorrect
The new canvas background color is white (255,255,255) to blend well for outpainting.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping inpainting and outpainting masks.
Using the same mask for both regions.
✗ Incorrect
Inpainting mask targets the center region, outpainting mask targets the border region.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same method for both modes.
Passing mode as a variable instead of string.
✗ Incorrect
Use TELEA method for inpainting, NS method for outpainting, and call function with mode 'outpainting'.