;;; midtone-sharpen.scm v0.1 ;;; Copyright (c) 2004 John Hall (jhall@alum.wpi.edu) ;;; ;;; A Script-Fu script for The GIMP to automate midtone 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.1: - First public release ;; Performs a midtone sharpen. ;; ;; This technique is described here: ;; http://www.outbackphoto.com/workflow/wf_17/essay.html (define (script-fu-midtone-sharpen image drawable) (let* ((flattened-image (car (gimp-image-duplicate image))) (flattened-drawable (car (gimp-image-flatten flattened-image))) (value-image (car (plug-in-decompose TRUE flattened-image flattened-drawable "Value" FALSE))) (value-drawable (car (gimp-image-get-active-layer value-image))) (sharpen-layer (car (gimp-layer-new image (car (gimp-image-width image)) (car (gimp-image-height image)) RGBA-IMAGE "Midtone Sharpen" 60.0 VALUE-MODE))) (sharpen-layer-mask (car (gimp-layer-create-mask sharpen-layer BLACK-MASK))) (lab-images (plug-in-decompose TRUE flattened-image flattened-drawable "LAB" FALSE)) (luminance-image (car lab-images)) (alpha1 (car (gimp-channel-new image (car (gimp-image-width image)) (car (gimp-image-height image)) "Alpha 1" 0 '(0 0 0)))) (alpha2 (car (gimp-channel-copy alpha1)))) (gimp-image-delete flattened-image) (gimp-image-delete (cadr lab-images)) (gimp-image-delete (caddr lab-images)) (gimp-image-undo-group-start image) ;; 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 value-image) ;; Copy LAB luminance channel to two alpha channels (gimp-drawable-set-name alpha2 "Alpha 2") (gimp-drawable-set-visible alpha1 FALSE) (gimp-drawable-set-visible alpha2 FALSE) (gimp-image-add-channel image alpha1 -1) (gimp-image-add-channel image alpha2 -1) (gimp-edit-copy (car (gimp-image-get-active-drawable luminance-image))) (gimp-floating-sel-anchor (car (gimp-edit-paste alpha1 TRUE))) (gimp-floating-sel-anchor (car (gimp-edit-paste alpha2 TRUE))) (gimp-image-delete luminance-image) ;; Inverse the first alpha and set output level to 20 (gimp-invert alpha1) (gimp-levels alpha1 VALUE-LUT 0 255 1.00 20 255) ;; Create the layer mask by intersecting the negative and positive ;; channels. Only the mid-tones will be affected by mayor ;; enhancement, so the USM-sharpening can be applied with very ;; strong values (gimp-layer-add-mask sharpen-layer sharpen-layer-mask) (gimp-selection-load alpha1) (gimp-selection-combine alpha2 CHANNEL-OP-INTERSECT) (gimp-palette-set-default-colors) (gimp-edit-fill sharpen-layer-mask BACKGROUND-FILL) (gimp-selection-none image) ;; Apply an unsharp mask to the value image (plug-in-unsharp-mask TRUE image sharpen-layer 0.6 2.0 2) (gimp-image-undo-group-end image) (gimp-displays-flush) (list image))) (script-fu-register "script-fu-midtone-sharpen" "/Script-Fu/Enhance/Midtone Sharpen" "Perform a midtone sharpen on an image." "John Hall" "John Hall" "2004" "" SF-IMAGE "The image" 0 SF-DRAWABLE "The layer (not used)" 0)