Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; Place the script in ~/.gimp/scripts, then invoke with:
- ;; gimp -i -b '(auto-figuier <input file> <output file>)' -b ‘(gimp-quit 0)’
- (define (figuier
- image
- drawable
- )
- (let* (
- (edge-layer 0)
- (nonedge-selection -1)
- )
- (let (
- (numlayers (car (gimp-image-get-layers image)))
- (bglayer (car (gimp-layer-new image
- 1 1 RGB-IMAGE "White background" 100 NORMAL-MODE)))
- )
- (gimp-image-add-layer image bglayer numlayers )
- (gimp-layer-resize-to-image-size bglayer)
- (gimp-drawable-fill bglayer WHITE-FILL)
- )
- (gimp-image-set-active-layer image drawable)
- (gimp-layer-add-alpha drawable)
- ; Selective Gauss filter to blur the background only
- (plug-in-sel-gauss RUN-NONINTERACTIVE image drawable 10 10)
- ; Setup a selection mask to preserve 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 "Edges")
- (gimp-image-lower-layer image edge-layer) (gimp-image-lower-layer image edge-layer)
- (gimp-layer-flatten edge-layer)
- (plug-in-edge RUN-NONINTERACTIVE image edge-layer 1 2 4)
- (gimp-image-set-active-layer image drawable)
- (gimp-by-color-select-full edge-layer '(0 0 0) 8 0 TRUE TRUE 2 2 FALSE FALSE SELECT-CRITERION-COMPOSITE)
- (gimp-by-color-select-full edge-layer '(4 6 16) 20 CHANNEL-OP-ADD TRUE FALSE 0 0 FALSE FALSE SELECT-CRITERION-COMPOSITE)
- (gimp-selection-grow image 1)
- (set! nonedge-selection (car (gimp-selection-save image)))
- ; Brighten reddish marks to have them removed with the background later
- (gimp-image-set-active-layer image drawable)
- (gimp-by-color-select-full drawable '(230 200 150) 22 CHANNEL-OP-REPLACE FALSE TRUE 2 2 FALSE FALSE SELECT-CRITERION-COMPOSITE)
- (gimp-by-color-select-full drawable '(216 177 104) 30 CHANNEL-OP-ADD FALSE TRUE 2 2 FALSE FALSE SELECT-CRITERION-COMPOSITE)
- (gimp-by-color-select-full drawable '(182 158 98) 3 CHANNEL-OP-ADD FALSE TRUE 2 2 FALSE FALSE SELECT-CRITERION-COMPOSITE)
- (gimp-by-color-select-full drawable '(221 197 134) 3 CHANNEL-OP-ADD FALSE TRUE 2 2 FALSE FALSE SELECT-CRITERION-COMPOSITE)
- (gimp-image-select-item image CHANNEL-OP-INTERSECT nonedge-selection)
- (gimp-brightness-contrast drawable 100 0)
- ; Sharpening filter
- (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 facing page
- (gimp-by-color-select-full drawable '(236 226 186) 12 CHANNEL-OP-REPLACE TRUE TRUE 6 6 FALSE FALSE SELECT-CRITERION-COMPOSITE)
- (gimp-image-select-item image CHANNEL-OP-INTERSECT nonedge-selection)
- (gimp-edit-clear drawable)
- ; Remove the old book background
- (for-each (lambda (x)
- (gimp-by-color-select-full drawable x 12 CHANNEL-OP-REPLACE TRUE TRUE 4 4 FALSE FALSE SELECT-CRITERION-COMPOSITE)
- (gimp-image-select-item image CHANNEL-OP-INTERSECT nonedge-selection)
- (gimp-edit-clear drawable))
- (list '(252 242 203) '(255 246 223) '(255 255 241)) ; List of colors to look for, may need tweaking
- )
- (gimp-image-remove-layer image edge-layer)
- (gimp-image-set-active-layer image drawable)
- (gimp-selection-none image)
- (gimp-desaturate drawable)
- (gimp-image-convert-grayscale image)
- (gimp-image-flatten image)
- (gimp-displays-flush)
- )
- )
- (define (auto-figuier
- input
- output
- )
- (let* (
- (image (car (gimp-file-load RUN-NONINTERACTIVE input input)))
- (drawable (car (gimp-image-get-active-layer image)))
- )
- (figuier image drawable)
- (gimp-file-save RUN-NONINTERACTIVE image (car (gimp-image-get-active-layer image)) output output)
- (gimp-image-delete image)
- )
- )
- (gimp-plugin-menu-branch-register "<Image>/Filters" "Digitization")
- (script-fu-register "figuier"
- "Old book illustration cleanup"
- "Automatically make illustrations from old books e-book ready by erasing the sepia background, removing ink marks from the facing page and reddish spots, and then by sharpenning and desaturating the final picture."
- "Elie Morisse"
- "contributed by Elie Morisse"
- "2013"
- "RGB*"
- SF-IMAGE "Image" 0
- SF-DRAWABLE "Layer" 0)
- (script-fu-menu-register "figuier"
- "<Image>/Filters/Digitization")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement