(load "assert.scm")
(load "ones.scm")
(load "stream-add.scm")
(load "stream-scale.scm")
(load "stream-delay.scm")
(load "stream-smooth.scm")
(load "stream-edges.scm")
(load "pnm.scm")
(define (filter-image-rows img filter)
(if (null? img)
'()
(cons-stream (filter (stream-car img))
(filter-image-rows (stream-cdr img) filter))))
(define (img-horiz-smooth img)
(filter-image-rows img stream-smooth))
(define (image-map proc img)
(if (null? img)
'()
(cons-stream (stream-map proc (stream-car img))
(image-map proc (stream-cdr img)))))
(define (clamp-image img)
(image-map (lambda (x) (min 1. x))
(image-map (lambda (x) (max 0. x)) img)))
(define img (pgm-file->image "hitchhiker-orig.pgm"))
(image->pgm-file img "hitchhiker-rewrite.pgm")
(image->pgm-file (clamp-image (img-horiz-smooth img)) "hitchhiker-smoothed.pgm")
(image->pgm-file (clamp-image (img-horiz-smooth (img-horiz-smooth
(img-horiz-smooth (img-horiz-smooth (img-horiz-smooth (img-horiz-smooth
(img-horiz-smooth img)))))))) "hitchhiker-super-smoothed.pgm")
(define (img-vert-edges img)
(filter-image-rows img stream-edges))
(image->pgm-file (clamp-image (img-vert-edges img)) "hitchhiker-vedges.pgm")
(define (mystery stream)
(if (null? stream) '()
(cons-stream
(stream-car stream)
(cons-stream
(stream-car stream)
(mystery (stream-cdr stream))))))
(define (image-mystery img)
(filter-image-rows img mystery))
(image->pgm-file (image-mystery img) "hitchhiker-zmystery.pgm")
(image->pgm-file (mystery (image-mystery img)) "hitchhiker-zmystery2.pgm")