;;; remove-haze.scm v0.2 ;;; Copyright (c) 2004 John Hall (jhall@alum.wpi.edu) ;;; ;;; A Script-Fu script for The GIMP to automate Local Contrast ;;; Enhancement 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.2: - Modified add-flattened-layer to add the new layer to the ;;; image. (Not doing so generates an error in The GIMP 2.0pre3. ;;; See bug #132504) ;;; v0.1: - First public release ;; Creates a new layer for the image. The new layer is a copy of the ;; image with all of the layers flattened. Other attributes such as ;; name, layer mask mode, and opacity should be set with explicit ;; procedure calls. (define (add-flattened-layer image) (let* ((flattened-image (car (gimp-image-duplicate image))) (flattened-drawable (car (gimp-image-flatten flattened-image))) (new-layer (car (gimp-layer-new image (car (gimp-image-width image)) (car (gimp-image-height image)) RGBA-IMAGE "New Layer" 100.0 NORMAL-MODE)))) ;; Copy flattened image to new layer (gimp-edit-copy flattened-drawable) (gimp-image-add-layer image new-layer -1) (gimp-floating-sel-anchor (car (gimp-edit-paste new-layer TRUE))) (gimp-image-delete flattened-image) (list new-layer))) ;; Removes haze from an image using Local Contrast Enhancement. For a ;; description of this technique, see ;; http://www.luminous-landscape.com/tutorials/contrast-enhancement.shtml ;; ;; The radius for the unsharp mask is calculated based on the number ;; of pixels in the image. The more pixels you have, the higher the ;; radius. (define (script-fu-remove-haze image drawable) (let* ((radius (min 120 (ceiling (* (/ (* (car (gimp-image-width image)) (car (gimp-image-height image))) 1000000) 30)))) (new-layer (car (add-flattened-layer image)))) ;; Add new layer to image (gimp-drawable-set-name new-layer "Clarified") (gimp-layer-set-mode new-layer NORMAL-MODE) (gimp-layer-set-opacity new-layer 100.0) (plug-in-unsharp-mask TRUE image new-layer radius 0.20 0.0) (list image))) (script-fu-register "script-fu-remove-haze" "/Script-Fu/Enhance/Remove Haze" "Removes haze from a picture." "John Hall" "John Hall" "2004" "" SF-IMAGE "The image" 0 SF-DRAWABLE "The layer (not used)" 0)