image - Generate a Photographic mosaic from a given set of thumbnails -
photographic mosaic technique of re-generating existing image mosaic of thumbnails. color of original pixels should resemble color of covering tile.
for example, role-playing gamer re-generated world map thumbnail images of users.
the source code image shared on github, it's pretty tailored specific world-map task.
is there general solution re-generating existing image collage/mosaic of set of given thumbnails?
proof of concept follows, simple bash
script imagemagick image processing work.
#!/bin/bash # take jpegs in current directory , average rgb color , name in "tiles.txt" f in *.jpg; convert $f -depth 8 -resize 1x1! -format "%[fx:int(mean.r*255)] %[fx:int(mean.g*255)] %[fx:int(mean.b*255)] $f\n" info: ; done > tiles.txt # create empty black output canvas same size original map convert map.png -threshold 100% result.png # split map tiles of 10x10 , x,y coordinates of each tile , average rgb colour convert map.png -depth 8 -crop 10x10 -format "%x %y %[fx:int(mean.r*255)] %[fx:int(mean.g*255)] %[fx:int(mean.b*255)]\n" info: | while read x y r g b; thumb=$(awk -v r=$r -v g=$g -v b=$b ' nr==1{nearest=3*255*255*255;tile=$4} { tr=$1;tg=$2;tb=$3 # calculate distance (squared sqrt slow) d=((r-tr)*(r-tr))+((g-tg)*(g-tg))+((b-tb)*(b-tb)) if(d<nearest){nearest=d;tile=$4} } end{print tile} ' tiles.txt) echo $x $y $r $g $b $thumb convert result.png -draw "image copy $x,$y 10,10 \"$thumb\"" result.png done
i don't have endless supply of thumbnails concept seems work. maths of distance between colours done in awk
, done in more perceptually uniform colorspace , things speeded considerably. thought, avoid repetition, might bin tiles similar colours , take 1 @ random nearest bin rather absolute nearest one.
the file tiles.txt
looks this:
111 116 109 0.jpg 82 88 81 1.jpg 112 110 95 10.jpg 178 154 150 100.jpg 190 169 163 101.jpg 187 166 163 102.jpg ... ...
Comments
Post a Comment