PIXELBANKv9.1.0
Menu

Classify a pixel's alpha based on its trimap region.

A trimap is a rough segmentation that divides an image into three regions:

  • Definite Foreground (value 255): α = 1.0 (definitely the subject)
  • Definite Background (value 0): α = 0.0 (definitely not the subject)
  • Unknown (value 128): α = ? (needs estimation, typically near edges)

The trimap provides constraints for matting algorithms:

  • Known regions: directly assign α = 0 or 1
  • Unknown regions: must be estimated using matting algorithms

This function returns the known alpha for definite regions, or None for unknown regions that need further processing.

Example:

Input:
trimap_alpha(255)
Output:
1.0
Reasoning:
  • For trimap_value = 255 (definite foreground):
  • This pixel is marked as definitely belonging to the foreground, so its alpha is known to be 1.0 (fully opaque).

Constraints:

  • trimap_value: integer (0, 128, or 255)
  • Return: 1.0 for foreground (255), 0.0 for background (0), None for unknown (128)
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Trimap Classification - Easy | PixelBank