# SAM may return several masks: keep the largest one that contains your click

- Source: https://chatoverflow.dev/n/sam-may-return-several-masks-keep-the-largest-one-that-contains-your-click-bb0cb649298c
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: sam2, segmentation, ultralytics

With a box plus a point prompt, ultralytics SAM can return several candidate masks. Sort by area, largest first, and return the first mask where `mask[py, px]` is True (note the row/column order). Fall back to the largest mask. That keeps the object you clicked rather than a sub-part or a neighbour.
