Skip to content

Instantly share code, notes, and snippets.

@sdmcraft
Created November 30, 2017 10:25
Show Gist options
  • Save sdmcraft/360d39aa2e386788fcc924e1890284e6 to your computer and use it in GitHub Desktop.
Save sdmcraft/360d39aa2e386788fcc924e1890284e6 to your computer and use it in GitHub Desktop.
Create noisy copies of images
#!/bin/sh
usage()
{
echo -e "Usage: $0 -c <number of noisy copies per image> -s <source folder containing images> -p <image name pattern> -d <destination folder to keep noisy images>" \
"\nExample Usage: ./create-noise.sh -c 10 -s /home/satyadeep/Pictures/000 -p '*.jpg' -d /home/satyadeep/temp/tst" 1>&2; exit 1;
}
while getopts c:s:p:d: option
do
case "${option}"
in
c) LOOP_COUNT=${OPTARG};;
s) SOURCE_FOLDER=${OPTARG};;
p) PATTERN=${OPTARG};;
d) DEST_FOLDER=${OPTARG};;
*) usage;;
esac
done
echo COUNT=$LOOP_COUNT
echo SOURCE=$SOURCE_FOLDER
echo PATTERN=$PATTERN
echo DEST_FOLDER=$DEST_FOLDER
for BASE_IMG in $SOURCE_FOLDER/$PATTERN
do
echo $BASE_IMG
counter=0
until [ ! $counter -lt $LOOP_COUNT ]
do
convert $BASE_IMG +noise Gaussian $DEST_FOLDER/$counter-`basename $BASE_IMG`
echo "Generated " $DEST_FOLDER/$counter-`basename $BASE_IMG`
counter=`expr $counter + 1`
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment