Tags

, , , ,

Here is the script that I developed for Gimp, to sharpen an image using the ‘Grain Extract’ method. Oh!! What is the method? Here are the steps, if you want to try and sharpen an image yourself.

  • Duplicate image into new layer (name this layer as ‘duplayer’)
  • Blur the image using Filter > Blur > Gaussian Blur
  • Enter blur radius (say 5)
  • Set ‘Layer Mode’ of ‘duplayer’ to ‘Grain Extract’
  • Make a copy of this layer using Layers > New from Visible (name this layer as ‘vislayer’)
  • Hide or delete ‘duplayer’
  • Change Mode to Overlay (? this is my own trial step)
  • Adjust Opacity setting (100.0 by default), to adjust for sharpness
  • Merge ‘vislayer’ with original image layer

Note: While sharpening an image, it is best to set zoom value to 100% to see the effect of sharpening.

And here is the script.

;; -*-scheme-*-
;; Gimp script-fu to sharpen an image using 'Grain Extract Method'
;;

(define (script-fu-bp-sharpen-grain-extract theImage drawable blurValue opacityValue deleteGrainExtractLayer mergeLayers)
  ; step one - create a new layer, apply gaussian blur and set mode to 'grain extract'
  ; Create a new layer
  (define layerGrainExtract (car (gimp-layer-copy drawable 0)))
  ; Give it a name
  (gimp-item-set-name layerGrainExtract "Grain Extract Layer")
  ; Add the new layer to the image
  (gimp-image-insert-layer theImage layerGrainExtract 0 0)

  ; Call a plugin to blur the image
  (plug-in-gauss-rle 1 theImage layerGrainExtract blurValue 1 1)
   
  ; Set the layer mode to Grain Extract
  (gimp-layer-set-mode layerGrainExtract GRAIN-EXTRACT-MODE)
   
  ;; step two - create one more layer, set layer mode to 'overlay'
  ; Create one more layer
  (define layerOverlay (car (gimp-layer-copy drawable 0)))
  ; Give it a name
  (gimp-item-set-name layerOverlay "Overlay Layer")
  ; Add the new layer to the image
  (gimp-image-insert-layer theImage layerOverlay 0 0)
   
  ; Set the layer mode to Overlay
  (gimp-layer-set-mode layerOverlay OVERLAY-MODE)
   
  ; Set opacity to 50%
  (gimp-layer-set-opacity layerOverlay opacityValue)

  (if (= deleteGrainExtractLayer 1)
    (begin
      (gimp-image-remove-layer theImage layerGrainExtract)
    )
  )

  (if (= mergeLayers 1)
    (begin
      (set! drawable (car (gimp-image-merge-down theImage layerOverlay 2)))
    )
  )

  (gimp-displays-flush)   
)

(script-fu-register
  "script-fu-bp-sharpen-grain-extract" ; script name
  "Sharpen using Grain Extract ..." ; menu label
  "Sharpen Image using Grain Extract Method." ; description
  "BP" ; author
  "(c) 2016, BP" ; copyright notice
  "Nov 2016" ; date created
  "*" ; image type the script works on
  SF-IMAGE "Image" 0
  SF-DRAWABLE "Drawable" 0
  SF-ADJUSTMENT "Blur Value" '(5 0 100 1 10 0 1)
  SF-ADJUSTMENT "Opacity %" '(50 0 100 1 10 0 1)
  SF-TOGGLE "Delete Grain Extract Layer?" FALSE
  SF-TOGGLE "Merge Layers?" FALSE
)

(script-fu-menu-register "script-fu-bp-sharpen-grain-extract" "/Filters/BP")

;
; end
;

Links

Advertisements