ce431d7eec
Delegate expected output filenames to modules so resume works for rembg and composite; normalize G'MIC multi-frame output; add OpenRouter style reference support with tests. Add Crusaders, orange, and team gallery pipelines plus SOUL/AGENTS context files. Co-authored-by: Cursor <cursoragent@cursor.com>
156 lines
5.9 KiB
Python
156 lines
5.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Crusaders pipeline: rembg variants composited over backgrounds and originals."""
|
|
|
|
from pathlib import Path
|
|
|
|
from imagepipeline import Pipeline
|
|
|
|
INPUT = Path("/home/frank/pics/20260620_Albershausen Crusaders - Montabaur Fighting Farmers/darktable_exported")
|
|
OUTPUT_BASE = Path.home() / "pipeline_output"
|
|
|
|
# Reuse outputs from a previous run or external folder (key = step id, e.g. rembg_01).
|
|
EXISTING_OUTPUTS: dict[str, Path] = {}
|
|
|
|
# Resume an aborted run: point to its output root folder (or None for a fresh run).
|
|
CONTINUE_FROM: Path | None = Path("/home/frank/pipeline_output/crusaders_260623085301")
|
|
|
|
COLOR1 = "#0064b0"
|
|
COLOR2 = "#00badf"
|
|
|
|
# COLOR1 = #0064b0 -> 0,100,176; COLOR2 = #00badf -> 0,186,223
|
|
GMIC_STEREO = "-gcd_stereo_img 0,0,2.028,1,1.714,3.06,4,1,0"
|
|
GMIC_DROP_SHADOW = "-fx_drop_shadow3d 0,0,0,10,1,1,2,0.5,0,186,223,200,0"
|
|
GMIC_BWRECOLOR = (
|
|
"-fx_bwrecolorize 0,0,0,0,0,1,0,2,0,186,223,255,0,100,176,0,255,"
|
|
"158,137,189,255,224,191,228,255,0,100,176,0,255,255,255,255,255,255,255,"
|
|
"255,255,0,100,176,0,255"
|
|
)
|
|
GMIC_GRADIENT_A = (
|
|
'-fx_custom_gradient 0,0,0,1,2,1,0,128,100,100,2,0,1,0,"",1,0,0,100,176,255,'
|
|
"0,186,223,255,255,255,0,255,255,255,255,255,0,255,255,255,0,255,0,255,0,0,"
|
|
"255,255,128,128,128,255,255,0,255,255,0,0,0,0"
|
|
)
|
|
GMIC_GRADIENT_B = (
|
|
'-fx_custom_gradient 0,0,0,1,2,1,0,128,100,100,2,0,1,0,"",1,0,0,186,223,255,'
|
|
"0,100,176,255,255,255,0,255,255,255,255,255,0,255,255,255,0,255,0,255,0,0,"
|
|
"255,255,128,128,128,255,255,0,255,255,0,0,0,0"
|
|
)
|
|
GMIC_JPR_SMOOTH = "-jpr_gradient_smooth 0,1.5"
|
|
|
|
|
|
def main() -> None:
|
|
with Pipeline(
|
|
name="crusaders",
|
|
input_dir=INPUT,
|
|
output_base=OUTPUT_BASE,
|
|
existing_outputs=EXISTING_OUTPUTS or None,
|
|
continue_from=CONTINUE_FROM,
|
|
) as p:
|
|
rembg_out = p.step("rembg", inputs="input")
|
|
|
|
white_bg = p.step("imagemagick_fill", inputs="input", color1="#ffffff")
|
|
black_bg = p.step("imagemagick_fill", inputs="input", color1="#000000")
|
|
gradient_45_bg = p.step(
|
|
"imagemagick_fill",
|
|
inputs="input",
|
|
color1=COLOR1,
|
|
color2=COLOR2,
|
|
gradient=True,
|
|
angle=45,
|
|
)
|
|
gradient_radial_bg = p.step(
|
|
"imagemagick_fill",
|
|
inputs="input",
|
|
color1=COLOR1,
|
|
color2=COLOR2,
|
|
gradient=True,
|
|
radial=True,
|
|
)
|
|
grayscale = p.step("gmic_grayscale", inputs="input")
|
|
|
|
rembg_stereo = p.step("gmic", inputs=rembg_out, command=GMIC_STEREO)
|
|
rembg_shadow = p.step("gmic", inputs=rembg_out, command=GMIC_DROP_SHADOW)
|
|
rembg_bwrecolor = p.step("gmic", inputs=rembg_out, command=GMIC_BWRECOLOR)
|
|
rembg_gradient_a = p.step("gmic", inputs=rembg_out, command=GMIC_GRADIENT_A)
|
|
rembg_gradient_b = p.step("gmic", inputs=rembg_out, command=GMIC_GRADIENT_B)
|
|
rembg_jpr_smooth = p.step("gmic", inputs=rembg_out, command=GMIC_JPR_SMOOTH)
|
|
rembg_jpr_smooth_sized = p.step(
|
|
"imagemagick_scale_crop",
|
|
inputs=rembg_jpr_smooth,
|
|
scale=1.05,
|
|
)
|
|
|
|
rembg_stereo_alpha = p.step(
|
|
"color_to_alpha", inputs=rembg_stereo, color="#000000"
|
|
)
|
|
color_bg = p.step("imagemagick_fill", inputs="input", color1=COLOR1)
|
|
rembg_smooth_alpha = p.step(
|
|
"color_to_alpha", inputs=rembg_jpr_smooth, color="#7f7f7f"
|
|
)
|
|
rembg_smooth_sized = p.step(
|
|
"imagemagick_scale_crop",
|
|
inputs=rembg_smooth_alpha,
|
|
scale=1.05,
|
|
)
|
|
|
|
# combine: white background, rembg
|
|
p.step("composite", inputs=[white_bg, rembg_out])
|
|
|
|
# combine: black background, rembg
|
|
p.step("composite", inputs=[black_bg, rembg_out])
|
|
|
|
# combine: linear gradient background, rembg
|
|
p.step("composite", inputs=[gradient_45_bg, rembg_out])
|
|
|
|
# combine: radial gradient background, rembg
|
|
p.step("composite", inputs=[gradient_radial_bg, rembg_out])
|
|
|
|
# combine: original, rembg (stereo), rembg
|
|
stereo_mid = p.step("composite", inputs=["input", rembg_stereo])
|
|
p.step("composite", inputs=[stereo_mid, rembg_out])
|
|
|
|
# combine: original, rembg (drop shadow), rembg
|
|
shadow_mid = p.step("composite", inputs=["input", rembg_shadow])
|
|
p.step("composite", inputs=[shadow_mid, rembg_out])
|
|
|
|
# combine: original, rembg (bw recolorize @ 50%), rembg
|
|
bw_mid = p.step(
|
|
"composite",
|
|
inputs=["input", rembg_bwrecolor],
|
|
foreground_opacity=0.5,
|
|
)
|
|
p.step("composite", inputs=[bw_mid, rembg_out])
|
|
|
|
# combine: rembg (custom gradient A), rembg
|
|
p.step("composite", inputs=[rembg_gradient_a, rembg_out])
|
|
|
|
# combine: rembg (custom gradient B), rembg
|
|
p.step("composite", inputs=[rembg_gradient_b, rembg_out])
|
|
|
|
# combine: original, rembg (jpr smooth, scaled), rembg
|
|
smooth_mid = p.step("composite", inputs=["input", rembg_jpr_smooth_sized])
|
|
p.step("composite", inputs=[smooth_mid, rembg_out])
|
|
|
|
# combine: original (grayscale), rembg
|
|
p.step("composite", inputs=[grayscale, rembg_out])
|
|
|
|
# combine: original, rembg (stereo, black to alpha), rembg
|
|
stereo_alpha_mid = p.step("composite", inputs=["input", rembg_stereo_alpha])
|
|
p.step("composite", inputs=[stereo_alpha_mid, rembg_out])
|
|
|
|
# combine: color background, rembg (drop shadow), rembg
|
|
shadow_color_mid = p.step("composite", inputs=[color_bg, rembg_shadow])
|
|
p.step("composite", inputs=[shadow_color_mid, rembg_out])
|
|
|
|
# combine: original, rembg (jpr smooth, #7f7f7f to alpha, scaled), rembg
|
|
smooth_alpha_mid = p.step("composite", inputs=["input", rembg_smooth_sized])
|
|
p.step("composite", inputs=[smooth_alpha_mid, rembg_out])
|
|
|
|
output_root = p.run()
|
|
|
|
print(f"Pipeline finished. Output: {output_root}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|