Implement background exclusion and refactor folder structure

- Added configurable background exclusion (#1f2937) with tolerance
- Implemented alpha thresholding (>= 128) to eliminate edge artifacts
- Refactored folder structure into analyses/[slug]/images, settings, and results
- Updated pattern puller to skip existing images and handle network errors
- Updated .gitignore and automated tests for path integrity
This commit is contained in:
lm
2026-03-22 20:09:05 +01:00
parent ff9dec0eff
commit 1c48a53c19
11 changed files with 249 additions and 28 deletions
+4
View File
@@ -6,6 +6,8 @@ from .constants import (
IMAGES_DIR,
LANGUAGE,
OVERLAY_COLOR,
EXCLUDE_BG_COLOR,
EXCLUDE_BG_TOLERANCE,
PREVIEW_MAX_SIZE,
RESET_EXCLUSIONS_ON_IMAGE_CHANGE,
SUPPORTED_IMAGE_EXTENSIONS,
@@ -17,6 +19,8 @@ __all__ = [
"IMAGES_DIR",
"LANGUAGE",
"OVERLAY_COLOR",
"EXCLUDE_BG_COLOR",
"EXCLUDE_BG_TOLERANCE",
"PREVIEW_MAX_SIZE",
"RESET_EXCLUSIONS_ON_IMAGE_CHANGE",
"SUPPORTED_IMAGE_EXTENSIONS",
+14 -1
View File
@@ -94,7 +94,12 @@ def _extract_language(data: dict[str, Any]) -> str:
_CONFIG_DATA = _load_config_data()
_OPTION_DEFAULTS = {"reset_exclusions_on_image_change": False, "overlay_color": "#ff0000"}
_OPTION_DEFAULTS = {
"reset_exclusions_on_image_change": False,
"overlay_color": "#ff0000",
"exclude_bg_color": "#1f2937",
"exclude_bg_tolerance": 5,
}
def _extract_options(data: dict[str, Any]) -> dict[str, Any]:
@@ -108,6 +113,12 @@ def _extract_options(data: dict[str, Any]) -> dict[str, Any]:
color = section.get("overlay_color")
if isinstance(color, str) and color.startswith("#") and len(color) in (7, 9):
result["overlay_color"] = color
exclude_bg = section.get("exclude_bg_color")
if isinstance(exclude_bg, str) and exclude_bg.startswith("#") and len(exclude_bg) in (7, 9):
result["exclude_bg_color"] = exclude_bg
tolerance = section.get("exclude_bg_tolerance")
if isinstance(tolerance, int):
result["exclude_bg_tolerance"] = max(0, min(255, tolerance))
return result
@@ -116,3 +127,5 @@ LANGUAGE = _extract_language(_CONFIG_DATA)
OPTIONS = {**_OPTION_DEFAULTS, **_extract_options(_CONFIG_DATA)}
RESET_EXCLUSIONS_ON_IMAGE_CHANGE = OPTIONS["reset_exclusions_on_image_change"]
OVERLAY_COLOR = OPTIONS["overlay_color"]
EXCLUDE_BG_COLOR = OPTIONS["exclude_bg_color"]
EXCLUDE_BG_TOLERANCE = OPTIONS["exclude_bg_tolerance"]