Skip to content

Fix findOutline4 emitting interior mask pixels as outline pixels - #81

Draft
rootkiller6788 wants to merge 1 commit into
facebookresearch:mainfrom
rootkiller6788:fix/findOutline4-outline-pixel-self-check
Draft

Fix findOutline4 emitting interior mask pixels as outline pixels#81
rootkiller6788 wants to merge 1 commit into
facebookresearch:mainfrom
rootkiller6788:fix/findOutline4-outline-pixel-self-check

Conversation

@rootkiller6788

Copy link
Copy Markdown

Problem

MaskAnalyzer::findOutline4 (impl/ocean/cv/segmentation/MaskAnalyzer.cpp) documents its result as: "the pixel itself is not a mask pixel but has at least one neighbor mask pixel in the four-neighborhood" (see MaskAnalyzer.h).

However, the center-rows pass only checked the four-neighborhood of each pixel:

if (maskRow[x - 1u] != nonMaskValue || maskRow[x + 1u] != nonMaskValue || maskRowTop[x] != nonMaskValue || maskRowBottom[x] != nonMaskValue)
{
    outlinePixels4.emplace_back(x, y);
}

It never verified that the pixel itself is a non-mask pixel. As a result, every interior mask pixel that has at least one mask neighbor is incorrectly reported as an outline pixel, so outlinePixels4 contains the full mask interior in addition to the true outline.

Fix

Gate the check on the pixel being a non-mask pixel, matching the top/bottom row and left/right column passes already present in the same function:

if (maskRow[x] == nonMaskValue && (maskRow[x - 1u] != nonMaskValue || maskRow[x + 1u] != nonMaskValue || maskRowTop[x] != nonMaskValue || maskRowBottom[x] != nonMaskValue))
{
    outlinePixels4.emplace_back(x, y);
}

Verification

  • Confirmed the header documentation (MaskAnalyzer.h:459) defines outline-4 pixels as non-mask pixels with a mask neighbor.
  • Confirmed the top-center (line 373/383) and bottom-center (line 513/523) passes already use the maskRow[x] != nonMaskValue / else structure, i.e. they correctly skip mask pixels.
  • Traced a concrete counterexample: a fully-mask 3x3 frame produces an outline entry for the interior pixel (1,1), which is a mask pixel and must not be an outline pixel.

The center-rows pass of MaskAnalyzer::findOutline4 only checked the
four-neighborhood of each pixel, without first verifying that the pixel
itself is a non-mask pixel. As a result every interior mask pixel having
at least one mask neighbor was incorrectly added to outlinePixels4,
contradicting the documented behavior that an outline pixel is a
non-mask pixel with a mask neighbor in the four-neighborhood. Gate the
check on maskRow[x] == nonMaskValue, matching the top/bottom row and
left/right column passes of the same function.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant