anchor.diff:  	)
   
   (defun f ()
  -   (setf canvas (load-painting "images/lenna.png"))
  -   (greyscale-image canvas)
  -   (setf canvas (dilate (discrete-convolve canvas *dilate*)
  -		(make-8-bit-rgb-image 3 3 :initial-element 8)))
  -   (threashold-image canvas 90)
  -   (write-image canvas "output/lenna_painting.png"))
  -   ;(filter "output/pacman_game_edge.png" "images/lenna.png" "output/lenna_painting.png"))
  +   ;(format t "Loading images...")
  +   ;(setf canvas (load-painting "images/lenna.png"))
  +   ;(setf source (load-painting "images/lenna.png"))
  +   ;(setf reference (load-painting "images/lenna.png"))
  +   ;(format t "Greyscale...")
  +   ;(greyscale-image canvas)
  +   ;(format t "Dilate...")
  +   ;(setf canvas (dilate (discrete-convolve canvas *dilate*)
  +	;	(make-8-bit-rgb-image 3 3 :initial-element 4)))
  +   ;(format t "Threashold...")
  +   ;(threashold-image canvas 90)
  +   ;(format t "Diffing...")
  +   ;(diff-stroke reference canvas)
  +
  +   ;(format t "Blur...")
  +   ;(setf reference (blur-image reference))
  +   ;(format t "Overlay...")
  +   ;(overlay-stroke source reference)
  +
  +   ;(format t "Write out...")
  +   ;(write-image reference "output/lenna_painting_r.png")
  +   ;(write-image canvas "output/lenna_painting_c.png")
  +   ;(write-image source "output/lenna_painting_s.png"))
  +   (filter-image "output/odetojoy_edge.png" "images/palm_beach.png" "output/palm_beach_odetojoy.png"))
      ;(filter "output/scream.png" "images/lenna.png" "output/lenna_painting_scream.png"))
   
   (defun s ()
      (stats))
   
  -(defun stats ()
  -   (setf blobs (label "output/scream.png"))
  -   (format t "Average size stroke ~S~%" (avg-l blobs))
  -   (format t "Minimum size stroke ~S~%" (min-l blobs))
  -   (format t "Maximum size stroke ~S~%" (max-l blobs))
  -   blobs)
  +(defun reduce-strokes (blobs)
  +   (setf blobs (cdr blobs))
  +   (setf blobs (cdr (reverse blobs)))
  +   (format t "~S~%" blobs)
  +   (setf strokes '())
  +   (setf strokes (append strokes (list (avg-l blobs))))
  +   (setf strokes (append strokes (list (/ (+ (avg-l blobs) (min-l blobs)) 2))))
  +   (setf strokes (append strokes (list (/ (+ (avg-l blobs) (max-l blobs)) 2))))
  +   (setf strokes(mapcar 'floor strokes))
  +   (sort strokes #'>)
  +   (format t "~S~%" strokes)
  +   strokes)
  
positive.code: (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 paint (source r)
     (setf r (remove-duplicates r))
     (format t "~S layers to paint~%" (length r))
     (setf source (load-painting source))
     (setf reference (copy-image source))
     (loop for i in r do
        (setf source (stroke source reference i))) source)
        ;(setf source (blur-image source))) source)
  
  (defun filter (filter input output)
     (format t "Labelling components~%")
     ;(setf blobs (label filter))
     (setf blobs '(255))
     (format t "Painting photo~%")
     (setf painting (paint input blobs))
     (write-image painting output))
  
  (defun e ()
  	(load 'fa.lisp)
  	(blob "images/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")
  
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
  