Import RLE segmentation masks as outlines - #1868
Open
mattdawkins wants to merge 2 commits into
Open
Conversation
DIVE stores geometry rather than rasters, so a decoded mask becomes its contour. Both counts spellings are read, the list form and the LEB128 string pycocotools writes; an undecodable mask still warns.
opencv is only a dev dependency, so the deployed server has numpy alone. Moore-neighbour tracing walks the boundary instead, which costs the perimeter rather than the area.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
COCO RLE masks were skipped on import with a warning, so masks from kwcoco and pycocotools — where RLE is the default mask encoding — were lost.
DIVE features store GeoJSON geometry, not rasters (
rleMaskexists only on the transient segmentation-service response, not the persisted schema), so a decoded mask is traced to its outline and imported as a polygon, the same shape a polygon segmentation takes today._decode_rle_countsreads both COCO spellings: the uncompressed list of run lengths, and the LEB128 string pycocotools writes_rle_polygon_coordsrebuilds the mask column-major (the COCO order), traces it withcv2.findContours, and returns image-space contours, largest firstRETR_EXTERNAL— since a DIVE polygon cannot express themThe LEB128 decoder is checked against pycocotools' own
rleToStringalgorithm reimplemented in the test, so it is verified against real encoder output rather than a fixture I wrote to match my decoder. Both spellings decode the same 6x6 square tox 3..8, y 2..7.Server/web import only. The desktop importer still skips RLE and shows the warning: it has no opencv, so contour tracing there means hand-writing a tracer in TypeScript, which is a bigger change and not something I can test in this checkout. Flagged in the docs so the asymmetry is visible.
One pre-existing test changed:
test_import_missing_bbox_raises_descriptive_errorasserted the old error wording. The behaviour is identical — an undecodable mask with no bbox still raises — only the message now says an RLE mask supplies bounds when it can be decoded.46 server tests pass locally. Not run: vitest, eslint, tsc — no
node_moduleshere, though this PR touches no client code.