Hi!
I need to weed through thausands of pictures and get rid of the ones that only have black pixels.
What is the fastest way to detect images that contain nothing else but black. grb 0,0,0.
The Key word is fast.
I'm using ImageMagick 6.6.4-4 2010-09-17 Q8 with cygwin
Any suggestions?
Thanks!
Andi
detect fully black images
Re: detect fully black images
Since all black images have a much smaller file size than images with detail you could use a bash script to delete all files below a certain amount of bytes. Check the properties of one of the black images for file size.
This will delete all jpg files smaller than 20k.
file.sh
This will delete all jpg files smaller than 20k.
file.sh
Code: Select all
#!/bin/bash
for image_file in *.jpg
do
filesize=$(stat -c%s "$image_file")
if [ $filesize -lt 20000 ]; then
rm $image_file
fi
done
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: detect fully black images
mean=`convert image -format "%[mean]" info:`
if [ "$mean" = 0 ]; then
echo "totally black image"
else
echo "not totally black image"
fi
or if you want a threshold
thresh=XX (XX as fraction between 0 and 1)
mean=`convert image -format "%[mean]" info:`
meantest=`convert xc: -format "%[fx:($mean/quantumrange)<$thresh?1:0]" info:`
if [ $meantest -eq 1 ]; then
echo "essentially black image"
else
echo "not black image"
fi
see string formats: http://www.imagemagick.org/script/escape.php
and fx escapes: http://www.imagemagick.org/Usage/transform/#fx_escapes
and fx at: http://www.imagemagick.org/script/fx.php
if [ "$mean" = 0 ]; then
echo "totally black image"
else
echo "not totally black image"
fi
or if you want a threshold
thresh=XX (XX as fraction between 0 and 1)
mean=`convert image -format "%[mean]" info:`
meantest=`convert xc: -format "%[fx:($mean/quantumrange)<$thresh?1:0]" info:`
if [ $meantest -eq 1 ]; then
echo "essentially black image"
else
echo "not black image"
fi
see string formats: http://www.imagemagick.org/script/escape.php
and fx escapes: http://www.imagemagick.org/Usage/transform/#fx_escapes
and fx at: http://www.imagemagick.org/script/fx.php