#!/bin/sh
# occlude - generate a set of images with rectangular sections occluded
# usage: occlude img
# Displays img in iv and generates a numbered occluded image
# for every two middle-clicks (which select a position in the image).

IFS=', '
BFN="${1%.*}"
FE="${1##*.}"
CTR=1
'/usr/local/bin/iv' "$1" | while read X Y
do
    if [ -n "$SX" ]
    then
        magick "$1" -fill black -draw "rectangle ${SX},${SY} ${X},${Y}" "${BFN}_${CTR}.${FE}"
        SX=''
        SY=''
        CTR="$((CTR+1))"
    else
        SX="$X"
        SY="$Y"
    fi
done
