Bird
Raised Fist0
Computer Visionml~8 mins

Image inpainting concept in Computer Vision - Model Metrics & Evaluation

Choose your learning style10 modes available
Metrics & Evaluation - Image inpainting concept
Which metric matters for Image Inpainting and WHY

Image inpainting means filling missing parts of an image so it looks natural. To check how well the model fills these gaps, we use metrics that compare the filled image to the original complete image.

Common metrics include:

  • PSNR (Peak Signal-to-Noise Ratio): Measures how close the filled image is to the original. Higher PSNR means better quality.
  • SSIM (Structural Similarity Index): Checks if the structure and textures look similar. Values closer to 1 mean the images are very alike.
  • L1 or L2 Loss: Measures pixel differences. Lower values mean the inpainted area is closer to the original.

These metrics matter because they tell us if the model is realistically restoring missing parts, not just guessing random pixels.

Confusion Matrix or Equivalent Visualization

Image inpainting is not a classification task, so it does not use a confusion matrix. Instead, we visualize results by comparing images side-by-side:

Original Image       Masked Image (with holes)       Inpainted Image
[Complete photo]     [Photo with missing parts]      [Model fills missing parts]

We also use difference images showing pixel errors:
Difference = |Original - Inpainted|
Lower difference means better inpainting.
    
Precision vs Recall Tradeoff (Equivalent for Image Inpainting)

In image inpainting, the tradeoff is between:

  • Detail preservation: Keeping fine textures and edges sharp.
  • Smoothness and consistency: Avoiding unnatural artifacts or noise.

If the model focuses too much on smoothness, it may blur details (low detail precision). If it tries to keep all details, it may create strange artifacts (low consistency recall).

Good inpainting balances these, producing images that look natural and detailed.

What "Good" vs "Bad" Metric Values Look Like
  • PSNR: Good values are usually above 30 dB, meaning the inpainted image is very close to original. Below 20 dB is poor quality.
  • SSIM: Values close to 1 (like 0.9 or above) show strong similarity. Values below 0.7 indicate poor structural match.
  • L1/L2 Loss: Lower is better. Good models have small pixel errors, bad models have large differences.

Visually, good inpainting looks seamless and natural. Bad inpainting shows blurry, patchy, or obviously fake areas.

Common Metrics Pitfalls
  • Relying only on PSNR or SSIM: These metrics may not capture perceptual quality well. An image can have good PSNR but look unnatural.
  • Ignoring visual inspection: Human eyes are good at spotting fake areas, so always check images visually.
  • Overfitting: Model may memorize training images and produce good metrics but fail on new images.
  • Data leakage: Using test images in training can give falsely high metrics.
Self-Check Question

Your image inpainting model shows a PSNR of 35 dB but the filled areas look blurry and unnatural. Is this model good?

Answer: Not necessarily. High PSNR means pixel values are close, but blurriness shows the model may be averaging pixels and losing details. You should also check SSIM and visual quality to confirm.

Key Result
PSNR and SSIM are key metrics to measure how well the inpainted image matches the original in quality and structure.

Practice

(1/5)
1. What is the main purpose of image inpainting in computer vision?
easy
A. To fill missing or damaged parts of an image
B. To increase the resolution of an image
C. To classify objects in an image
D. To detect edges in an image

Solution

  1. Step 1: Understand image inpainting definition

    Image inpainting is a technique used to restore or fill missing or damaged parts of an image.
  2. Step 2: Compare options with definition

    Only To fill missing or damaged parts of an image matches the purpose of filling missing or damaged parts, while others describe different tasks.
  3. Final Answer:

    To fill missing or damaged parts of an image -> Option A
  4. Quick Check:

    Image inpainting = fill missing parts [OK]
Hint: Remember: inpainting means filling gaps in images [OK]
Common Mistakes:
  • Confusing inpainting with image classification
  • Thinking it increases image resolution
  • Mixing it up with edge detection
