anchor.diff:  (defun scale (max min l)
      (float (+ (/ l max) (/ l min))))
   
  -(defun stroke (source reference stroke)
  -   ;(with-image-bounds (height width) reference
  -   ;   (setf stroke (floor (* stroke (scale width height stroke)))))
  -   ;(format t "painting ~S sized strokes~%" stroke)
  -   (setf canvas (copy-image reference))
  -   ;(threashold-image-colour canvas stroke)
  -   (setf canvas (erode (discrete-convolve canvas *edge-kernel*)
  -		(make-8-bit-rgb-image 3 3 :initial-element 3)))
  -   ;(setf canvas (blur-image canvas))
  -   ;(overlay-stroke reference canvas) reference)
  -   canvas)
  +(defun scale-stroke (max min s)
  +   (if (< (scale max min s) 1)
  +      (floor (* s (scale max min s)))
  +      (floor (float (+ (scale max min s) 8)))))
  +
  +(defun circle-stroke (img ref ss x y)
  +   (typecase img
  +      (8-bit-rgb-image
  +         (locally (declare (type 8-bit-rgb-image img))
  +            (with-image-bounds (height width) img)
  +               (multiple-value-bind (r g b)
  +                  (if (and (>= ss 8) (<= 200))
  +                     (pixel ref x y)
  +                     (pixel img x y))
  +                  ;(format t "~%~S,~S,~S~%" r g b)
  +                  (fill-circle img x y ss r g b))))))
  +
  +(defun stroke (source reference stroke-size)
  +   ;(setf canvas (copy-image source))
  +   ;(greyscale-image canvas)
  +   ;(format t ".")
  +   ;(if (< stroke-size 255)
  +   ;   (setf canvas (dilate (discrete-convolve canvas *dilate*)
  +   ;		(make-8-bit-rgb-image stroke-size stroke-size :initial-element stroke-size)))
  +   ;   (threashold-image-colour canvas (ceiling (/ stroke-size 255))))
  +   ;(format t ".")
  +   ;(threashold-image canvas 90)
  +   ;(format t ".")
  +
  +
  +   ;(format t ".")
  +   ;(if (> stroke-size 255)
  +   ;   (loop for i below (ceiling (/ stroke-size 255)) do
  +   ;      (setf reference (blur-image reference)))
  +   ;   (diff-stroke reference canvas))
  +   (typecase source
  +      (8-bit-rgb-image
  +         (locally (declare (type 8-bit-rgb-image source))
  +            (with-image-bounds (height width) source
  +               (format t "." stroke-size)
  +               (loop for i below (/ (+ width height) 2) do
  +                  (circle-stroke source reference stroke-size (random height) (random width))))))))
  +
  +   ;(format t ".")
  +   ;(setf reference (blur-image reference))
  +
  +   ;(format t ".")
  +   ;(overlay-stroke source reference) source)
   
   (defun paint (source r)
  -   (setf r (remove-duplicates r))
  +   (format t "Painting ~S~%" source)
      (format t "~S layers to paint~%" (length r))
      (setf source (load-painting source))
      (setf reference (copy-image source))
  +   ;(format t "~S" blobs)
      (loop for i in r do
  -      (setf source (stroke source reference i))) source)
  +      (format t "~S" i)
  +      (stroke source reference i)) source)
         ;(setf source (blur-image source))) source)
   
  -(defun filter (filter input output)
  +(defun filter-image (filter input output)
      (format t "Labelling components~%")
  -   ;(setf blobs (label filter))
  -   (setf blobs '(255))
  +   (setf blobs (reduce-strokes (label filter)))
  +   ;(setf blobs '(8 4))
      (format t "Painting photo~%")
      (setf painting (paint input blobs))
  +   ;(format t "Determining the average colour~%")
  +   ;(setf col (k-means-cluster-image-pixels (load-painting input) 2))
  +   ;(format t "~S~%" col)
  +   ;(format t "filling image~%")
  +   ;(fill-image bg (aref col 0 0 0) (aref col 0 0 1) (aref col 0 0 2))
  +   ;(format t "overlaying image~%")
  +   ;(overlay-bg painting bg)
  +   (format t "writing image~%")
      (write-image painting output))
   
   (defun e ()
   	(load 'fa.lisp)
  -	(blob "images/starry_night.png" "output/starry_night_edge.png")
  +	(blob "paintings/starry_night.png" "output/starry_night_edge.png")
   	;(edge "images/odetojoy.png" "output/odetojoy_edge.png")
   	;(edge "images/the_scream.png" "output/scream_edge.png")
   	;(edge "images/odetojoy.png" "output/odetojoy_edge.png")
  
positive.code: (defun write-image (img name)
  	(write-png-file name img))
  
  (defun 4-neighbors (img i j)
     (declare (type fixnum i j))
        (with-image-bounds (height width)
  
negative.code:                            (pixel source i j)
                             (declare (type (unsigned-byte 8) r1 g1 b1))
                             (setf grey (floor (/ (+ r g b) 3)))
                             (if (>= grey 12) ;; used for now, needs to be something later
                                (setf (pixel source i j)
                                   (values r1 g1 b1))
                                (setf (pixel source i j)
                                   (values r g b))))))))))))
  ;; Takes a set of brush strokes and overlays them on top of a source
  (defun overlay-bg (source strokes)
     (typecase source
        (8-bit-rgb-image
           (locally (declare (type 8-bit-rgb-image source))
              (with-image-bounds (height width) source
                 (loop for i below height do
                    (loop for j below width do
                       (multiple-value-bind (r g b)
                          (pixel strokes i j)
                          (declare (type (unsigned-byte 8) r g b))
                          (multiple-value-bind (r1 g1 b1)
                             (pixel source i j)
                             (declare (type (unsigned-byte 8) r1 g1 b1))
                             (setf grey (floor (/ (+ r1 g1 b1) 3)))
                             (if (<= grey 24) ;; used for now, needs to be something later
                                (setf (pixel source i j)
                                   (values r g b))
                                (setf (pixel source i j)
                                   (values r1 g1 b1))))))))))))
  
  ;;; Takes a set of strokes in colour 255 and diffs them to the same source
  (defun diff-stroke (source strokes)
     (typecase source
        (8-bit-rgb-image
           (locally (declare (type 8-bit-rgb-image source))
              (with-image-bounds (height width) source
                 (loop for i below height do
                    (loop for j below width do
                       (multiple-value-bind (r g b)
                          (pixel strokes i j)
                          (declare (type (unsigned-byte 8) r g b))
                          (multiple-value-bind (r1 g1 b1)
                             (pixel source i j)
                             (declare (type (unsigned-byte 8) r1 g1 b1))
                             (if (eq r 255)
                                (setf (pixel source i j)
                                   (values r1 g1 b1))
                                (setf (pixel source i j)
                                   (values 0 0 0))))))))))))
  
  
  (defun invert-greyscale (img)
     (typecase img
        (8-bit-rgb-image
           (locally (declare (type 8-bit-rgb-image img))
              (with-image-bounds (height width) img
                 (loop for i below height do
                    (loop for j below width do
                       (multiple-value-bind (r g b)
                          (pixel img i j)
                          (declare (type (unsigned-byte 8) r g b))
                          (if (eq r 0) (setf v 255))
                          (if (eq r 255) (setf v 0))
                          (setf (pixel img i j)
                             (values v v v))))))))))
  
  ;; Sums an array
  ; https://faculty.washington.edu/ikalet/courses/lisp/code/arrays.cl
  