Visualizzazione post con etichetta image. Mostra tutti i post
Visualizzazione post con etichetta image. Mostra tutti i post

lunedì 5 luglio 2010

GIMP Scripting - HDR

Dato che ormai ho preso un po' di mano con lo scripting in GIMP sto cercando di realizzare degli effetti che mi piacciono da applicare indistintamente alle foto senza dover ripetere continuamente tutte le operazioni.
L'HDR (High Dynamic Range) è l'effetto che ho scelto; se vogliamo essere pignoli questo effetto necessiterebbe di almeno 3 immagini, scattate con tempi di esposizione diversi, in maniera da avere un'immagine sovraesposta, una normale ed una sottoesposta... unendo queste tre con particolari procedure si ottiene un HDR reale.
Siccome non sempre è possibile procurarsi facilmente 3 immagini con esposizioni diverse, un po' di tempo fa ho trovato un tutorial che spiegava come ottenere un'immagine simil HDR partendo da un singolo scatto applicandogli vari filtri per simulare la sovra/sotto esposizione ottnendo un buon risultato; trovando la procedura valida ho scriptato il processo spiegato ottenendo l'effetto voluto tramite il seguente  script-fu:

; Script to make HDR Image from one layer file
;
; The script is located in "<Image> / Script-Fu / SebaX75 / HDR..."
;
; Last changed: 29 Aprile 2010
;
; Copyright (C) 2010 SebaX75 <sebax75 AT yahoo DOT it>
;
; --------------------------------------------------------------------
; 
; Changelog:
;  Version 0.1
;    - Initial version, with manual dodge-burn 
;  Version 0.2
;    - Added dodge-burn code and automated
;
; --------------------------------------------------------------------
;
; 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 3 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, you can view the GNU General Public
; License version 3 at the web site http://www.gnu.org/licenses/gpl-3.0.html
; Alternatively you can write to the Free Software Foundation, Inc., 675 Mass
; Ave, Cambridge, MA 02139, USA.
;

