#! /usr/bin/python3 # Last edited on 2025-08-10 10:29:34 by stolfi import sys, re from math import sin, cos, log, exp, floor, ceil, inf, nan, pi from error_funcs import arg_error, prog_error from process_funcs import run_command, bash import argparser def main(): page, clip, oname, inR, inG, inB = parse_options() # Grab the monochrome images for this composite: components = [] for band, maxval in inR, inG, inB: cfile_in = f"MS/davis/{page}/{band}/clips/{clip}.pgm" cdir_ot = f"pages/{page}/clips/{clip}/mono" bash(f"mkdir -p {cdir_ot}") cfile_ot = f"{cdir_ot}/{band}.png" hmaxval = ("%04x" % maxval) hblack = "#000000000000" hwhite= f"#{hmaxval}{hmaxval}{hmaxval}" sys.stderr.write(f"{cfile_in} -> {cfile_ot}\n") bash \ ( f"convert {cfile_in}" + \ f" -set colorspace LinearGray" + \ f" -level-colors '{hblack},{hwhite}'" + \ f" -depth 16" + \ f" -colorspace Gray" + \ f" {cfile_ot}" ) bash(f"display -title '%f' {cfile_ot}") components.append(cfile_ot) # Create the composite: odir = f"pages/{page}/clips/{clip}/comps/hand" bash(f"mkdir -p {odir}") ofile = f"{odir}/{oname}.png" bash \ ( f"convert" + \ f" {components[0]}" + \ f" {components[1]}" + \ f" {components[2]}" + \ f" -combine" + \ f" {ofile}" ) bash(f"gimp -s -n {ofile}") return 0 # ---------------------------------------------------------------------- def parse_options(): iarg = 1 # Next command line arg to parse page = sys.argv[iarg]; iarg += 1 clip = sys.argv[iarg]; iarg += 1 oname = sys.argv[iarg]; iarg += 1 inR = split_component(sys.argv[iarg]); iarg += 1 inG = split_component(sys.argv[iarg]); iarg += 1 inB = split_component(sys.argv[iarg]); iarg += 1 return page, clip, oname, inR, inG, inB # ---------------------------------------------------------------------- def split_component(arg): # The {arg} must be a string "{band}/{maxval}". # Returns a tuple {({band}, {maxval})} with {maxval} as {int}. flds = re.split(r"/", arg) if len(flds) != 2: arg_error(f"bad component {arg}") band = flds[0] maxval = int(flds[1]) return (band, maxval,) # ---------------------------------------------------------------------- main()