Hi,
thanks for the detailed reply. I found another way:
Code: Select all
#!/bin/bash
declare dir=Reassembled
if [ ! -d $dir ]; then
mkdir $dir; fi
declare -a eqORgt
eqORgt=("-eq" "-gt");
for k in *.tif; do
op=$(($RANDOM % ${#eqORgt[@]}))
noEntries=25
count=0
numbers=()
files=()
# crop the interesting part
convert $k -crop 42%x86%+260+80 ${k%.*}_crop.jpg
# resize
convert $ECHO "${k%.*}_crop.jpg" -resize 35x50 rf${k%.*}.jpg
# cut into pieces
convert $ECHO "rf${k%.*}.jpg" -crop 20% %d_mask.jpg
while [ $count -lt $noEntries ]; do
random=$(($RANDOM % $noEntries))
case " ${numbers[@]} " in *" ${random} "*) continue ;; esac
numbers[$count]=${random}
files[$count]=${random}_mask.jpg
let Even=$random%2
if [ $Even ${eqORgt[op]} 0 ] ; then
convert -rotate 180 $ECHO "${files[$count]}" $ECHO "${files[$count]}"; fi
let count++
done
echo NUMBERS: ${numbers[@]}
echo FILES: ${files[@]}
# reassemble the pieces
convert \( $ECHO "${files[0]}" $ECHO "${files[1]}" $ECHO "${files[2]}" $ECHO "${files[3]}" $ECHO "${files[4]}" +append \) \( $ECHO "${files[5]}" $ECHO "${files[6]}" $ECHO "${files[7]}" $ECHO "${files[8]}" $ECHO "${files[9]}" +append \) \( $ECHO "${files[10]}" $ECHO "${files[11]}" $ECHO "${files[12]}" $ECHO "${files[13]}" $ECHO "${files[14]}" +append \) \( $ECHO "${files[15]}" $ECHO "${files[16]}" $ECHO "${files[17]}" $ECHO "${files[18]}" $ECHO "${files[19]}" +append \) \( $ECHO "${files[20]}" $ECHO "${files[21]}" $ECHO "${files[22]}" $ECHO "${files[23]}" $ECHO "${files[24]}" +append \) -append rf${k%.*}_mask.jpg
# create a gray background
convert $ECHO "rf${k%.*}_mask.jpg" -background 'rgb(170,170,170)' -gravity center -extent 800x600 rf${k%.*}_mask.png
convert $ECHO "rf${k%.*}.jpg" -background 'rgb(170,170,170)' -gravity center -extent 800x600 rf${k%.*}.png
# clear the mess
rm $ECHO ${files[@]}
rm $ECHO "rf${k%.*}_mask.jpg"
rm $ECHO "rf${k%.*}.jpg"
mv $ECHO "rf${k%.*}_mask.png" $ECHO ${dir}/.
mv $ECHO "rf${k%.*}.png" $ECHO ${dir}/.
done
It's surely not the most elegant way, but it works for me.
There is only one thing left:
the pictures are actually displaying faces. Unfortunately, the faces are not on all the pictures centered, and they also differ slightly in size.
So with my command:
Code: Select all
# crop the interesting part
convert $k -crop 42%x86%+260+80 ${k%.*}_crop.jpg
I do not obtain always the face centered. All the pictures should have the same size in the end. But I need to crop from each picture a slightly different part.
How can I do this?
My idea was to create a black and white mask of each picture and then cut from each picture the part where the black (= background) starts.
But since I am not so familiar with ImageMagick, I did not find the right way to do that.
Any hint is most appreciated!
Thank you very much in advance!
Hannes