Optical Object Recognition Example

This simple example demonstrates how easily object recognition and image processing applications can be implemented in Inlab Scheme. Given is the following input bitmap, an excerpt of a high quality scan at a resolution of 300DPI:

Input Image

The code below looks for the following search pattern, an “e”:

Lookup Pattern

This is the Inlab Scheme program that analyses each object in the input bitmap returning the number of actually found matching objects. The number of found objects is displayed and a output bitmap is generated that contains the objects that match the search criteria (of being at least 85% equal in the sense of “bitmap-equality” after resizing to 100×100) unchanged and all other objects in grey:


(define cbitmap (bitmap-readxbm "pattern.xbm"))  ;; pattern to search
 (define bitmap (bitmap-readxbm "input.xbm"))    ;; input to analyze
 (define objects (bitmap-explode bitmap))        ;; explode input
 (define mcount 0)                               ;; number of matching objects
 (define object-list '())                        ;; initialize list of objects

  (length objects)
    " objects in input.xbm")

  (lambda (object)
        (bitmap-scale-absolute object 100 100))
    (if (> (bitmap-equality sobject cbitmap) 0.85)
        (set! mcount (+ mcount 1))
        (set! object-list
          (cons object object-list)))
        (bitmap-grey! object)
        (set! object-list
          (cons object object-list)))))

(writeln mcount " matching objects found")

;; generate output-bitmap and write it to output.xbm

 (bitmap-implode object-list
 (bitmap-height bitmap)
 (bitmap-width bitmap))


A run of the program leads to the following output:

57 objects in input.xbm
7 matching objects found

output.xbm looks now like the following and finally indicates the found objects in black:

Output Image with recognised Patterns marked

The running time was 1.1 seconds on an old Pentium90 running FreeBSD 2.1.5 including initialisation of Inlab Scheme which took about 0.2 seconds on this platform (A pentium pro 200 running FreeBSD 2.1.5 needed about 0.44 seconds including 0.05 seconds to initialise).