; Copyright (C) 2010 Paul Chown
;
; Version 1.0 09.03.2010
;
; Cleanup whiteboard photos to give a white background

(define (script-fu-whiteboard aimg adraw)
    (let* ((layercopy 0))
        (gimp-image-undo-group-start aimg)

        ; basic removal of background surface
        (set! layercopy (car (gimp-layer-copy adraw FALSE)))
        (gimp-image-add-layer aimg layercopy -1)
        (gimp-layer-set-mode layercopy DIVIDE-MODE)
        (plug-in-gauss 1 aimg layercopy 50 50 0)
        (set! layercopy (car (gimp-image-flatten aimg)))

        ; try to remove noise in the background
        (plug-in-sel-gauss 1 aimg layercopy 15 15)

        ; beef up the lines a bit
        ;(plug-in-despeckle 1 aimg layercopy 1 1 1 200)
        (plug-in-c-astretch 1 aimg layercopy)

        (gimp-image-undo-group-end aimg)
        (gimp-displays-flush)
    )
)

(script-fu-register "script-fu-whiteboard"
  _"_Whiteboard..."
  "Cleanup a whiteboard image"
  "Paul Chown"
  "Paul Chown"
  "09/03/2010"
  "*"
  SF-IMAGE       "Input image" 0
  SF-DRAWABLE    "Input drawable" 0
)

(script-fu-menu-register "script-fu-whiteboard"
                         "<Image>/Filters/Enhance")
