GIMP Chat
http://gimpchat.com/

looking for help with a Python script
http://gimpchat.com/viewtopic.php?f=9&t=17357
Page 1 of 1

Author:  KevinYork [ Sun Apr 07, 2019 10:20 pm ]
Post subject:  looking for help with a Python script

I'm writing a short Smart-Sharpen script. And it just stops without error message.
I'm hoping some kind soul can get the last two lines of code to execute:

CODING SUMMARY:
1) SmartSharpen_1() creates a rough edge mask from current layer. [AND WORKS FINE]
2){user manually cleans up any problems with the EDGE-MASK}
3) SmartSharpen_2() uses layer EDGE-MASK for sharpening the layer directly below it with:
a) UNSHARP MASK
b) invert selection
c) GAUSSIAN BLUR
d) clear selection

Execution stops between 3b and 3c (without an error message).
I have included a summary up to the problem; and full code around the problem.
I can certainly upload the entire script if that helps.

I have tried simplifying the code and throwing extra 'gimp.displays_flush()' as a "Hail Mary!".

I also tried running the Gaussian Blur manually. One time it worked; and the time I got 'GIMP Warning: The active layer is not visible."
But it was. Even via Python console showed the correct active layer and .visible=True

P.S.: is there a better forum for debug help?

def   SmartSharpen_1(image, layer):
# Create a rough edge mask from current layer
# make copy of active layer; name it 'EDGE-MASK'; desaturate the EDGE-MASK:
# run EDGE-DETECT plugin on EDGE-MASK layer:
# run Color>Levels on EDGE-MASK layer. 
# -----------------------------------------------------------------------------

# user should now manually clean up any problems with the EDGE-MASK; before running ....part2...

#------------------------------------------------------------------------------
def   SmartSharpen_2(image, layer):
# use layer EDGE-MASK for sharpening the layer directly below it [since that is where 'SmartSharpen_1()' left the original photo]:
# create the channel 'EDGES'; copy layer 'EDGE-MASK' into channel 'EDGES'; copy 'EDGES' into {selection}; and hide 'EDGES':
# make 'EDGE-MASK' the active layer; delete 'EDGE-MASK'; which should make the original photo the active  layer:
   ... code above removed for Brevity... full code below:
   
# make a copy of the original photo layer; do mods on the copy!; run UNSHARP plug-in; invert the selection; run GAUSSIAN plugin; clear the selection:
   layer                       = image.active_layer.copy(True) #\ make a COPY OF original photo.
   image.add_layer(              layer,    -1)                 #/
   image.active_layer         =  layer                         # [i.e. work on a backup copy only]
   pdb.gimp_selection_grow(      image,     1)
   pdb.plug_in_unsharp_mask(     image,     layer, 3.0, 0.65, 0)
   pdb.gimp_selection_invert(    image)
# --------------- execution stops here for some reason -------------------
   pdb.plug_in_gauss_iir2(       image,     layer, 0.9, 0.9,  0)   
   pdb.gimp_selection_none(      image)
   image.undo_group_end()
   pdb.gimp_displays_flush()

Author:  Tas_mania [ Sun Apr 07, 2019 11:54 pm ]
Post subject:  Re: looking for help with a Python script

Hi Kevin welcome to Gimp Chat.
I'm sure there is a Python expert looking at this right now. There is probably just a semantic reason why the code fails to execute.
Cheers.

Author:  ofnuts [ Mon Apr 08, 2019 1:17 am ]
Post subject:  Re: looking for help with a Python script

I don't see any obviously wrong. In My Python scripts, I use:

    image.undo_group_start()

    try:
        [ .. insert your code here ..]
    except Exception as e:
        print e.args[0]
        gimp.message(e.args[0])

    image.undo_group_end()


That way, some Python problem get caught and displayed in the python console.

Otherwise:

1. See here for general debugging techniques if you are on Windows. On Linux and OSX, things are simpler, just start Gimp from a command prompt/terminal, error messages will show up there. Also see here for further questions.
2. Best use standard code formatting if you want other people to read your code
3. Don't play with "image.active_layer". The active layer is the layer you are passed as an argument anyway, and all the calls that act on a layer take the layer as an argument and don't rely on the "active layer".
4. Display flushes are very rarely necessary in Python code

Author:  Skinnyhouse [ Mon Apr 08, 2019 3:12 am ]
Post subject:  Re: looking for help with a Python script

Which version of Gimp are you using Kevin?

Author:  KevinYork [ Mon Apr 08, 2019 12:55 pm ]
Post subject:  Re: looking for help with a Python script

(grrrr..... never mind; I found my stupidity.
I was reading documentation on pdb.plug_in_gauss() ...but typed in pdb.plug_in_gauss_iir2(). which has fewer parameters) :gaah
Script runs fine now...

Many thanks for the quick response! As this was my first Python script; I do fear I will be posting more questions.

Author:  Rod [ Tue Apr 09, 2019 12:25 pm ]
Post subject:  Re: looking for help with a Python script

KevinYork wrote:
(grrrr..... never mind; I found my stupidity.
I was reading documentation on pdb.plug_in_gauss() ...but typed in pdb.plug_in_gauss_iir2(). which has fewer parameters) :gaah
Script runs fine now...

Many thanks for the quick response! As this was my first Python script; I do fear I will be posting more questions.


Thats all right. What ever you need were all here to help. :) :bigthup

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/