Advertisement
Guest User

Untitled

a guest
Oct 1st, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 3.09 KB | None | 0 0
  1. (define (add-background-layer
  2.     image
  3.     drawable
  4.     filltype
  5.     )
  6.  
  7.     (let (
  8.             ; Get the number of layers
  9.             (numLayers (car (gimp-image-get-layers image)))
  10.  
  11.             ; Make a new layer
  12.             (bgLayer (car (gimp-layer-new image
  13.                 1 1 RGB-IMAGE drawable 100 NORMAL-MODE )))
  14.         )
  15.  
  16.         ; Add to the image at the lowest postion
  17.         (gimp-image-add-layer image bgLayer numLayers )
  18.  
  19.         ; Resize to fit the image
  20.         (gimp-layer-resize-to-image-size bgLayer)
  21.  
  22.         ; Fill it with pure white
  23.         (gimp-drawable-fill bgLayer filltype)
  24.     )
  25. )
  26.  
  27.  
  28. (define (auto-figuier
  29.    input
  30.    output
  31.    )
  32.  
  33.    (let* (
  34.           (image (car (gimp-file-load RUN-NONINTERACTIVE input input)))
  35.           (drawable (car (gimp-image-get-active-layer image)))
  36.           (edge-layer 0)
  37.       )
  38.  
  39.      (add-background-layer image "White background" WHITE-FILL)
  40.  
  41.      (gimp-image-set-active-layer image drawable)
  42.      (gimp-layer-add-alpha drawable)
  43.  
  44.      ; Selective Gauss filter to blur the background
  45.      (plug-in-sel-gauss RUN-NONINTERACTIVE image drawable 10 10)
  46.  
  47.      ; Brighten reddish marks to have them removed with the background later
  48.      (gimp-by-color-select-full drawable '(216 187 129) 20 0 FALSE TRUE 3 3 FALSE FALSE SELECT-CRITERION-COMPOSITE)
  49.      (gimp-by-color-select-full drawable '(208 185 128) 15 CHANNEL-OP-INTERSECT FALSE TRUE 3 3 FALSE FALSE SELECT-CRITERION-S)
  50.      (gimp-brightness-contrast drawable 50 0)
  51.      (gimp-selection-none image)
  52.  
  53.      (plug-in-unsharp-mask RUN-NONINTERACTIVE image drawable 5 0.20 20)
  54.      (gimp-brightness-contrast drawable 40 15)
  55.  
  56.     ; Attempt to remove darker characters impressed from the page in front of while preserving light edges
  57.      (set! edge-layer (car (gimp-layer-copy drawable FALSE)))
  58.      (gimp-image-add-layer image edge-layer -1)
  59.      (gimp-layer-set-name edge-layer "Edge")
  60.      (gimp-image-lower-layer image edge-layer) (gimp-image-lower-layer image edge-layer)
  61.      (gimp-layer-flatten edge-layer)
  62.      (plug-in-dog RUN-NONINTERACTIVE image edge-layer 1 4 TRUE FALSE)
  63.      (gimp-image-set-active-layer image drawable)
  64.      (gimp-by-color-select-full edge-layer '(0 0 0) 5 0 TRUE TRUE 2 2 FALSE FALSE SELECT-CRITERION-COMPOSITE)
  65.      (gimp-by-color-select-full drawable '(236 226 186) 12 CHANNEL-OP-INTERSECT TRUE TRUE 2 2 FALSE FALSE SELECT-CRITERION-COMPOSITE)
  66.      (gimp-edit-clear drawable)
  67.      (gimp-image-remove-layer image edge-layer)
  68.      (gimp-image-set-active-layer image drawable)
  69.  
  70.      ; Remove the old book background
  71.      (for-each (lambda (x)
  72.          (gimp-by-color-select-full drawable x 12 0 TRUE TRUE 3 3 FALSE FALSE SELECT-CRITERION-COMPOSITE)
  73.          (gimp-edit-clear drawable)
  74.          (gimp-selection-none image))
  75.           (list '(252 242 203) '(255 246 223) '(255 255 241)) ; List of colors to look for, may need tweaking
  76.      )
  77.  
  78.      (gimp-desaturate drawable)
  79.  
  80.      (gimp-image-flatten image)
  81.      (gimp-file-save RUN-NONINTERACTIVE image (car (gimp-image-get-active-layer image)) output output)
  82.      (gimp-image-delete image)
  83.   )
  84. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement