feat(compact_mask): add resize() method and benchmark stage#2227
Draft
feat(compact_mask): add resize() method and benchmark stage#2227
resize() method and benchmark stage#2227Conversation
- Add CompactMask.resize(new_image_shape) — scales RLE crops, offsets, and image_shape to an arbitrary target resolution via per-crop decode → cv2.INTER_NEAREST → re-encode; identity fast path avoids all decoding - Add 16 parametrized tests covering identity, halve/double, empty N=0, invalid dimensions, non-square scale, zero-extent edge case, dense-parity roundtrip (1-px tolerance) - Add stage_resize to benchmark: times resize-to-half vs numpy linspace dense path; adds Resize column to summary table and CSV output --- Co-authored-by: Claude Code <noreply@anthropic.com>
Codecov Report❌ Patch coverage is ❌ Your project check has failed because the head coverage (78%) is below the target coverage (95%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #2227 +/- ##
========================================
Coverage 77% 78%
========================================
Files 66 66
Lines 8211 8338 +127
========================================
+ Hits 6350 6469 +119
- Misses 1861 1869 +8 🚀 New features to boost your workflow:
|
- Vectorise all coordinate arithmetic (no Python loop over N masks); offsets and crop shapes computed with np.clip/round in one shot - All-False crops skip decode/resize entirely (single False-run output) - Parallel decode/resize/encode via ThreadPoolExecutor for N ≥ 8 - Add _rle_resize(): direct RLE manipulation without 2D array allocation; uses floor(dst*src/dst_size) — bit-exact with cv2.INTER_NEAREST; caches per-source-row scaled runs (O(1) for repeated rows in upscale) - Dispatch in resize(): _rle_resize for sparse masks (run density < 0.25); cv2 path retained for dense masks - 35 new parametrized tests; cv2 parity verified across 20 random seeds --- Co-authored-by: Claude Code <noreply@anthropic.com>
- Split _rle_resize into three focused helpers: _rle_split_rows (flat RLE → per-row run lists), _rle_scale_row (horizontal nearest-neighbour scale via precomputed column map), _rle_join_rows (concatenate rows, merging same-parity runs at junctions) - Extract _resize_one closure from resize() into module-level _resize_crop (all-False → L3 → cv2 dispatch); remove local cv2 import from resize() - Move _L3_DENSITY_THRESHOLD to module level with explanatory comment --- Co-authored-by: Claude Code <noreply@anthropic.com>
- Add tests for independent axis scaling, extreme ratios, and large crops. - Parameterize for prime-sized, asymmetric, and single-axis crops. - Increase random seeds in dense parity and cv2 rounding tolerance checks. - Adjust `_rle_resize` parity checks to allow 1-pixel differences.
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.
This pull request adds a new
resizemethod to theCompactMaskclass, enabling efficient resizing of masks to arbitrary resolutions with nearest-neighbor interpolation. The benchmark and summary reporting code is updated to include timing and correctness checks for the new operation, and a comprehensive suite of tests is provided to ensure correctness and robustness of the resize logic.CompactMask resize implementation and tests:
resizemethod toCompactMask, which rescales masks, offsets, and crop shapes to a new image size using nearest-neighbor interpolation and updates the internal RLE encoding. The method handles identity, empty, and invalid-resize cases efficiently and raises an error for non-positive dimensions.TestCompactMaskResizewith extensive parameterized and property-based tests covering proportional scaling, identity, empty masks, invalid shapes, non-square scaling, extreme downscaling, and pixel-level parity with OpenCV's resizing.Benchmark and reporting updates:
stage_resizetiming and correctness check in the benchmark, using the newresizemethod and a dense mask baseline, with 1-pixel tolerance for correctness. Integrated these metrics into scenario results and reporting. [1] [2] [3] [4] [5]Internal utilities:
_resize_dense_to_shapeas a utility for resizing dense masks using numpy fancy-indexing, to serve as a baseline for correctness and timing comparisons.These changes ensure that
CompactMasksupports robust and efficient resizing, with full test coverage and integration into benchmarking and reporting workflows.