I tried to create auto color correction according to well known PS method: duplicate layer, blur to average, invert H value, set opacity to please, blend in color mode.
I hit to obstacles in ImageMagick:
1) best solution would be create automatically two separate layers with appropriate settings (blend mode, opacity) and later just review them, adjust sliders when necessary and save output; but I've found that IM doesn't really support multilayer TIF files
2) after many tests I've come to settings that best 'good enough' opacity of correcting layer is B*0.5. It isn't perfect but as I said 'good enough'. But looks like Colorize composition supports neither blending intensity options nor opacity in blended file. Any suggestions how to solve that?
Code: Select all
#!/bin/zsh
LC_ALL=C
overlay_size=$(identify -format "%wx%h" "$1")
hsb_line=$(/x/Roboczy/mikolaj/im690st/convert.exe "$1" -resize "1x1" -colorspace HSB txt:- | tail -1)
hsb_vals=$(expr match "$hsb_line" '.*hsb(\(.*\))' | tr -d '%')
h_val=$(echo $hsb_vals | cut -f1 -d,); h_val=$(printf "%.0f" $(($h_val+0.5)))
s_val=$(echo $hsb_vals | cut -f2 -d,); s_val=$(printf "%.0f" $(($s_val+0.5)))
b_val=$(echo $hsb_vals | cut -f3 -d,); b_val=$(printf "%.0f" $(($b_val+0.5)))
o_val=$(printf "%.0f" $((($b_val*45)/100)))
if [[ $h_val -gt 50 ]]; then
new_h=$(($h_val-50))
elif [[ $h_val -lt 50 ]]; then
new_h=$(($h_val+50))
else
new_h=0
fi
/x/Roboczy/mikolaj/im690st/convert.exe -depth 8 -size $overlay_size xc:"hsba($new_h%,$s_val%,$b_val%,0.$o_val)" o.tif
/x/Roboczy/mikolaj/im690st/convert.exe -depth 8 "$1" o.tif -compose Colorize -composite $1.o.tif