;;; smart-sharpen2.scm v0.3 ;;; Copyright (c) 2004-2005 John Hall (jhall@gimpfaq.org) ;;; ;;; A Script-Fu script for The GIMP to automate "smart" sharpening ;;; technique. ;;; ;;; ;;; This program is free software; you can redistribute it and/or modify ;;; it under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 2 of the License, or ;;; (at your option) any later version. ;;; ;;; This program is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with this program; if not, write to the Free Software ;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ;;; ;;; ;;; Revision history: ;;; ;;; v0.3: - Cleaned up code ;;; v0.2: - Modified for The GIMP 2.0pre2 ;;; v0.1: - First public release ;; Performs a "smart" sharpen. ;; ;; This technique is described by Eric R. Jeschke here: ;; http://gimpguru.org/Tutorials/SmartSharpening2/ ;; ;; However, he adapted this technique for The GIMP from a sharpening ;; article by Bruce Fraser on the creativepro.com web site: ;; http://www.creativepro.com/printerfriendly/story/20357.html (define (script-fu-smart-sharpen2 image drawable) ;; Uses a logarithmic scale to calculate a reasonable amount for ;; edge detection. (define (get-edge-amount width height) (min (max (* 3.5 (log (/ (* width height) 1000000))) 1.0) 10.0)) (let* ((width (car (gimp-image-width image))) (height (car (gimp-image-height image))) (edge-amount (get-edge-amount width height)) (blur-radius (+ 1 edge-amount)) (edge-image (car (gimp-image-duplicate image))) (edge-drawable (car (gimp-image-flatten edge-image))) (hsv-images (plug-in-decompose TRUE edge-image edge-drawable "HSV" FALSE)) (value-image (caddr hsv-images)) (value-drawable (car (gimp-image-get-active-layer value-image))) (sharpen-layer (car (gimp-layer-new image width height RGBA-IMAGE "Smart Sharpening" 80.0 VALUE-MODE))) (sharpen-layer-mask (car (gimp-layer-create-mask sharpen-layer WHITE-MASK)))) (gimp-image-undo-group-start image) ;; Apply an unsharp mask to the value image (plug-in-unsharp-mask TRUE value-image value-drawable 1.0 1.0 0) ;; Copy value image to sharpen layer (gimp-image-add-layer image sharpen-layer -1) (gimp-edit-copy value-drawable) (gimp-floating-sel-anchor (car (gimp-edit-paste sharpen-layer TRUE))) (gimp-image-delete (car hsv-images)) (gimp-image-delete (cadr hsv-images)) (gimp-image-delete (caddr hsv-images)) ;; Adjust the tonality so that areas that need sharpening are ;; white and everything else is black (this will become the ;; sharpening mask). The input levels were picked arbitrarily, ;; but they seem to work for me. (plug-in-edge TRUE edge-image edge-drawable edge-amount 1 0) (gimp-image-convert-grayscale edge-image) (gimp-levels edge-drawable VALUE-LUT 40 200 1.00 0 255) (plug-in-gauss-iir2 TRUE edge-image edge-drawable blur-radius blur-radius) (gimp-levels-auto edge-drawable) ;; Copy edge image to sharpen layer mask (gimp-layer-add-mask sharpen-layer sharpen-layer-mask) (gimp-edit-copy edge-drawable) (gimp-floating-sel-anchor (car (gimp-edit-paste sharpen-layer-mask TRUE))) (gimp-image-delete edge-image) (gimp-image-undo-group-end image) (gimp-displays-flush) (list image))) (script-fu-register "script-fu-smart-sharpen2" "/Script-Fu/Enhance/Smart Sharpen" "Performa a smart sharpen on an image." "John Hall" "John Hall" "2004-2005" "" SF-IMAGE "The image" 0 SF-DRAWABLE "The layer (not used)" 0)