2. Which of the following is the correct way to represent a mask for image inpainting?
easy
A. A binary image where 1 indicates missing pixels and 0 indicates known pixels
B. A color image with random colors
C. A text file describing image pixels
D. A grayscale image where white pixels mark missing areas

Solution

  1. Step 1: Understand mask role in inpainting

    The mask guides the model where to fill missing parts, usually as a binary image.
  2. Step 2: Identify correct mask format

    A binary image where 1 indicates missing pixels and 0 indicates known pixels correctly describes a binary mask with 1 for missing and 0 for known pixels.
  3. Final Answer:

    A binary image where 1 indicates missing pixels and 0 indicates known pixels -> Option A
  4. Quick Check:

    Mask = binary image marking missing areas [OK]
Hint: Mask uses 1 for missing, 0 for known pixels [OK]
Common Mistakes:
  • Thinking mask is a color image
  • Assuming mask is a text file
  • Confusing grayscale with binary mask
3. Given this Python snippet for image inpainting using OpenCV:
import cv2
image = cv2.imread('photo.jpg')
mask = cv2.imread('mask.png', 0)
inpainted = cv2.inpaint(image, mask, 3, cv2.INPAINT_TELEA)
print(inpainted.shape)

What will be the output if photo.jpg is 640x480 pixels with 3 color channels?
medium
A. (640, 480, 3)
B. (480, 640, 3)
C. (480, 640)
D. (640, 480)

Solution

  1. Step 1: Understand image shape format in OpenCV

    OpenCV images have shape (height, width, channels). For 640x480, height=480, width=640.
  2. Step 2: Confirm inpainted image shape

    Inpainting returns an image of same size and channels as input, so shape is (480, 640, 3).
  3. Final Answer:

    (480, 640, 3) -> Option B
  4. Quick Check:

    OpenCV shape = (height, width, channels) [OK]
Hint: OpenCV shape order is height, width, channels [OK]
Common Mistakes:
  • Swapping width and height in shape
  • Ignoring color channels in output
  • Assuming grayscale output
4. You run this code but get an error:
import cv2
image = cv2.imread('photo.jpg')
mask = cv2.imread('mask.png')
inpainted = cv2.inpaint(image, mask, 3, cv2.INPAINT_NS)

What is the likely cause of the error?
medium
A. Inpaint radius is too large
B. Image file path is incorrect
C. Using wrong inpainting method
D. Mask image is not loaded as a single channel (grayscale)

Solution

  1. Step 1: Check mask loading method

    The mask must be loaded as grayscale (single channel) for inpainting, but code loads it as color by default.
  2. Step 2: Identify cause of error

    Passing a 3-channel mask causes cv2.inpaint to fail, so loading mask with flag 0 is needed.
  3. Final Answer:

    Mask image is not loaded as a single channel (grayscale) -> Option D
  4. Quick Check:

    Mask must be grayscale for inpainting [OK]
Hint: Load mask with cv2.imread('mask.png', 0) [OK]
Common Mistakes:
  • Loading mask as color image
  • Ignoring file path errors
  • Changing inpainting method unnecessarily
5. You want to remove a small object from a photo using image inpainting. Which steps should you follow?
hard
A. Crop the image to exclude the object
B. Blur the entire image to hide the object
C. Create a binary mask marking the object, then apply inpainting with that mask
D. Convert the image to grayscale and apply thresholding

Solution

  1. Step 1: Mark the object with a mask

    Create a binary mask where the object pixels are 1 (missing) and others 0 (known).
  2. Step 2: Apply inpainting using the mask

    Use an inpainting algorithm with the mask to fill the object area with surrounding pixels.
  3. Final Answer:

    Create a binary mask marking the object, then apply inpainting with that mask -> Option C
  4. Quick Check:

    Mask object + inpaint = object removal [OK]
Hint: Mask object area before inpainting to remove it [OK]
Common Mistakes:
  • Blurring instead of inpainting
  • Cropping loses image context
  • Thresholding unrelated to object removal
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard