Programmatically determine “uniformity” of image

image manipulationimagemagickimages

I'm attempting to write a script which thumbnails our many thousands of assets. The assets use Flash for the most part, and I'm capturing them via chromium-browser on the command line. I pretty much need to stand over it to make it work at the moment and it's a PITA. What would help would be a way for my script to know when it had made a failed thumbnail, which seems to happen a lot.

The "fails" tend to be a uniform colour, either dark grey or white, and I thought I might be able to use this "degree of uniformity" as a way of programmatically rating the success of the thumbnail. Here's some examples:

https://dl.dropboxusercontent.com/u/846812/permanent/thumb_examples/fail_1.jpg
https://dl.dropboxusercontent.com/u/846812/permanent/thumb_examples/fail_2.jpg
https://dl.dropboxusercontent.com/u/846812/permanent/thumb_examples/success1.jpg
https://dl.dropboxusercontent.com/u/846812/permanent/thumb_examples/success2.jpg

What makes this (I would assume) more difficult is that the dark grey one is not a uniform color, but is rather a repeated pattern of pixels, which looks like this in close up:

enter image description here

So it is uniform, but it's a uniform repeated pattern.

Can anyone think of a way I could do this at the command line?

Best Answer

I don't know how you can programatically do this and it is not a 100% accurate thing but, since you are doing something close to screen scraping, I would suggest actually launching the image on the screen and using xdtool, you can sample many random points on the image and detect the pixel color. If all or say more than 95% of them are coming up the same color, it is safe to say the image is a flat color.

Another way is to store commonly encountered erroneous images and compare the image size to the size of erroneous images. I am extracting stills from videos using VLC for my video library and while doing this, I realized, higher the contrast in an image, larger the size of a png file I capture. So, see if the image sizes are too small. After all, image compression is all about minimizing the amount of storage of a repeating pattern. You can use this fact to your advantage.

Related Question