6

I have checked that a lot of images in a website are completely blank, ie, 500x500 with all pixels white. All the images are in subdirectories of the images directory. How can I check which ones are white? I am thinking on getting the names of these images.

UPDATE:

  • I would like to use some bash script or command.
  • Imagemagick is installed
  • Server is Ubuntu 14.04
  • All images are .jpg extension
1
  • 3
    ...with a browser? with a script? with a "one-liner"? Do you have any command-line tools to do image analysis? Commented Oct 13, 2016 at 17:58

3 Answers 3

4

If you have -- or can install -- the ImageMagick package, it has an identify utility that can print out a histogram of the colors in the file; the awk program below will scan the identify -verbose output for the number of colors and the colors listed in the histogram. If there is only one color listed and the only colors in the histogram are white, then it will return "success", otherwise "failure".

You can then wrap a shell script around awk and identify to flag matching files:

for f in images/* do identify -verbose "$f" | awk -f iswhite.awk && echo "$f is an all-white image" done 

iswhite.awk:

/Histogram:/ { inhisto=1 } inhisto && /[[:digit:]]+: \([ [:digit:]]{3},[ [:digit:]]{3},[ [:digit:]]{3}\) #/ { if ($0 !~ /#FFFFFF white/) { nonwhite=1 } } /Rendering intent/ { inhisto=0 } /Colors: / { ncolors=$2 } END { if (ncolors == 1 && nonwhite == 0) { exit 0 } else { exit 1 } } 
1
  • It works like a charm. I have just edited the loop with a find to be able to retrieve the images in the subdirectories. Thanks Commented Oct 14, 2016 at 7:39
2

Using findimagedupes:

# Look for and compare images that are 90% similar # in all subdirectories of the current directory. findimagedupes -R -- . 

The -t option controls how similar the images should be:

# Same as before but for images that are 99% similar. findimagedupes -t 99 -R -- . 

Suppose a directory had these files:

white.png foo.png. bar.png. baz.jpg green.png 

...where white.png was known to be white, green.png was known to be green, and the other were uncertain. Since findimagedupes outputs any similar files on the same line, (space separated), this would show only the white ones:

findimagedupes -t 100 -R -- . | grep -w white.png 

Output, (assuming bar.png is white):

white.png bar.png 

See also: Command line tool to check whether two images are exactly the same graphically, and more generally: An intelligent duplicate file finder for Linux.

1
  • 1
    Actually, findimagedupes deliberately throws away colour information before comparing. A 100% white image would match a 100% green image just fine if both had maximum intensity They'd both have the fingerprint: //////////////////////////////////////////8= Commented Feb 2, 2019 at 21:25
1

The following command will tell you the value of the darkest pixel in an image:

magick YOURIMAGE.jpg -format "%[min]" info: 

If a JPEG image is white, that value will be 255.


If your images happen to be 16-bit PNGs (I know you currently have JPEGs, but there are other readers), the value for white will be 65,535 rather than 255. Rather than write two test cases, you may want to invert your image so white (255 or 65,535) becomes black (0) and then look for the brightest pixel which will be zero in both cases if your original image was white:

magick YOURIMAGE.jpg -negate -format "%[max]" info: 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.