It is currently Thu Jul 04, 2024 4:06 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: looking for help with a Python script
PostPosted: Sun Apr 07, 2019 10:20 pm  (#1) 
Offline
New Member

Joined: Apr 06, 2019
Posts: 2
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()


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: looking for help with a Python script
PostPosted: Sun Apr 07, 2019 11:54 pm  (#2) 
Offline
GimpChat Member
User avatar

Joined: Nov 04, 2015
Posts: 1365
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.


Top
 Post subject: Re: looking for help with a Python script
PostPosted: Mon Apr 08, 2019 1:17 am  (#3) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4756
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

_________________
Image


Top
 Post subject: Re: looking for help with a Python script
PostPosted: Mon Apr 08, 2019 3:12 am  (#4) 
Offline
GimpChat Member
User avatar

Joined: Aug 08, 2016
Posts: 2062
Location: East Midlands of England
Which version of Gimp are you using Kevin?

_________________
Image

"Let no one steal your dreams."
Paul Cookson


Latest plug-in update: Paragrapher v.1.4
Custom Font Links
Tools
Character Paths
White Bases


Top
 Post subject: Re: looking for help with a Python script
PostPosted: Mon Apr 08, 2019 12:55 pm  (#5) 
Offline
New Member

Joined: Apr 06, 2019
Posts: 2
(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.


Top
 Post subject: Re: looking for help with a Python script
PostPosted: Tue Apr 09, 2019 12:25 pm  (#6) 
Offline
GimpChat Member
User avatar

Joined: May 16, 2010
Posts: 14709
Location: USA
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

_________________
Image
Edmund Burke nailed it when he said, "The only thing necessary for the triumph of evil is for good men to do nothing."


Top
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) Learning to do first Python script

6

No new posts .py script not showing under Python-Fu

3

No new posts Attachment(s) My first Python Script for Gimp

7

No new posts Does anyone have script fu and python plugins that work on 2.99.19?

1

No new posts Can a python script use gimpfu, run from terminal, and create new img?

2



* Login  



Powered by phpBB3 © phpBB Group