> (define pcb (read-image "pcb1.pgm"))
> pcb
#
>
> (define thresholded-pcb (> pcb 64))
> thresholded-pcb
#
>
> (define (paint-components labeled v)
(image-map (lambda (x) (vector-ref v x)) labeled))
>
> (define (area-image labeled)
(paint-components labeled (areas labeled)))
>
> (define holes (< (area-image (label (= thresholded-pcb 0))) 40))
> holes
#
>
> (define (make-overlay A r g b)
(let ((B (outline A)))
(rgb->color-image (* r B) (* g B) (* b B))))
>
> (define hole-overlay (make-overlay holes 1 1 0))
> hole-overlay
#
>
> (define filled-holes-pcb (+ holes thresholded-pcb))
> filled-holes-pcb
#
>
> (define rectangular-pads (open filled-holes-pcb (make-vector 11 (make-vector 27 1))))
> rectangular-pads
#
>
> (define rectangular-pad-overlay (make-overlay rectangular-pads 1 0 0))
> rectangular-pad-overlay
#
>
> (define square-pads (open filled-holes-pcb (make-vector 17 (make-vector 17 1))))
> square-pads
#
> (define square-pads-overlay (make-overlay square-pads 0 1 0))
> square-pads-overlay
#
> (define circle
(lambda (x y rr)
(lambda (i j)
(if (<= (+ (* (- x i) (- x i)) (* (- y j) (- y j))) rr) 1 0))))
>
> (define circular-pad (image->array (make-image 19 19 (circle 9 9 79))))
> (array->image circular-pad)
#
>
> (open filled-holes-pcb circular-pad)
#
>
> (define no-square-pads (* (= square-pads 0) filled-holes-pcb))
> no-square-pads
#
>
> (define circular-pads (open no-square-pads circular-pad))
> circular-pads
#
>
> (define circular-pad-overlay (make-overlay circular-pads 0 0 1))
> circular-pad-overlay
#
>
> (define no-pads (= (+ rectangular-pads square-pads circular-pads) 0))
> no-pads
#
>
> (define eroded-no-pads (erode no-pads #(#(1 1 1) #(1 1 1) #(1 1 1))))
> eroded-no-pads
#
>
> (define wires (* eroded-no-pads filled-holes-pcb))
> wires
#
>
> (define wire-overlay (make-overlay wires 1 0 1))
> wire-overlay
#
>
> (define (color-image+ . args)
(define (helper x y)
(apply
rgb->color-image
(map + (color-image->rgb x) (color-image->rgb y))))
(if (null? (cdr args))
(car args)
(helper (car args)
(apply color-image+ (cdr args)))))
>
> (color-image+ rectangular-pad-overlay square-pad-overlay circular-pad-overlay wire-overlay hole-overlay)
#
>