;; this example reads a black-and-white scanned document and extracts the ;; components which are roughly letter-sized (require-extension format) (require-extension leptonica) (require-extension srfi-42) (define original-pix (pix-read "feyn.tif")) (format #t "Size of original ~d x ~d, colour depth ~d bpp~&" (pix-get-width original-pix) (pix-get-height original-pix) (pix-get-depth original-pix)) (format #t "Image contains ~d components (by 8) and ~d (by 4)~&" (pix-count-conn-comp original-pix 8) (pix-count-conn-comp original-pix 4)) (format #t "Analysing by 8-wise connectivity~&") (let-values (((boxes images) (pix-conn-comp-pixa original-pix 8))) (when (eq? #f boxes) (error "Failure in identifying components")) (format #t "There are ~d boxes~&" (boxa-get-count boxes)) (do-ec (: i (boxa-get-count boxes)) (let ((box (boxa-get-box boxes i L-COPY))) (let-values (((x y w h) (box-get-geometry box))) ; constraint the size of image to save (when (and (> w 10) (< w 50) (> h 10) (< h 50)) (format #t "Box ~d at (~d, ~d) size ~d x ~d~&" i x y w h) (let ((pix (pixa-get-pix images i L-COPY))) (pix-write (string-concatenate (list "feyn-" (number->string i) ".png")) pix IFF-PNG)))))))