This commit is contained in:
2ManyProjects 2026-01-08 00:49:02 -06:00
parent baf0f2a782
commit 961e828adc

View file

@ -196,50 +196,56 @@ class StitchingScanner:
result[:, w_strip - blend_w:w_strip] = blended result[:, w_strip - blend_w:w_strip] = blended
result[:, w_strip:] = base[:, blend_w:] result[:, w_strip:] = base[:, blend_w:]
return result return result
def _blend_vertical_at_x(self, base: np.ndarray, strip: np.ndarray, def _blend_vertical_at_x(self, base: np.ndarray, strip: np.ndarray,
blend_height: int, append_below: bool) -> np.ndarray: blend_height: int, append_below: bool,
x_offset: int = 0) -> np.ndarray:
mh, mw = base.shape[:2] mh, mw = base.shape[:2]
sh, sw = strip.shape[:2] sh, sw = strip.shape[:2]
# Match widths # Clamp x_offset to valid range
if sw > mw: x_offset = max(0, min(x_offset, mw - 1))
strip = strip[:, :mw]
elif sw < mw:
pad = np.zeros((sh, mw - sw, 3), dtype=np.uint8)
strip = np.hstack([strip, pad])
# Calculate how much of strip fits in mosaic
available_width = mw - x_offset
strip_width = min(sw, available_width)
# Create full-width strip with strip placed at x_offset
full_strip = np.zeros((sh, mw, 3), dtype=np.uint8)
full_strip[:, x_offset:x_offset + strip_width] = strip[:, :strip_width]
# Now blend using existing logic
blend_h = min(blend_height, sh, mh) blend_h = min(blend_height, sh, mh)
if blend_h <= 0: if blend_h <= 0:
if append_below: if append_below:
return np.vstack([base, strip]) return np.vstack([base, full_strip])
return np.vstack([strip, base]) return np.vstack([full_strip, base])
if append_below: if append_below:
alpha = np.linspace(1, 0, blend_h, dtype=np.float32)[:, np.newaxis, np.newaxis] alpha = np.linspace(1, 0, blend_h, dtype=np.float32)[:, np.newaxis, np.newaxis]
base_overlap = base[-blend_h:].astype(np.float32) base_overlap = base[-blend_h:].astype(np.float32)
strip_overlap = strip[:blend_h].astype(np.float32) strip_overlap = full_strip[:blend_h].astype(np.float32)
blended = (base_overlap * alpha + strip_overlap * (1 - alpha)).astype(np.uint8) blended = (base_overlap * alpha + strip_overlap * (1 - alpha)).astype(np.uint8)
result_h = mh + sh - blend_h result_h = mh + sh - blend_h
result = np.zeros((result_h, mw, 3), dtype=np.uint8) result = np.zeros((result_h, mw, 3), dtype=np.uint8)
result[:mh - blend_h] = base[:-blend_h] result[:mh - blend_h] = base[:-blend_h]
result[mh - blend_h:mh] = blended result[mh - blend_h:mh] = blended
result[mh:] = strip[blend_h:] result[mh:] = full_strip[blend_h:]
return result return result
else: else:
alpha = np.linspace(0, 1, blend_h, dtype=np.float32)[:, np.newaxis, np.newaxis] alpha = np.linspace(0, 1, blend_h, dtype=np.float32)[:, np.newaxis, np.newaxis]
strip_overlap = strip[-blend_h:].astype(np.float32) strip_overlap = full_strip[-blend_h:].astype(np.float32)
base_overlap = base[:blend_h].astype(np.float32) base_overlap = base[:blend_h].astype(np.float32)
blended = (strip_overlap * (1 - alpha) + base_overlap * alpha).astype(np.uint8) blended = (strip_overlap * (1 - alpha) + base_overlap * alpha).astype(np.uint8)
result_h = mh + sh - blend_h result_h = mh + sh - blend_h
result = np.zeros((result_h, mw, 3), dtype=np.uint8) result = np.zeros((result_h, mw, 3), dtype=np.uint8)
result[:sh - blend_h] = strip[:-blend_h] result[:sh - blend_h] = full_strip[:-blend_h]
result[sh - blend_h:sh] = blended result[sh - blend_h:sh] = blended
result[sh:] = base[blend_h:] result[sh:] = base[blend_h:]
return result return result
def _blend_vertical(self, base: np.ndarray, strip: np.ndarray, def _blend_vertical(self, base: np.ndarray, strip: np.ndarray,
blend_height: int, append_below: bool) -> np.ndarray: blend_height: int, append_below: bool) -> np.ndarray:
mh, mw = base.shape[:2] mh, mw = base.shape[:2]