#! /bin/bash
# Last edited on 2012-09-08 02:59:06 by stolfilocal

dset="$1"; shift
dext="$1"; shift
imgs=( "$@" ); shift

chunks=()
for img in ${imgs[@]} ; do 
  for cut in 00 01 02 03 04 05 06; do
    cutfile="data/${dset}/${img}-c${cut}.cut"
    echo "${cutfile}" 1>&2
    if [[ -s ${cutfile} ]]; then
      cutargs=( `cat ${cutfile}` )
      oname="out/${dset}/${img}-c${cut}"
      ifile="data/${dset}/${img}.${dext}"
      ofile="${oname}.ppm"
      echo "${ifile} --> ${ofile}" 1>&2
      convert \
          ${ifile} \
          -depth 16 \
          +repage "${cutargs[@]}" \
          ${ofile}
      chunks=( ${chunks[@]} ${ofile} )
      # display -title '%f' ${oname}.ppm 
      # -channel ${ch} -separate \
    fi
  done
done
display -title '%f' ${chunks[@]}
