Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define (add-background-layer
- image
- drawable
- filltype
- )
- (let (
- ; Get the number of layers
- (numLayers (car (gimp-image-get-layers image)))
- ; Make a new layer
- (bgLayer (car (gimp-layer-new image
- 1 1 RGB-IMAGE drawable 100 NORMAL-MODE )))
- )
- ; Add to the image at the lowest postion
- (gimp-image-add-layer image bgLayer numLayers )
- ; Resize to fit the image
- (gimp-layer-resize-to-image-size bgLayer)
- ; Fill it with pure white
- (gimp-drawable-fill bgLayer filltype)
- )
- )
- (define (auto-figuier
- input
- output
- )
- (let* (
- (image (car (gimp-file-load RUN-NONINTERACTIVE input input)))
- (drawable (car (gimp-image-get-active-layer image)))
- (edge-layer 0)
- )
- (add-background-layer image "White background" WHITE-FILL)
- (gimp-image-set-active-layer image drawable)
- (gimp-layer-add-alpha drawable)
- ; Selective Gauss filter to blur the background
- (plug-in-sel-gauss RUN-NONINTERACTIVE image drawable 10 10)
- ; Brighten reddish marks to have them removed with the background later
- (gimp-by-color-select-full drawable '(216 187 129) 20 0 FALSE TRUE 3 3 FALSE FALSE SELECT-CRITERION-COMPOSITE)
- (gimp-by-color-select-full drawable '(208 185 128) 15 CHANNEL-OP-INTERSECT FALSE TRUE 3 3 FALSE FALSE SELECT-CRITERION-S)
- (gimp-brightness-contrast drawable 50 0)
- (gimp-selection-none image)
- (plug-in-unsharp-mask RUN-NONINTERACTIVE image drawable 5 0.20 20)
- (gimp-brightness-contrast drawable 40 15)
- ; Attempt to remove darker characters impressed from the page in front of while preserving light edges
- (set! edge-layer (car (gimp-layer-copy drawable FALSE)))
- (gimp-image-add-layer image edge-layer -1)
- (gimp-layer-set-name edge-layer "Edge")
- (gimp-image-lower-layer image edge-layer) (gimp-image-lower-layer image edge-layer)
- (gimp-layer-flatten edge-layer)
- (plug-in-dog RUN-NONINTERACTIVE image edge-layer 1 4 TRUE FALSE)
- (gimp-image-set-active-layer image drawable)
- (gimp-by-color-select-full edge-layer '(0 0 0) 5 0 TRUE TRUE 2 2 FALSE FALSE SELECT-CRITERION-COMPOSITE)
- (gimp-by-color-select-full drawable '(236 226 186) 12 CHANNEL-OP-INTERSECT TRUE TRUE 2 2 FALSE FALSE SELECT-CRITERION-COMPOSITE)
- (gimp-edit-clear drawable)
- (gimp-image-remove-layer image edge-layer)
- (gimp-image-set-active-layer image drawable)
- ; Remove the old book background
- (for-each (lambda (x)
- (gimp-by-color-select-full drawable x 12 0 TRUE TRUE 3 3 FALSE FALSE SELECT-CRITERION-COMPOSITE)
- (gimp-edit-clear drawable)
- (gimp-selection-none image))
- (list '(252 242 203) '(255 246 223) '(255 255 241)) ; List of colors to look for, may need tweaking
- )
- (gimp-desaturate drawable)
- (gimp-image-flatten image)
- (gimp-file-save RUN-NONINTERACTIVE image (car (gimp-image-get-active-layer image)) output output)
- (gimp-image-delete image)
- )
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement