0

写真モザイクは、既存の画像をサムネイルのモザイクとして再生成する手法です。元のピクセルの色は、カバー タイルの色にほぼ似ている必要があります。

たとえば、ロールプレイング ゲーマーは、ユーザーのサムネイル画像から世界地図を再生成しました

ここに画像の説明を入力

この画像のソース コードは githubで共有されていますが、特定の世界地図タスク用にかなり調整されています。

既存の画像を一連のサムネイルのコラージュ/モザイクとして再生成するための一般的な解決策はありますか?

4

1 に答える 1

3

bash画像処理作業を行う ImageMagick を使用した単純なスクリプトとして、概念実証が続きます。

#!/bin/bash

# Take all JPEGS in current directory and get their average RGB color and name in "tiles.txt"
for f in *.jpg; do 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 as original map
convert map.png -threshold 100% result.png

# Split map into tiles of 10x10 and get x,y coordinates of each tile and the 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; do
      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 actually but sqrt is 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

ここに画像の説明を入力

サムネイルの無限の供給はありませんが、コンセプトは機能しているようです. 色間の距離の計算は で行われawk、明らかに、より知覚的に均一な色空間で行うことができ、物事を大幅に高速化することもできます。繰り返しを避けるためのもう 1 つの考えは、タイルを似たような色にビン分けし、絶対的に最も近いビンではなく、最も近いビンからランダムに 1 つ取得することです。

ファイルtiles.txtは次のようになります。

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
...
...
于 2016-02-08T16:16:43.357 に答える