122 lines
4.4 KiB
Python
122 lines
4.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Baxxter pipeline: rembg variants composited over backgrounds and originals."""
|
|
|
|
from pathlib import Path
|
|
|
|
from imagepipeline import Pipeline
|
|
|
|
INPUT = Path("/home/frank/pics/20260525_Shooting Baxxter Boys/darktable_exported")
|
|
OUTPUT_BASE = Path.home() / "pipeline_output"
|
|
|
|
GRADIENT_COLOR1 = "#d7fd00ff"
|
|
GRADIENT_COLOR2 = "#fc0adeff"
|
|
|
|
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,252,10,222,200,0"
|
|
GMIC_BWRECOLOR = (
|
|
"-fx_bwrecolorize 0,0,0,0,0,1,0,2,252,10,222,255,215,253,0,255,"
|
|
"158,137,189,255,224,191,228,255,215,253,0,255,255,255,255,255,255,255,"
|
|
"255,255,215,253,0,255"
|
|
)
|
|
GMIC_GRADIENT_A = (
|
|
'-fx_custom_gradient 0,0,0,1,2,1,0,128,100,100,2,0,1,0,"",1,0,215,253,0,255,'
|
|
"252,10,222,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,252,10,222,255,'
|
|
"215,253,0,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="baxxter",
|
|
input_dir=INPUT,
|
|
output_base=OUTPUT_BASE,
|
|
) 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=GRADIENT_COLOR1,
|
|
color2=GRADIENT_COLOR2,
|
|
gradient=True,
|
|
angle=45,
|
|
)
|
|
gradient_radial_bg = p.step(
|
|
"imagemagick_fill",
|
|
inputs="input",
|
|
color1=GRADIENT_COLOR1,
|
|
color2=GRADIENT_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,
|
|
)
|
|
|
|
# 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])
|
|
|
|
output_root = p.run()
|
|
|
|
print(f"Pipeline finished. Output: {output_root}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|