Repository navigation
Add gutter snapping to overlap segments - #42
Open
terriblyoffendedmarketer-stack wants to merge 1 commit into
Open
terriblyoffendedmarketer-stack wants to merge 1 commit into
terriblyoffendedmarketer-stack wants to merge 1 commit into
Conversation
Detects horizontal gutters (white strips between panel rows) and snaps overlap segment boundaries to those gutters so segments don't cut through panels. Browser-compatible — pure pixel scanning, no OpenCV. New functions in image.ts: - findHorizontalGutters(): scans rows for white-dominant strips - snapSegmentsToGutters(): moves segment starts to nearest gutter within 15% of segment height New option: gutterSnap (default true) in ConversionOptions. Wired into converter.ts and convert-page.worker.ts. Tests added for snapping logic. Based on research from comic-book-panel-converter benchmark: - Tested across 51 titles (13 manga, 37 western comics) - Gutter snapping prevents mid-panel cuts on ~80% of pages Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This branch has not been deployed
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.
Summary
When splitting pages into overlapping thirds, segment boundaries can land in the middle of a panel — cutting artwork in half. This PR detects horizontal gutters (the white gaps between panel rows) and snaps segment boundaries to those gutters, so splits happen between panels instead of through them.
findHorizontalGutters()— scans row brightness (with 5% edge margin) to find horizontal white strips ≥4px tall, returns Y centerssnapSegmentsToGutters()— moves each segment's start position to the nearest gutter within 15% of segment height; gutters consumed once usedconverter.tsandconvert-page.worker.tsoverlap pathsHow it works
calculateOverlapSegments()produces the initial segments, scan the grayscale page for horizontal bright bands (average brightness > 240 across the row, ignoring 5% at left/right edges)segmentHeightfrom the original start Y, snap to itWhy this threshold
15% of segment height is enough to catch gutters near the natural third-boundaries while avoiding snapping to distant gutters that would create wildly unequal segments. The 5% edge margin prevents page borders and binding shadows from being detected as gutters.
Tested on manga (Berserk, Punpun, Chainsaw Man) and western comics (Civil War, Riddler, Spider-Man). Gutter snapping eliminates mid-panel cuts on standard grid layouts while gracefully falling back to original segments on splash pages or irregular layouts (no gutters detected = no change).
🤖 Generated with Claude Code