3

I want to delete duplicates in a massive bunch of images. Well as I have dups of the same picture in a different resolution I will make the deletion myself. BUT I want to do this in linear time. So I thought it woud be smart to sort the images via renaming the images with an average color prefix with a little script. The problem is that I don't know any software that is able to compute the average color in the CLI. Is there any?

ManuelSchneid3r
  • 4,256
  • 8
  • 41
  • 58
  • Unless you're really looking for images with the same average color and not for duplicate images in general, see [Open source duplicate image finder for Linux?](http://unix.stackexchange.com/q/28895) – Gilles 'SO- stop being evil' Feb 10 '13 at 19:28

2 Answers2

6

Finally I played around a while and found the ImageMagick software pack. It's great because it lets me do it in a one-liner in the console without the need for a script.

for i in ./*; do mv "$i" "$(convert "$i" -scale 1x1\! -format '%[pixel:s]' info:- | cut -db -f2-)${i#./}" ;done

It just does nothing more than loop through the folder (precondition: it just contains images!), get the average color via convert "$i" -scale 1x1\! -format '%[pixel:s]' info:- extract the relevant part from the output cut -db -f2- and finally rename the file. Horribly how well it worked.

Greets

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
ManuelSchneid3r
  • 4,256
  • 8
  • 41
  • 58
4

If I understand your question correctly, you could do something like:

wget -qO- 'https://www.gravatar.com/avatar/22e8a29fced165b37995aa5e05e6449b?s=32&d=identicon&r=PG' |
 anytopnm |
 tail -n +4 |
 perl -ne 'BEGIN{$/=\3}
   ($r,$g,$b)=unpack"C3";$ar+=$r;$ag+=$g;$ab+=$b
   END{printf "#%02x%02x%02x\n", $ar/$.,$ag/$.,$ab/$.}'

Which for your avatar (DevNoov avatar) gives: #c350c2 (some light magenta at the time of writing).

That assumes anytopnm always returns a PNM in P6 format. There might be cases where it doesn't such as when the image is grayscale, in which case convert - ppm:- from ImageMagick may be safer.

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501