PIXELBANKv9.1.0
Menu

Problem Statement

In image segmentation, adjacent pixels with similar intensities are often merged into the same region.

Given a list of pixel values and a list of edges (i, j) indicating which pixels are adjacent, merge pixels into groups where the absolute intensity difference is at most threshold.

Return the number of distinct groups after merging.

Applications

  • Region-based segmentation
  • Color quantization
  • Superpixel generation

Constraints

  • 1≤len(pixels)≤10001 \leq len(pixels) \leq 1000
  • 0≤pixels[i]≤2550 \leq pixels[i] \leq 255
  • 0≤threshold≤2550 \leq threshold \leq 255

Example:

Input:
pixels = [10, 12, 50, 52], edges = [[0,1], [1,2], [2,3]], threshold = 5
Output:
2
Reasoning:

Pixels 0,1 merge (diff=2). Pixels 2,3 merge (diff=2). But 1,2 don't merge (diff=38>5).

🔒

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.
Merge Similar Pixels - Medium | PixelBank