Skip to content

Instantly share code, notes, and snippets.

@JayGoldberg
Last active October 23, 2024 01:59
Show Gist options
  • Save JayGoldberg/80a8c466df4d13d21295d82fc841dae7 to your computer and use it in GitHub Desktop.
Save JayGoldberg/80a8c466df4d13d21295d82fc841dae7 to your computer and use it in GitHub Desktop.
adds organic noise to AI generated images
# adds organic noise to AI generated images
# requires ImageMagick `convert` command
function makenoise {
# Get the input extension and use the same one for output
imageName="$1"
basename=$(basename "$imageName")
extension="${imageName##*.}"
# Split the image into channels
convert "$imageName" -separate "channel_%d.png"
# Add noise to each channel
noiseLevel=0.4
convert "channel_0.png" -evaluate gaussian-noise "$noiseLevel" "channelnoise_0.png"
convert "channel_1.png" -evaluate gaussian-noise "$noiseLevel" "channelnoise_1.png"
convert "channel_2.png" -evaluate gaussian-noise "$noiseLevel" "channelnoise_2.png"
# Combine the noisy channels with the original extension
convert "channelnoise_0.png" "channelnoise_1.png" "channelnoise_2.png" -combine "${basename}-noise.${extension}"
# Catch errors and delete temp files
if [[ $? -ne 0 ]]; then
echo "Error adding noise to image"
rm channel_*.png
rm channelnoise_*.png
exit 1
fi
rm channel_*.png
rm channelnoise_*.png
echo "Created ${basename}-noise.${extension}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment