It is currently Tue Jun 23, 2026 1:24 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Need some help for a script
PostPosted: Fri Dec 13, 2013 10:46 am  (#1) 
Offline
GimpChat Member
User avatar

Joined: Jan 03, 2011
Posts: 1656
Hello there,
I know lot of you are fantastic script writers, and Patrick David and myself have a little problem you could probably easily solve.

We want to reproduce what 'Wavelet Decompose' does, and I wrote a small G'MIC command that allows to decompose an image to several 'detail scales',
so that the original image can be seen as all these layers blended with the 'Grain merge' mode.
We have already wrote a small script that is able to call the G'MIC plug-in to perform the image decomposition into layers.
Now, we are stuck in the step which should set the correct blending modes for all layers.
Could we get help from some of you to do this ? We are not really expert in GIMP script coding.

Attached file is our first attempt : it takes an image and decompose it as several layers.
To make it work correctly, you need latest G'MIC (1.5.8.0) with latest update file (update your filters from the G'MIC plug-in before).

Any help is appreciated ! Thanks by advance.

Attachment:
gwd.scm [3.27 KiB]
Downloaded 125 times


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Need some help for a script
PostPosted: Fri Dec 13, 2013 12:21 pm  (#2) 
Offline
GimpChat Member
User avatar

Joined: Jan 12, 2012
Posts: 178
Location: Mobile, AL USA
Some more details:

The G'MIC function will create multiple layers (for the residual and multiple scales - variable number of scales) on the image.

Each layer will be named:
[G'MIC] : -v - -split_details 5,3 -+[^0] 128 -c 0,255 -reverse (#N)

Where the top most layer doesn't have (#N) appended, but subsequent ones do, where N = 1 -> (number of scales - 1).

So, requesting 5 scales will yield 5 new layers, named:
[G'MIC] : -v - -split_details 5,3 -+[^0] 128 -c 0,255 -reverse
[G'MIC] : -v - -split_details 5,3 -+[^0] 128 -c 0,255 -reverse #1
[G'MIC] : -v - -split_details 5,3 -+[^0] 128 -c 0,255 -reverse #2
[G'MIC] : -v - -split_details 5,3 -+[^0] 128 -c 0,255 -reverse #3
[G'MIC] : -v - -split_details 5,3 -+[^0] 128 -c 0,255 -reverse #4

We simply need to iterate through these new layers, and set their layer modes to "Grain Merge"...

_________________
patdavid.net
Image
PIXLS.US F/OSS Photography


Top
 Post subject: Re: Need some help for a script
PostPosted: Fri Dec 13, 2013 12:27 pm  (#3) 
Offline
GimpChat Member
User avatar

Joined: Jan 03, 2011
Posts: 1656
... except for the base layer (#4 in your example) which keep the 'normal' blending mode.


Top
 Post subject: Re: Need some help for a script
PostPosted: Fri Dec 13, 2013 12:40 pm  (#4) 
Offline
Script Coder
User avatar

Joined: Jul 14, 2010
Posts: 697
Does the (plugin-in-gmic...) call return the IDs of the new layers?

If not the script will have to get a list of all the image layers, call GMIC, then get all the layers again after, and set the blend mode for all new layers.

To get a list of all the layers use:
(vector->list (cadr (gimp-image-get-layers img)))

before and after

To change the layer mode use:
(gimp-layer-set-mode <layer> GRAIN-MERGE-MODE)

You can do this via (map..) like so:

before is set to the list before
after is set to the list after

(map (lambda (x) (if  (eq? (member x before) #f) (gimp-layer-set-mode x GRAIN-MERGE-MODE))) after)


Hope those dribbits of code help - I don't have a machine handy to try this on.

-Rob A>

_________________
Image
Fantasy Cartography and Mapping by RobA


Top
 Post subject: Re: Need some help for a script
PostPosted: Fri Dec 13, 2013 1:02 pm  (#5) 
Offline
GimpChat Member
User avatar

Joined: Jan 12, 2012
Posts: 178
Location: Mobile, AL USA
RobA wrote:
Does the (plugin-in-gmic...) call return the IDs of the new layers?

If not the script will have to get a list of all the image layers, call GMIC, then get all the layers again after, and set the blend mode for all new layers.

To get a list of all the layers use:
(vector->list (cadr (gimp-image-get-layers img)))

before and after

To change the layer mode use:
(gimp-layer-set-mode <layer> GRAIN-MERGE-MODE)

You can do this via (map..) like so:

before is set to the list before
after is set to the list after

(map (lambda (x) (if  (eq? (member x before) #f) (gimp-layer-set-mode x GRAIN-MERGE-MODE))) after)


Hope those dribbits of code help - I don't have a machine handy to try this on.

-Rob A>


For the love of Pete, this is why this is an awesome place. Thank you so much Rob! (I was conceptually there, but technically failing).

_________________
patdavid.net
Image
PIXLS.US F/OSS Photography


Top
 Post subject: Re: Need some help for a script
PostPosted: Fri Dec 13, 2013 3:17 pm  (#6) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
RobA wrote:
(if (eq? (member x before) #f) ...
Equivalent alternatives:
(if (not (member x before)) ...
(unless (member x before) ...
:)

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Need some help for a script
PostPosted: Fri Dec 13, 2013 11:22 pm  (#7) 
Offline
Script Coder
User avatar

Joined: Feb 18, 2011
Posts: 4826
Location: Bendigo Vic. Australia
before
Image
after
Image

(let* (
         (copy-layer (car (gimp-layer-copy drawable TRUE)))
       (layerList 0)
       (layerId 0)
         )

    ;; Add a copy of the layer to the image.
    (gimp-image-add-layer img copy-layer -1)

    ;; Render a 3D mapped cube from the active layer, using G'MIC.
    (plug-in-gmic 1 img drawable 1
                  (string-append
                   "-v - " ; To have a silent output. Remove it to display errors from the G'MIC interpreter on stderr.
                   "-split_details "
                   (number->string nbs) ","
                   (number->string ratio) " -+[^0] 128 -c 0,255 -reverse"
                   ))
   (gimp-drawable-set-visible drawable FALSE)
    (set! layerList (vector->list (cadr (gimp-image-get-layers img))))
    (while (not (null? layerList))
    (set! layerId (car layerList))
    (if (= (car (gimp-drawable-get-visible layerId)) TRUE) (begin
   (gimp-layer-set-mode layerId GRAIN-MERGE-MODE)
   )) ;endif
    (set! layerList (cdr layerList)))
    (gimp-drawable-set-visible drawable TRUE)   
    )

or this is easier and more concise (thanks RobA)
(let* (
         (copy-layer (car (gimp-layer-copy drawable TRUE)))
       (before (vector->list (cadr (gimp-image-get-layers img))))
       (after 0)
         )

    ;; Add a copy of the layer to the image.
    (gimp-image-add-layer img copy-layer -1)

    ;; Render a 3D mapped cube from the active layer, using G'MIC.
    (plug-in-gmic 1 img drawable 1
                  (string-append
                   "-v - " ; To have a silent output. Remove it to display errors from the G'MIC interpreter on stderr.
                   "-split_details "
                   (number->string nbs) ","
                   (number->string ratio) " -+[^0] 128 -c 0,255 -reverse"
                   ))
   (set! after (vector->list (cadr (gimp-image-get-layers img))))            
   (map (lambda (x) (if  (eq? (member x before) #f) (gimp-layer-set-mode x GRAIN-MERGE-MODE))) after)            
    )

do you want the layers merged after, and would you like me to post the amended script?

_________________
Image
No matter how much you push the envelope, it'll still be stationery.


Top
 Post subject: Re: Need some help for a script
PostPosted: Sat Dec 14, 2013 1:32 am  (#8) 
Offline
Script Coder
User avatar

Joined: Feb 18, 2011
Posts: 4826
Location: Bendigo Vic. Australia
This result is similiar to the G'MIC HardLight Mode

_________________
Image
No matter how much you push the envelope, it'll still be stationery.


Top
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group