PIXELBANKv9.1.0
Menu

Region Growing Segmentation

Given a 2D grayscale image, a list of seed positions, and a threshold T, perform region growing segmentation.

Algorithm:

  1. Each seed starts a new region with a unique label (1, 2, 3, ...)
  2. For each region, maintain a growing queue (BFS)
  3. A neighboring pixel (4-connected) is added to the region if:
    • It is not yet labeled
    • ∣pixel_intensity−region_mean∣<T|\text{pixel\_intensity} - \text{region\_mean}| < T (strictly less than)
  4. Update the region mean as pixels are added
  5. Pixels not claimed by any region remain 0

Return the labeled image.

Example:

Input:
image = [[10, 12, 50], [11, 13, 55], [52, 54, 53]]
seeds = [(0, 0), (0, 2)]
T = 5
Output:
[[1, 1, 2], [1, 1, 0], [0, 0, 0]]
Reasoning:
  • The algorithm starts with two seeds at positions (0, 0) and (0, 2) with initial labels 1 and 2, respectively. The region mean for label 1 is 10 and for label 2 is 50.
  • The neighboring pixels of the seed (0, 0) are checked: the pixel to the right has an intensity of 12, which satisfies ∣12−10∣<5|12 - 10| < 5, so it's added to region 1 and the region mean is updated to (10+12)/2=11(10 + 12) / 2 = 11.
  • The pixel below the seed (0, 0) has an intensity of 11, which satisfies ∣11−11∣<5|11 - 11| < 5, so it's also added to region 1, and the region mean is updated to (10+12+11)/3=11(10 + 12 + 11) / 3 = 11.
  • The algorithm continues, but no other pixels satisfy the condition for either region, especially since the threshold T=5T = 5 is not met for the pixels near the seed (0, 2) to expand into the lower-right part of the image, resulting in the given output.

Constraints:

  • image is a 2D list of numeric intensities
  • seeds is a list of (row, col) tuples
  • T is a positive threshold
  • Use 4-connectivity
  • Region mean updates as pixels are added
  • Return 2D labeled list
🔒

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.
Region Growing Segmentation - Medium | PixelBank