It is currently Sun Sep 20, 2026 6:36 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: plug-in borderaverage
PostPosted: Wed Feb 27, 2013 7:40 am  (#1) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14835
Location: roma, italy
GIMP Version: 2.8.4
Operating System: Windows
OS Version: XP - SP3
GIMP Experience: Beginner Level

List any relevant plug-ins or scripts:
plug-in borderaverage

List any ERROR messages you received:
no return value



Because I liked the effect proposed on a recent tutorial on colour enhancement, I tried to implement a python script to perform the steps, but I encountered a strange error: while the borderaverage plug-in works perfectly when executed directly on the screen, it seems not to work when called inside a python script, neither launching the script not even trying the function on the python console; in both cases, when plug-in borderaverage is called, it starts work for a while then crashes ("no return value").
I did evaluate my script using Komodo Edit, both performing a syntax check and simulating the run: no errors (only, as expected, "no module named gimpfu).
Any idea about the possible causes?
Many thanks
(PS: this post has been reposted here from the one I appended to the topic on the tutorial, because I think it's more appropriate here)

_________________
"Where am I ?"


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: plug-in borderaverage
PostPosted: Wed Feb 27, 2013 7:41 am  (#2) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14835
Location: roma, italy
sorry, I didn't correct my OS: it is Windows 7 32 bits

_________________
"Where am I ?"


Top
 Post subject: Re: plug-in borderaverage
PostPosted: Wed Feb 27, 2013 8:39 am  (#3) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
Without seeing your code, it's impossible to give more than vague suggestions.

Vague suggestion number 1:
Are you sure you are supplying the correct parameters to plug-in-borderaverage?

Kevin


Top
 Post subject: Re: plug-in borderaverage
PostPosted: Wed Feb 27, 2013 10:29 am  (#4) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14835
Location: roma, italy
Hi Kevin, here is my code
------------------------------------------------------------------------------------------
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from gimpfu import *

#
# create a function which sends msg to gimp's Error Console
#

def gprint( text ):
pdb.gimp_message(text)
return

#
# definition of the script
# name must correspond to the name
# at the bottom of the registration, before menu
#

def enhancecolors(inImage, inDrawable, inOpacity) :

gprint("Hello from my script!")
gprint("You sent me this level of opacity: %d"%inOpacity)

# Store the GIMP's settings so they can be restored when we're finished
gimp.context_push()

# Make all the operations in this filter undo in one group
inImage.undo_group_start()

copiedDrawable=pdb.gimp_layer_copy(inDrawable, TRUE)
pdb.gimp_image_add_layer(inImage, copiedDrawable, -1)
pdb.gimp_selection_all(inImage)
pdb.gimp_image_set_active_layer(inImage, copiedDrawable)

fgc=pdb.plug_in_borderaverage(inImage, copiedDrawable, 3, 16)

#pdb.plug_in_colortoalpha(inImage, copiedDrawable, fgc)

inImage.undo_group_end()
gimp.context_pop()

return

# This is the plugin registration function
register(
"enhancecolors",
"to enhance pale colors",
"This script does make colors more vivid",
"Diego",
"Diego Nassetti ",
"February 2013",
"enhancecolors",
"*",
[
(PF_IMAGE, "image", "Input image", None),
(PF_DRAWABLE, "drawable", "Input drawable", None),
(PF_SLIDER, 'opacity', 'opacity level:', 50, (10, 100, 10))
],
[],
enhancecolors,
menu="<Image>/Additional/Diego/",
)

main()
-------------------------------------------------------------------------------------------
I hope you can find where my errors are, thanks

_________________
"Where am I ?"


Top
 Post subject: Re: plug-in borderaverage
PostPosted: Wed Feb 27, 2013 12:29 pm  (#5) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
For the future it's better if you put code into [ code ] [ / code ] tags, especially for Python as it's indent sensitive.

Anyway as your problem happens at the pdb.plug_in_borderaverage then I'd suggest that you've got too big a value for the bucket-exponent parameter. The PDB browser says that the default value is 4 which means 16 levels and you've set a value of 16 which will be 2^16 = 65536 levels. Now I don't know what this parameter does, but I think you should try using a much lower number and see if you've still got a problem.

Kevin


Top
 Post subject: Re: plug-in borderaverage
PostPosted: Thu Feb 28, 2013 12:04 am  (#6) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14835
Location: roma, italy
Thanks Kevin.
Partially good news: by reducing the second number the plug-in does not crash, made some trials and the maximum level not to crash is 8 (BTW I thought the numbers to put were the same as in the interactive dialogue (3 and 16 are the proposed values); so no crash but:
1 - the plug-in does not change the foreground colour, which remains black, and to be sure it isn't coming out from my image I prepared a sample image completely red and activated the script: the FG still remained black afterwards
2 - the returned value seems not to be a "colour" in the sense I supposed, that is like (x, y, z) with the 3 values of red, green, blue; in fact by activating the statement which follows ("colortoalpha") I get an error saying that the variable fgc contains only two values and three are expected; to verify I replaced fgc with (10, 10, 10) and colortoalpha did work
(BTW how can I "print" the fgc value(s)?)
Thanks for your help

_________________
"Where am I ?"


Top
 Post subject: Re: plug-in borderaverage
PostPosted: Thu Feb 28, 2013 1:01 am  (#7) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14835
Location: roma, italy
eureka!
after many trials it seems I found the solution:
in the colortoalpha statement I have to put:
pdb.plug_in_colortoalpha(inImage, copiedDrawable, fgc[0]),
so it works, fgc[0] IS A COLOR
(and I can print it using gprint ( fgc[0] ))
Thanks for your help on borderaverage, without it I was in a big trouble.

_________________
"Where am I ?"


Top
 Post subject: Re: plug-in borderaverage (inconsistent parameter def.?)
PostPosted: Thu Feb 28, 2013 10:32 am  (#8) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14835
Location: roma, italy
As a conclusion of my experience with this plug-in, I would line to underline two aspects:
1 - the definition in the PDB says that this plug-in returns a COLOR; this is not 100% true, it returns a tuple composed of two elements, the first one is a COLOR tuple in the form (r g b a), the second one is a single value (found 0, don't know what's its meaning); this fact is misleading for a poor novice programmer, because, having to use a subsequent plug-in as colortoalpha which requires in input a COLOR in the traditional gimp understanding of a tuple of 3 (rgb) or 4 (rgba) elements, I initially passed the result of borderaverage as input to colortoalpha and only after many trials I discovered that I had to pass not the result but the first element of the tuple-result. If some guru agrees, maybe it could be possible to change the plug-in description for a easier understanding of what to do with the result
2 - also, the definition says the plug-in changes the foreground color, but - while this is perfectly true when called from the gimp menu, it seems to me not to be true when called inside another plug-in (this is not a negative observation, just an indication of what I noticed)
3 - even if clearly stated in the description that the second input parameter is not the number of buckets but the n-power of 2 of the number of buckets ( default 4 >=> 16), because when called from the gimp menu the default is shown as number of buckets (16), I consider this as being an inconsistent appearance of the parameter, IMHO it would be better to have the same default in both cases.
Because of this points I modified the post subject to include - in parenthesis - is somebody could consider evaluating inconsistent indication of parameter in this plug-in.
Thanks...

_________________
"Where am I ?"


Top
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group