This comment is reply for 1750 shiro: > なお、ファイルの読み込みに1....(モノクロ画像の類似検索). Go to thread root.
shiro #1755(2007/08/03 02:43 GMT) [ Scheme ] Rating0/0=0.00
むむ。他の動的言語(PnutsやScala)がけっこういけてますね。闘志に火がつきました。 uniform vectorの組込み演算を使って0.87秒 (Pen4 2.0GHz)。オンメモリのデータで。 gosh> (time (find-closest-pic (ref *vecs* 35) *vecs*) ) ;(time (find-closest-pic (ref *vecs* 35) *vecs*)) ; real 0.873 ; user 0.870 ; sys 0.000 392016
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
(use gauche.uvector) (use gauche.sequence) (use srfi-42) (define-constant *image-size* (* 1024 768)) (define (find-closest-pic vs pics) (define (diff-score vp vs) (let1 vx (u8vector-xor vp vs) (+ (u8vector-dot v1 (u8vector-and vx #x01)) (/ (u8vector-dot v1 (u8vector-and vx #x02)) 2) (/ (u8vector-dot v1 (u8vector-and vx #x04)) 4) (/ (u8vector-dot v1 (u8vector-and vx #x08)) 8) (/ (u8vector-dot v1 (u8vector-and vx #x10)) 16) (/ (u8vector-dot v1 (u8vector-and vx #x20)) 32) (/ (u8vector-dot v1 (u8vector-and vx #x40)) 64) (/ (u8vector-dot v1 (u8vector-and vx #x80)) 128)))) (define v1 (make-u8vector (/ *image-size* 8) 1)) (values-ref (fold2 (lambda (vp score ans) (cond [(eq? vs vp) (values score ans)] [else (let1 s (diff-score vp vs) (if (< s score) (values s vp) (values score ans)))])) #i1/0 #f pics) 0)) ;; (find-closest-pic "pic035" (sys-glob "pic???")) ;; => 392118 and "pic064" ;;; ;;; test data generation ;;; (use srfi-27) (define (generate-random-pics n) (list-ec (: k n) (let1 v (make-u8vector (/ *image-size* 8)) (do-ec (: i (/ *image-size* 8)) (u8vector-set! v i (random-integer (expt 2 8)))) v))) (define *vecs* (generate-random-pics 100))
Rating0/0=0.00-0+
[ reply ]
shiro
#1755()
[
Scheme
]
Rating0/0=0.00
Rating0/0=0.00-0+