; This part code was got from dodge-burn.scm script-fu (http://registry.gimp.org/files/dodge-burn.scm) by Harry Phillips <script-fu@tux.com.au>
(define (my-layer-dodge-burn    myImage
   myLayer
   modeOp
   thinNum
   thickNum
 )
 ;Initiate some variables
 (let* (
  (firstTemp (car (gimp-layer-copy myLayer 1)))
  (thinTemp)
  (thickTemp)
  (merged)
  )
  ;Rename the layer
  (gimp-drawable-set-name firstTemp "First temp")
  ;Add the first layer to the image
  (gimp-image-add-layer myImage firstTemp 0)
  ;Desaturate the layer
  (gimp-desaturate firstTemp)
  ;Copy and add the dodge me layer as the thin layer
  (set! thinTemp (car (gimp-layer-copy firstTemp 1)))
  (gimp-image-add-layer myImage thinTemp 0)
  ;Blur the thin layer
  (plug-in-gauss 1 myImage thinTemp thinNum thinNum 0)
  (if (= modeOp 1)
   ;Change the mode of the thin layer to lighten
   (gimp-layer-set-mode thinTemp 10)
   ;Change the mode of the thin layer to darken
   (gimp-layer-set-mode thinTemp 9)
  )
  ;Blur the dodge me layer
  (plug-in-gauss 1 myImage firstTemp thickNum thickNum 0)
  ;Copy the dodge me layer as a new layer
  (set! thickTemp (car (gimp-layer-copy firstTemp 1)))
  ;Add the new layer to the image
  (gimp-image-add-layer myImage thickTemp 1)
  ;Merge the top layer down and keep track of the newly merged layer
  (set! merged (car (gimp-image-merge-down myImage thinTemp 0)))
  ;Change the mode of the dodge copy layer to difference mode
  (gimp-layer-set-mode merged 6)
  ;Merge the top layer down and keep track of the newly merged layer
  (set! merged (car (gimp-image-merge-down myImage merged 0)))
  (if (= modeOp 1)
   (begin
    ;Rename the layer
    (gimp-drawable-set-name merged "Dodge channel")
    ;Change the mode of the dodge copy layer to dodge mode
    (gimp-layer-set-mode merged 16)
   )
   (begin
    ;Rename the layer
    (gimp-drawable-set-name merged "Burn channel")
    ;Change the mode of the dodge copy layer to dodge mode
    (gimp-layer-set-mode merged 17)
    ;Invert layer
    (gimp-invert merged)
   )
  )
  ;Return
 )
)

(define (script-fu-SebaX75-HDR      myImage
    layer0
    thinAmount
    thickAmount
 )
;       Start an undo group so the process can be undone with one undo
 (gimp-image-undo-group-start myImage)

 ; Rimuove qualunque selezione
 (gimp-selection-none myImage)

 ; Esegue la normalizzazione del layer principale
 (plug-in-normalize 1 myImage layer0)

 ; Inizializzo le variabili da utilizzare
 (let* ( (layer1()) (layer2()) (layer3()) (layer4()) )

  ; Creo una copia del layer principale, lo aggiungo e lo rinomino
  (set! layer1 (car (gimp-layer-copy layer0 1)))
  (gimp-image-add-layer myImage layer1 0)
  (gimp-drawable-set-name layer1 "Op. 50%")

  ; Desaturo, inverto ed applico l'effetto chiaritore sfumato al nuovo layer
  (gimp-desaturate layer1)
  (gimp-invert layer1)
  (plug-in-softglow 1 myImage layer1 10 0.75 0.85)

  ; Imposto il merging del layer a "Soft light" con opacita' al 50%
  (gimp-layer-set-mode layer1 SOFTLIGHT-MODE)
  (gimp-layer-set-opacity layer1 50)

  ; Creo una copia del layer modificato, imposto l'opacita' al 75% e lo rinomino
  (set! layer2 (car (gimp-layer-copy layer1 1)))
  (gimp-image-add-layer myImage layer2 -1)
  (gimp-layer-set-opacity layer2 75)
  (gimp-drawable-set-name layer2 "Op. 75%")

  ; Creo il layer di testa, modifico l'istogramma dei colori, eseguo il merging ed imposto la trasparenza al 40% (valori consigliati 30%-50%)
  (set! layer3 (car (gimp-layer-copy layer0 1)))
  (gimp-image-add-layer myImage layer3 -1)
  (gimp-levels layer3 HISTOGRAM-VALUE 100 255 1.00 0 255)
  (gimp-layer-set-mode layer3 DARKEN-ONLY-MODE)
  (gimp-layer-set-opacity layer3 40)
  (gimp-drawable-set-name layer3 "Top Layer")

  ; Unisco tutti i layer visibili
  (set! layer4 (car (gimp-image-flatten myImage)))
  (gimp-drawable-set-name layer4 "Last Layer")

  ;Do the dodge layer first
  (my-layer-dodge-burn myImage layer4 1 thinAmount thickAmount)

  ;Do the burn layer
  (my-layer-dodge-burn myImage layer4 0 thinAmount thickAmount)

  ; Modifico la saturazione/luminanza
  (gimp-hue-saturation layer4 ALL-HUES 0 0 50)

 )

 ;Finish the undo group for the process
 (gimp-image-undo-group-end myImage)

 ; Assicuro l'aggiornamento e la nuova visualizzazione
 (gimp-displays-flush)
)

; Registrazione dello script
(script-fu-register "script-fu-SebaX75-HDR"
 _"<Image>/Script-Fu/SebaX75/HDR..."
 "Applica gli effetti per ottenere un HDR"
 "SebaX75"
 "SebaX75"
 "April 29 2010"
 "*"
 SF-IMAGE "Image"     0
 SF-DRAWABLE     "Drawable"  0
 SF-ADJUSTMENT   _"Thin amount"  '(10 0 1000 1 1 0 1)
 SF-ADJUSTMENT   _"Thick amount" '(25 0 10000 1 1 0 1)
)

Buon HDR a tutti ed alla prossima.

lunedì 28 giugno 2010

GIMP Scripting - Fade and Shadow

Siccome qualcuno potrebbe pensare che questo blog sia stato abbandonato, provvedo a pubblicare qualcosa di nuovo che non è molto impegnativo, ma può fare molto comodo ed essere interessante.
Non pensate che siano stati abbandonati gli argomenti da sistemista, ma ho accumulato solamente un deciso ritardo perchè le tante bozze presenti sono da revisionare e correggere, alcune anche da terminare.
Visto che non mi piace farmi mancare "oggetti" scaturiti dalla mia mente e non perdo mai l'abitudine a cercare di arrivare dove altri si sentono a casa loro, mi sono dedicato ad un po' di sano scripting per GIMP, ovvero gli script-foo; questa tipologia di script serve per automatizzare operazioni ricorsive sulle immagini semplificando di molto la vita, ed aumentando moltissimo la velocità, se si devono applicare sempre gli stessi effetti.
Il primo e più semplice script che ho creato serve per effettuare un effetto fading e shadowing ad un'immagine, ovvero sfumare l'immagine ai bordi, come se fosse un rettangolo arrotondato, ed applicargli l'effetto ombra.

Ecco il codice:
; Script to make fading and shadowing of an image
;
; The script is located in "<Image> / Script-Fu / SebaX75 / Fade & Shadow..."
;
; Last changed: 25 Aprile 2010
;
; Copyright (C) 2010 SebaX75 <sebax75 AT yahoo DOT it>
;
; --------------------------------------------------------------------
; 
; Changelog:
;  Version 0.1
;    - First release
;
; --------------------------------------------------------------------
;
; 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 3 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, you can view the GNU General Public
; License version 3 at the web site http://www.gnu.org/licenses/gpl-3.0.html
; Alternatively you can write to the Free Software Foundation, Inc., 675 Mass
; Ave, Cambridge, MA 02139, USA.
;

(define (script-fu-SebaX75-fade-shadow      myImage
     layer0
     offset_x
     offset_y
     arrotondamento
     riduzione
     sfumatura
     coloreOmbra
 )
;       Start an undo group so the process can be undone with one undo
 (gimp-image-undo-group-start myImage)

 ; Esegue la normalizzazione del layer principale
 (plug-in-normalize 1 myImage layer0)

 ; Rimuove qualunque selezione
 (gimp-selection-none myImage)

 ; Inizializzo le variabili da utilizzare
 (let* (
  (image-width (gimp-drawable-width layer0))
  (image-height (gimp-drawable-width layer0))
  (layer1())
  )

  ;Impostare il colore del primo piano a #444444
  (gimp-context-set-foreground coloreOmbra)
  ;Livello -> Trasparenza -> Aggiungi canale alfa
  (gimp-layer-add-alpha layer0)
  ; Seleziona -> Rettangolo arrotondato (20)
  (gimp-selection-all myImage)
  (script-fu-selection-rounded-rectangle myImage layer0 arrotondamento FALSE)
  ; Seleziona -> Riduci (10)
  (gimp-selection-shrink myImage riduzione)
  ; Seleziona -> Inverti
  (gimp-selection-invert myImage)
  ; Seleziona -> Sfumata (20)
  (gimp-selection-feather myImage sfumatura)
  ;Pressione Canc
  (gimp-edit-clear layer0)
;# Seleziona -> Niente
  ;Livello -> Nuovo livello con colore del primo piano ed in secondo piano
  (set! layer1 (car (gimp-layer-new-from-drawable layer0 myImage)))
  (gimp-image-add-layer myImage layer1 1)
  (gimp-drawable-fill layer1 FOREGROUND-FILL)
  ;Seleziona -> Rettangolo arrotondato (20)
  (gimp-selection-all myImage)
  (script-fu-selection-rounded-rectangle myImage layer1 arrotondamento FALSE)
  ;Seleziona -> Riduci (15)
  (gimp-selection-shrink myImage (+ riduzione 5))
  ;Seleziona -> Inverti
  (gimp-selection-invert myImage)
  ;#Seleziona -> Sfumata (20)
  (gimp-selection-feather myImage sfumatura)
  ;Pressione Canc
  (gimp-edit-clear layer1)
  ;Spostare di posizione il nuovo layer (10,10 pixel)
  (gimp-layer-set-offsets layer1 offset_x offset_y)
  ; Rimuove qualunque selezione
  (gimp-selection-none myImage)
  ; Unisco tutti i layer in uno unico
  (set! layer0 (car (gimp-image-flatten myImage)))
  (gimp-drawable-set-name layer0 "Ombra+Fade")
 )

 ;Finish the undo group for the process
 (gimp-image-undo-group-end myImage)

 ; Assicuro l'aggiornamento e la nuova visualizzazione
 (gimp-displays-flush)
)

; Registrazione dello script
(script-fu-register "script-fu-SebaX75-fade-shadow"
 _"<Image>/Script-Fu/SebaX75/Fade & Shadow..."
 "Applica gli effetti per ottenere l'ombra ed il fading dell'immagine"
 "SebaX75"
 "SebaX75"
 "April 21 2010"
 "*"
 SF-IMAGE "Image"     0
 SF-DRAWABLE     "Drawable"  0
 SF-ADJUSTMENT   _"Spostamento X" '(10 -4096 4096 1 10 0 1)
 SF-ADJUSTMENT   _"Spostamento Y" '(10 -4096 4096 1 10 0 1)
 SF-ADJUSTMENT   _"Arrotondamento %"     '(20 -4096 4096 1 10 0 1)
 SF-ADJUSTMENT   _"Riduzione"    '(10 0 1024 1 10 0 1)
 SF-ADJUSTMENT   _"Sfumatura"    '(20 0 1024 1 10 0 1)
 SF-COLOR _"Colore ombra" "#444444"
)

Per oggi direi che è tutto... buon divertimento con GIMP.