Find images that are almost entirely blank white
Find images that are almost entirely blank white
Hi
I've used ImageMagick to find pure white images using the command line (linux) without an issue, however I notice that some images are also almost white. The command I used was
identify -verbose -unique
And count the colours. If it was 1 it was assumed pure white (as we don't have any other colours). Is there a way of finding these images with slight artifacts on them using IM?
Kind regards
Jay
I've used ImageMagick to find pure white images using the command line (linux) without an issue, however I notice that some images are also almost white. The command I used was
identify -verbose -unique
And count the colours. If it was 1 it was assumed pure white (as we don't have any other colours). Is there a way of finding these images with slight artifacts on them using IM?
Kind regards
Jay
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Find images that are almost entirely blank white
Please, always provide your IM version and platform when asking questions, since syntax may differ. Also provide your exact command line and if possible your images.
See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at viewtopic.php?f=1&t=9620
The easiest way I can think is to do:
convert image -fuzz XX% -fill black +opaque white -fill white -opaque white -format "%[fx:100*mean]" info:
The result will be a value between 0% and 100%. The closer to 100% the more white you have. The -fuzz XX% will allow colors close to white to be treated as white. A value of 0% would mean keep only perfectly white values.
See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at viewtopic.php?f=1&t=9620
The easiest way I can think is to do:
convert image -fuzz XX% -fill black +opaque white -fill white -opaque white -format "%[fx:100*mean]" info:
The result will be a value between 0% and 100%. The closer to 100% the more white you have. The -fuzz XX% will allow colors close to white to be treated as white. A value of 0% would mean keep only perfectly white values.
Re: Find images that are almost entirely blank white
Hi
Thanks for the reply. Sorry for not giving the full info.
Version: ImageMagick 6.7.2-7 2017-03-22 Q16 http://www.imagemagick.org on centos 6
I'll give the fuzz option a shot and see what it comes up with thanks
Kind regards
Jay
Thanks for the reply. Sorry for not giving the full info.
Version: ImageMagick 6.7.2-7 2017-03-22 Q16 http://www.imagemagick.org on centos 6
I'll give the fuzz option a shot and see what it comes up with thanks
Kind regards
Jay
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Find images that are almost entirely blank white
If you just need to determine how near an image is to pure white, you can use IM to find its total average brightness by resizing it to 1x1, then testing that pixel for luma. A command like this should work for IM v6...JAY6390 wrote: ↑2017-07-11T14:19:56-07:00I've used ImageMagick to find pure white images using the command line (linux) without an issue, however I notice that some images are also almost white. The command I used was
identify -verbose -unique
And count the colours. If it was 1 it was assumed pure white (as we don't have any other colours). Is there a way of finding these images with slight artifacts on them using IM?
Code: Select all
convert input.png[1x1!] -format "%[fx:100*luma]" info:
Re: Find images that are almost entirely blank white
Nice info thanks GeeMack
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Find images that are almost entirely blank white
The FX expressions are extremely helpful for doing various types of analyses. You can find some good basic instructions at THIS link. You can even use conditional expressions in them, so you could, for example, test a whole directory of images with a command like this...
Code: Select all
convert *.jpg[1x1!] -format "%[fx:luma>0.98?1:0] %[f]\n" info: > tmp.txt
In a *nix shell or script you could pipe the output of the above command through "sed" to get only lines that start with 1, and even peel off the 1 so you get a text file list of all the JPGs in the directory with a luma value more than 98%.
Re: Find images that are almost entirely blank white
Awesome thank you GeeMack very much. I'll see if I can get a bash script going that'll do that for the some 1/4 million images it needs to check!
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Find images that are almost entirely blank white
I just found that at least in v6.7.7 and older versions of IM6, the FX expression "luma" isn't available, but "luminance" is. It seems to do exactly the same thing. I ran a command like this in a bash shell under Windows 10. I ran it in a directory of almost 2000 JPG images...
Code: Select all
convert *.jpg[1x1\!] -format '%[fx:luminance>0.98?1:0] %[f]\n' info: | sed -n 's/^1 \(.*\)/\1/p' > tmp.txt
Re: Find images that are almost entirely blank white
Awesome. As it's a client server, I daren't update the version of IM, so will take a crack at that tomorrow and post back with the results
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Find images that are almost entirely blank white
Luma and luminance are different. The first is sRGB (non-linear) and the second is linear. In very old versions of Imagemagick, they were even swapped.
The reason I did not go to luma or grayscale or even simply fx:mean or even -threshold is that it does not consider color. That is why I simply tried to isolate near-white vs everything else. There may not be much difference when you get really close to white (very bright), but I thought this would be the best approach.
EDITED to remove an incorrect statement.
The reason I did not go to luma or grayscale or even simply fx:mean or even -threshold is that it does not consider color. That is why I simply tried to isolate near-white vs everything else. There may not be much difference when you get really close to white (very bright), but I thought this would be the best approach.
EDITED to remove an incorrect statement.
Re: Find images that are almost entirely blank white
Hmm - might have to go the separate server route then and compile a more recent version. Do either of you know which version I'll be safe to use that'll have the luma?
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Find images that are almost entirely blank white
You shouldn't have to do any upgrading if the command fmw42 provided works. Try his example and just modify that "-format" part...
Code: Select all
... -format '%[fx:100*mean]' ...
Code: Select all
... -format '%[fx:mean>0.98?1:0] %[f]\n' ...
Re: Find images that are almost entirely blank white
I just went with the upgrade to be sure - wasn't too much extra work. Found some images which was the main thing, and removed them. Thanks for all the help - much appreciated fmw42 and GeeMack