PIXELBANKv8.2.1
Menu

Merge Similar Pixels

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

  • 1len(pixels)10001 \leq len(pixels) \leq 1000
  • 0pixels[i]2550 \leq pixels[i] \leq 255
  • 0threshold2550 \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

Test Results

0/0
Run code to see test results.