home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
vis-ftp.cs.umass.edu
/
vis-ftp.cs.umass.edu.tar
/
vis-ftp.cs.umass.edu
/
pub
/
Software
/
ASCENDER
/
ascendMar8.tar
/
UMass
/
Epipolar
/
epimatch.lisp
< prev
next >
Wrap
Lisp/Scheme
|
1994-01-29
|
7KB
|
207 lines
;;; EPIMATCH.LISP
;;;
;;; Top-level routines for epipolar line matching
;;;
;;; Author: Robert T. Collins
;;; Date: Mar 1, 1995
;;; based on my earlier epipolar.lisp, written Dec 28, 1993
;;;
;-----------------------------------------------------------------
; (c) Copyright 1995 by The University of Massachusetts
;------------------------------------------------------------------
(in-package 'epipolar :nicknames '(epi))
;;;;================================================================
;;;; INITIALIZE MATCHING SYSTEM
(defun init-epipolar-histograms (&optional (numbuckets *num-z-buckets*)
(lowvalue *lowz*) (highvalue *highz*))
(setf *current-histogram*
(init-height-histogram numbuckets lowvalue highvalue))
(setf *accum-histogram*
(init-height-histogram numbuckets lowvalue highvalue))
t)
(defun init-epipolar-matcher (all-views)
(init-epipolar-histograms)
(when *demo-mode*
(init-epipolar-screens all-views)))
;;;;================================================================
;;;; MULTI-IMAGE EPIPOLAR MATCHING
(defstruct (epimatch (:print-function print-epimatch-struct))
(reference-view nil)
(line-list nil)
(rough-zvalue nil)
(list-of-viewmatches nil)
(peak-confidence nil))
(defun print-epimatch-struct (epimatch stream &rest ignore)
ignore
(format stream "<EPIMATCH ~a>"
(view-label (epimatch-reference-view epimatch))))
(defstruct viewmatch
(view nil)
(match-list nil))
(defun generate-indices (low high)
(let ((result nil))
(do ((i high (- i 1)))
((<= i low) (push low result))
(push i result))))
(defun interpolate-peak (histogram &optional
(peak-index (hist::find-highest-peak histogram)))
(let* ((array (hist::histogram-array histogram))
(min-index (max (- peak-index 1) 0))
(max-index (min (+ peak-index 1) (- (length array) 1)))
(sum 0.0)
(sum-weights 0.0)
(numbuckets (+ 1 (- max-index min-index))))
(dotimes (i numbuckets)
(incf sum-weights (aref array (+ i min-index)))
(incf sum (* (aref array (+ i min-index))
(hist::index-to-value histogram (+ i min-index)))))
(values
(if (zerop sum-weights) -9999.9 (/ sum sum-weights))
(aref array peak-index)
(generate-indices min-index max-index))))
(defun epipolar-match-linelist (reference-view linelist other-view-list
&key (endpoint-slop 1.0)(delta-theta .1)
&aux save-pause-mode)
(when *demo-mode*
(setf save-pause-mode *pause-mode*)
(let ((window (view-window reference-view)))
(activate-window window)
(let ((minx (reduce #'min linelist :key #'car))
(miny (reduce #'min linelist :key #'cadr))
(maxx (reduce #'max linelist :key #'car))
(maxy (reduce #'max linelist :key #'cadr)))
(cme::zoom-to-bounding-box window minx miny maxx maxy 10))
(dolist (line linelist)
(display-line window (car line) (cadr line) (third line) (fourth line)
:color *match-color* :thickness *match-thickness*))))
(clear-height-histogram *accum-histogram*)
(dolist (other-view other-view-list)
(clear-height-histogram *current-histogram*)
(histogram-linelist-candidates
reference-view linelist other-view
:histogram *current-histogram*
:deltatheta delta-theta
:endpoint-slop endpoint-slop
:peak-weight? t)
(add-to-height-histogram *accum-histogram* *current-histogram*)
(when *demo-mode*
(synch-epipolar-screen (view-window other-view))
(when (eq *pause-mode* :views)
(setf *pause-mode*
(and (yes-or-no-p "Pause between views?") :views))))
; (plot-histogram *plot1* *accum-histogram* :max 3)
)
(setf *pause-mode* :views)
(let* ((peak-index (hist::find-highest-peak *accum-histogram*))
(epimatch (make-epimatch :reference-view reference-view
:line-list linelist
:list-of-viewmatches nil))
(halfwidth (/ (hist::histogram-bucket-width *accum-histogram*) 2.0))
(zpeak nil)
(zconf nil))
(multiple-value-setq (zpeak zconf)
(interpolate-peak *accum-histogram* peak-index))
(setf (epimatch-rough-zvalue epimatch) zpeak)
; Normalized by number of edges, Jan. 30, 1996
(setf (epimatch-peak-confidence epimatch) (/ zconf (length linelist)))
(dolist (view other-view-list)
(push (make-viewmatch
:view view
:match-list
(collect-linelist-matches
reference-view linelist view
:lowz (- zpeak halfwidth) :highz (+ zpeak halfwidth)
:midz zpeak
:deltatheta delta-theta
:endpoint-slop endpoint-slop
:only-display-matches t))
(epimatch-list-of-viewmatches epimatch))
(when *demo-mode*
(synch-epipolar-screen (view-window view))
(when *pause-mode*
(setf *pause-mode*
(yes-or-no-p "Pause between views?")))))
(setf *pause-mode* save-pause-mode)
epimatch))
(defun count-matchlist-numlines (matchlist)
(apply #'+ (mapcar #'(lambda (x) (length (cadr x))) matchlist)))
(defun write-proj-info (file view)
(ecase (intern (format nil "~a" (type-of (view-projection view))) :keyword)
(:FAST-BLOCK-INTERPOLATION-PROJECTION
(format file "1~%~a~%" (view-projfile view))
(format file "0~%"))
(:COMPOSITE-COORDINATE-PROJECTION
(format file "1~%~a~%" (view-projfile view))
(format file "0~%"))
(:4X4-COORDINATE-PROJECTION
(format file "0~%")
(format file "1~%")
(let ((mat (cme::projection-matrix (view-projection view))))
(dotimes (i 4)
(dotimes (j 4)
(format file " ~,8f" (aref mat i j)))
(format file "~%"))))))
(defun save-matches-to-file (epimatch filename)
(let ((linelist (epimatch-line-list epimatch))
(refview (epimatch-reference-view epimatch))
(zvalue (epimatch-rough-zvalue epimatch))
(list-of-matches (epimatch-list-of-viewmatches epimatch)))
(with-open-file (file filename :direction :output)
;;number of lines followed by initial estimates of each (two 3d endpoints)
(format file "~d~%" (length linelist)) ;number of polygon lines
(let ((refproj (view-projection refview)))
(dolist (line linelist)
(let ((x1y1 (backproject-point
refproj (car line) (cadr line) zvalue))
(x2y2 (backproject-point
refproj (third line) (fourth line) zvalue)))
(format file "~,3f ~,3f ~,3f ~,3f ~,3f ~,3f~%"
(car x1y1) (cadr x1y1) zvalue
(car x2y2) (cadr x2y2) zvalue))))
;;number of images
(format file "~d~%" (+ 1 (length list-of-matches))) ;number of images
;;first image is the reference view
(write-proj-info file refview)
(format file "~d~%" (length linelist))
(dotimes (i (length linelist))
(let ((line (elt linelist i)))
(format file "~d ~,3f ~,3f ~,3f ~,3f~%" ;write one line match
(+ 1 i) (car line) (cadr line) (third line) (fourth line))))
(dolist (match (reverse list-of-matches))
(write-proj-info file (viewmatch-view match))
(format file "~d~%" ;number of line matches
(count-matchlist-numlines (viewmatch-match-list match)))
(dolist (linematch (viewmatch-match-list match))
(let ((index (car linematch)))
(dolist (line (cadr linematch))
(let ((pt1 (car line))
(pt2 (cadr line)))
(format file "~d ~,3f ~,3f ~,3f ~,3f~%" ;write one line match
index (car pt1) (cadr pt1) (car pt2) (cadr pt2))))))))))