Comment detail

モノクロ画像の類似検索 (Nested Flatten)
Squeak Smalltalk で。001.png 〜 100.png から indexOfRef で指定した番号の画像とそれ以外とを比べ、その中で最も似ている画像の番号を返します。実行時間は 1 GHz PowerPC (Mac OS X) で 11.5 秒程度でした。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
| indexOfRef getImage refImage numOfImgs |
indexOfRef := 1.
numOfImgs := 100.

getImage := [:index |
    | name file |
    name := (index printPaddedWith: $0 to: 3), '.png'.
    file := FileStream fileNamed: name.
    file binary.
    (PNGReadWriter createAFormFrom: file contentsOfEntireFile) first].

refImage := getImage value: indexOfRef.

((1 to: numOfImgs) copyWithout: indexOfRef) detectMin: [:idx |
    (refImage deltaFrom: (getImage value: idx)) primCountBits]
Squeak Smalltalk のいったん読み込んでから一気に比較する版。選定にかかった時間(最後の式の処理時間)は 1 GHz PowerPC (Mac OS X) で 1 秒ほどでした。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
| indexOfRef refImage numOfImgs images |
indexOfRef := 1.
numOfImgs := 100.
images := (1 to: numOfImgs) collect: [:idx |
    | name file |
    name := (idx printPaddedWith: $0 to: 3), '.png'.
    file := FileStream fileNamed: name.
    file binary.
    (PNGReadWriter createAFormFrom: file contentsOfEntireFile) first].

refImage := images at: indexOfRef.

((1 to: numOfImgs) copyWithout: indexOfRef) detectMin: [:idx |
    (refImage deltaFrom: (images at: idx)) primCountBits]
参考まで、#deltaForm: の中身はビット列の XOR で、#primCountBits の中身は popCount です。いずれも、Smalltalk システム(暫定ダイナブック環境、あるいは ALTO コンピュータ)発祥ということでよく知られている BitBlt という機構が下請けています。http://ja.wikipedia.org/wiki/Bitblt

Index

Feed

Other

Link

Pathtraq

loading...