Identify images with blocks of black colour

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
teresaejunior
Posts: 2
Joined: 2015-08-22T08:18:11-07:00
Authentication code: 1151

Identify images with blocks of black colour

Post by teresaejunior »

Hello! I would like to know if it is possible to identify image with black blocks. I'm downloading static aerial pictures from the Google API, but for places where Google has not images available, it returns black, but with street names and other things. Example picture:

Image

Such pictures are generally smaller in size than working ones, but that is not always the case, as in the example below of an image that is small too, but has almost only the green colour:

Image

The only thing I want is for ImageMagick to identify such images as the first one, so I can delete them and retry downloading again every month.

I have the command-line ImageMagick 6.7.7.10 on Linux. Thank you for your attention!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Identify images with blocks of black colour

Post by snibgo »

The first image has a low mean and high standard deviation. The second has a high mean with low standard deviation. This might be a reliable indicator.

Or you could turn all non-black pixels white (within a fuzz limit, as JPEG will not create solid blacks). Then find the mean: a high value means there was litle black; a low value means there was much black. This might be more reliable.

Code: Select all

f:\web\im>%IM%convert oNarCc5.jpg -fuzz 1% -fill White +opaque Black -format %[fx:mean] info:

0.15052

f:\web\im>%IM%convert 5GzLkbj.jpg -fuzz 1% -fill White +opaque Black -format %[fx:mean] info:

0.999852
See also http://www.imagemagick.org/script/escape.php
snibgo's IM pages: im.snibgo.com
teresaejunior
Posts: 2
Joined: 2015-08-22T08:18:11-07:00
Authentication code: 1151

Re: Identify images with blocks of black colour

Post by teresaejunior »

That seems to be enough, @snibgo. Thank you so much!
Post Reply