From 9af75de6635b4bfa64155d69bc9d0aad4ef47c11 Mon Sep 17 00:00:00 2001 From: 2ManyProjects Date: Sat, 10 Jan 2026 02:20:04 -0600 Subject: [PATCH] tab --- src/stitching_scanner.py | 102 +++++++++++++++++++-------------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/src/stitching_scanner.py b/src/stitching_scanner.py index 502e54f..1870ef8 100644 --- a/src/stitching_scanner.py +++ b/src/stitching_scanner.py @@ -199,58 +199,58 @@ class StitchingScanner: return result else: # append_left - place at x_offset position - # x_offset represents where camera's LEFT edge is in mosaic coordinates - # For LEFT scanning, we pass abs(current_x) as x_offset - # The strip covers content from x_offset leftward - - if x_offset is None: - x_offset = 0 - - self.log(f"=== _blend_horizontal_at_y (append_left) ===") - self.log(f" base: {w_base}x{h_base}, strip: {w_strip}x{h_strip}") - self.log(f" x_offset (camera left edge): {x_offset}, y_offset: {y_offset}, blend_w: {blend_w}") - - # Result is same size as base (no expansion when going left) - result = base.copy() - - # Strip's RIGHT edge should align with camera's current left edge (x_offset) - # Strip content goes from (x_offset - w_strip + blend_w) to x_offset - strip_x_end = min(x_offset + blend_w, w_base) # Right edge with blend zone - strip_x_start = max(0, strip_x_end - w_strip) - - actual_strip_width = strip_x_end - strip_x_start - - self.log(f" Placing strip at X={strip_x_start}:{strip_x_end}, Y={y_offset}:{y_offset + h_strip}") - self.log(f" Actual strip width: {actual_strip_width}") - - if actual_strip_width <= blend_w: - self.log(f" Strip too narrow, skipping") - return result - - # Step 1: Copy non-blend portion of strip - # Strip's left portion (non-blend) goes at strip_x_start - non_blend_width = actual_strip_width - blend_w - if non_blend_width > 0: - # Take from LEFT side of strip (new content) - result[y_offset:y_offset + h_strip, strip_x_start:strip_x_start + non_blend_width] = strip[:, :non_blend_width] - self.log(f" Step 1: Placed {non_blend_width}px non-blend at X={strip_x_start}:{strip_x_start + non_blend_width}") - - # Step 2: Blend zone at the RIGHT edge of where we're placing - blend_x_start = strip_x_end - blend_w - blend_x_end = strip_x_end - - if blend_w > 0 and blend_x_start >= strip_x_start: - # Alpha: 1 at left (new content) -> 0 at right (existing content) - alpha = np.linspace(1, 0, blend_w, dtype=np.float32)[np.newaxis, :, np.newaxis] - strip_overlap = strip[:, non_blend_width:non_blend_width + blend_w].astype(np.float32) - base_overlap = base[y_offset:y_offset + h_strip, blend_x_start:blend_x_end].astype(np.float32) - blended = (strip_overlap * alpha + base_overlap * (1 - alpha)).astype(np.uint8) + # x_offset represents where camera's LEFT edge is in mosaic coordinates + # For LEFT scanning, we pass abs(current_x) as x_offset + # The strip covers content from x_offset leftward - result[y_offset:y_offset + h_strip, blend_x_start:blend_x_end] = blended - self.log(f" Step 2: Blend zone at X={blend_x_start}:{blend_x_end}") - - self.log(f" Final: Strip placed at X={strip_x_start}:{strip_x_end}, Y={y_offset}") - return result + if x_offset is None: + x_offset = 0 + + self.log(f"=== _blend_horizontal_at_y (append_left) ===") + self.log(f" base: {w_base}x{h_base}, strip: {w_strip}x{h_strip}") + self.log(f" x_offset (camera left edge): {x_offset}, y_offset: {y_offset}, blend_w: {blend_w}") + + # Result is same size as base (no expansion when going left) + result = base.copy() + + # Strip's RIGHT edge should align with camera's current left edge (x_offset) + # Strip content goes from (x_offset - w_strip + blend_w) to x_offset + strip_x_end = min(x_offset + blend_w, w_base) # Right edge with blend zone + strip_x_start = max(0, strip_x_end - w_strip) + + actual_strip_width = strip_x_end - strip_x_start + + self.log(f" Placing strip at X={strip_x_start}:{strip_x_end}, Y={y_offset}:{y_offset + h_strip}") + self.log(f" Actual strip width: {actual_strip_width}") + + if actual_strip_width <= blend_w: + self.log(f" Strip too narrow, skipping") + return result + + # Step 1: Copy non-blend portion of strip + # Strip's left portion (non-blend) goes at strip_x_start + non_blend_width = actual_strip_width - blend_w + if non_blend_width > 0: + # Take from LEFT side of strip (new content) + result[y_offset:y_offset + h_strip, strip_x_start:strip_x_start + non_blend_width] = strip[:, :non_blend_width] + self.log(f" Step 1: Placed {non_blend_width}px non-blend at X={strip_x_start}:{strip_x_start + non_blend_width}") + + # Step 2: Blend zone at the RIGHT edge of where we're placing + blend_x_start = strip_x_end - blend_w + blend_x_end = strip_x_end + + if blend_w > 0 and blend_x_start >= strip_x_start: + # Alpha: 1 at left (new content) -> 0 at right (existing content) + alpha = np.linspace(1, 0, blend_w, dtype=np.float32)[np.newaxis, :, np.newaxis] + strip_overlap = strip[:, non_blend_width:non_blend_width + blend_w].astype(np.float32) + base_overlap = base[y_offset:y_offset + h_strip, blend_x_start:blend_x_end].astype(np.float32) + blended = (strip_overlap * alpha + base_overlap * (1 - alpha)).astype(np.uint8) + + result[y_offset:y_offset + h_strip, blend_x_start:blend_x_end] = blended + self.log(f" Step 2: Blend zone at X={blend_x_start}:{blend_x_end}") + + self.log(f" Final: Strip placed at X={strip_x_start}:{strip_x_end}, Y={y_offset}") + return result def _blend_horizontal(self, base: np.ndarray, strip: np.ndarray, blend_width: int, append_right: bool) -> np.ndarray: