Page 1 of 1

detect fully black images

Posted: 2010-09-20T14:51:30-07:00
by andienz
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

Re: detect fully black images

Posted: 2010-09-20T15:09:46-07:00
by lwhistler
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

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

Re: detect fully black images

Posted: 2010-09-20T15:18:06-07:00
by fmw42
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