I have an example working with Fx, which checks a basic plus-shaped kernel for a difference in value past some limit:
Code: Select all
#!/bin/bash runthis.sh
convert in.png \
-fx "lim = .25;
mm = 0;
mm = max(mm, p[-1,0]);
mm = max(mm, p[0,-1]);
mm = max(mm, p[0,1]);
mm = max(mm, p[1,0]);
mm-p[0] > lim ? p[0]+lim/2 : p[0]" \
out.png
METRIC=`compare -metric AE in.png out.png null: 2>&1`
echo $METRIC
if [ $METRIC -ne "0" ]; then
cp out.png in.png
sh runthis.sh
fi
Output:
In this case, it brightens pixels near a peak until they're within the contrast limit, and loops until all areas of contrast over the limit are gone. I can also write it so it pulls down peaks, but this is better for my purposes (for now).
Of course Fx is extremely slow, and the simple unweighted kernel produces some very obvious artifacts. Is there a faster and better way to do this?
The old "inverse of unsharp mask" trick is similar, but doesn't seem to be very easy to control; some kind of convolution also seems likely; but in both cases, I can't work out how I'd specify a contrast threshold, or – even better – specify that the effect be proportional over some contrast threshold.
Thanks --