Feature Request: General λ-connected (lambda-connected) segmentation (beyond flood_fill())
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.4k
- Forks
- 1k
- Avg merge
- 22h 17m
- Merged PRs (30d)
- 3
Description
Title: Feature Request: General λ-connected (lambda-connected) segmentation
Summary
Both cv2.floodFill() and skimage.segmentation.flood()/flood_fill() implement region-growing using a purely local, pairwise similarity rule — a pixel is added if it differs from an already-included neighbor by less than a fixed tolerance. This is fast and simple, but it inherits a well-known weakness: gradient leakage. A smooth intensity gradient can chain together pixels that are locally similar at every step but globally very different, causing the region to "leak" past intended boundaries.
Proposed addition
Implement λ-connected segmentation, a formal generalization of region-growing based on fuzzy connectedness theory. Instead of a local pairwise test, connectivity between two pixels is defined by the strongest path between them — specifically, the maximum over all paths of the minimum pairwise similarity along that path (a max-min / bottleneck-path formulation). Two pixels are λ-connected if this path strength is ≥ λ.
Why this is a natural fit
• It's a strict generalization: setting λ's degree function to a simple local threshold and ignoring the path constraint collapses back to today's flood_fill() behavior — so it wouldn't replace existing functionality, only extend it.
• It directly addresses flood-fill's most common failure mode (leakage through gradients) without requiring users to switch to a heavier method like GrabCut or a full DL segmentation model.
• Efficient implementation is well understood: this is equivalent to a maximum-capacity/bottleneck shortest-path problem, solvable with a Dijkstra-like or Kruskal-like (max-spanning-forest) approach in effectively linear-ish time for practical image sizes — no need for iterative PDE solvers.
• It would sit naturally alongside existing skimage.segmentation tools (flood, watershed, random_walker, chan_vese) as another region-growing option, giving users a controlled way to compare "naive" vs. "leak-resistant" region growing on the same image.
• Related lambda-connectedness methods already have precedent in imaging toolkits (e.g., Leadtools lambda-connectedness segmentation), so this isn't an unprecedented ask — it would bring scikit-image/OpenCV's region-growing toolbox to parity with a well-established technique in medical/scientific imaging.
python
cv2.segmentation.lambda_connected(image, seed, lam, connectivity=1, degree_func='intensity_diff')
Returns a boolean mask, mirroring flood()'s existing interface for easy comparison in the same script.
References
• L. Chen, Cheng, H.D. and Zhang, J., 1994. Fuzzy subfiber and its application to seismic lithology classification. Information Sciences-Applications, 1(2), pp.77-95.
• L. Chen, "The lambda-connected segmentation and the optimal algorithm for split-and-merge segmentation," Chinese J. Computers, Vol. 14, pp. 321–331, 1991.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing cv2.floodFill() and skimage flood/flood_fill() interfaces, then determine whether this segmentation feature belongs in the opencv-python packaging repository or upstream OpenCV. Done would require an agreed lambda-connected API, implementation scope, and validation that it returns the proposed boolean mask without replacing existing flood-fill behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- computer-vision
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100