Switch to full style
Post all Gimp scripts and script writing questions here
Post a reply

Help with pdb.plug_in_displace when using python-fu

Tue Feb 25, 2020 3:52 am

I'm trying to write a plugin for realistically blending tattoos to facial images, but I am unable to get any effect when using pdb.plug_in_displace in version 2.10 of GIMP. Note, that the displacement works if I manually go to Filters -> Map -> Displace and uses the same tattoo image and displacement map.

A sample of my code is given below:

Code:
img = gimp.Image(width, height)
pdb.gimp_display_new(img)

# load face and tattoo images
face_layer = open_images_as_layer(img, path_to_facial_image)
tattoo_layer= open_images_as_layer(img, path_to_tattoo_image)

# rescale tattoo layer
pdb.gimp_layer_scale(tattoo_layer, new_width, new_height, False)

# set offset of tattoo_layer
pdb.gimp_layer_set_offsets(tattoo_layer, x_offset, y_offset)

# set the tattoo_layer we want to displace to be the same size as the image
pdb.gimp_layer_resize_to_image_size(tattoo_layer)

# load the displacement map
disp_image = pdb.gimp_file_load(disp_file, disp_file)
disp_drawable = pdb.gimp_image_get_active_layer(disp_image)   

# this line does not seem to do anything no matter how I set the parameters
pdb.plug_in_displace(img, tattoo_layer, 10, 10, True, True, disp_drawable, disp_drawable, 2)


Any suggestions to why the displacement (in the last line of the code above) has no effect - is really appreciated

Thanks!

Re: Help with pdb.plug_in_displace when using python-fu

Tue Feb 25, 2020 4:43 am

Hi i-regular.

You used the wrong number of parameters - lack: run_mode=......
Code:
pdb.plug_in_displace(img, tattoo_layer, 10, 10, True, True, disp_drawable, disp_drawable, 2, run_mode=RUN_NONINTERACTIVE)

Re: Help with pdb.plug_in_displace when using python-fu

Tue Feb 25, 2020 5:04 am

Thanks - I forgot to tell that I was running the plugin from within GIMP, so I believe in that case I do not need to specify the run-mode? But, I will need to run it later from batch, so thanks for pointing out!

I found the issue. There seems to be an error in version 2.10.14 of GIMP where the procedure does not work. I just upgraded to version 2.10.18 and now it seems to work also without specifying the run-mode i.e. with no modifications to the code above. Also I tried version 2.8.22 of GIMP where it also works!

Anyhow thanks for the help - I really appreciate it!

Re: Help with pdb.plug_in_displace when using python-fu

Tue Feb 25, 2020 7:47 am

MareroQ wrote:Hi i-regular.

You used the wrong number of parameters - lack: run_mode=......
Code:
pdb.plug_in_displace(img, tattoo_layer, 10, 10, True, True, disp_drawable, disp_drawable, 2, run_mode=RUN_NONINTERACTIVE)


You never *need* that run_mode parameter. It's a named parameter because it is optional in the Python API (and defaults to RUN_NONINTERACTIVE, so you typically only use it with RUN_INTERACTIVE). The doc mentions it because the Python doc is built from the Scheme one, but there are mappings between the Python and Scheme.

Re: Help with pdb.plug_in_displace when using python-fu

Tue Feb 25, 2020 10:07 am

... the Python doc is built from the Scheme one, but there are mappings between the Python and Scheme


This is what I understand now why in script-fu this is the first parameter and in python the last - if needed (because erroneously indicated in the Python Procedure Browser also as the first by stupid analogy).

Thanks for the clarification.
Post a reply