(use-modules (aiscm magick) (aiscm image) (aiscm core))
(define (to-gray img) (from-image (convert-image (to-image img) 'GRAY)))
(define (norm x y) (/ (+ (abs x) (abs y)) 8))
(define (sobel img) (norm (convolve img (arr (1 0 -1) (2 0 -2) ( 1 0 -1))) (convolve img (arr (1 2 1) (0 0 0) (-1 -2 -1)))))
(write-image (to-type <ubyte> (sobel (to-gray (read-image "star-ferry.jpg")))) "sobel.jpg")
