/Filters/Render/Stroke to SVG...
This discussion is connected to the gimp-developer-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.
This is a read-only list on gimpusers.com so this discussion thread is read-only, too.
newb questions re python-fu | paul taney | 22 Sep 17:29 |
newb questions re python-fu | Chris Mohler | 22 Sep 18:50 |
newb questions re python-fu | paul taney | 22 Sep 19:37 |
newb questions re python-fu | Chris Mohler | 22 Sep 19:44 |
newb questions re python-fu | paul taney | 23 Sep 00:41 |
newb questions re python-fu | Chris Mohler | 23 Sep 00:51 |
newb questions re python-fu | paul taney | 23 Sep 20:11 |
/Filters/Render/Stroke to SVG... | paul taney | 25 Sep 18:49 |
/Filters/Render/Stroke to SVG... | David Gowers | 26 Sep 00:44 |
/Filters/Render/Stroke to SVG... | paul taney | 26 Sep 01:26 |
/Filters/Render/Stroke to SVG... | David Gowers | 26 Sep 05:29 |
newb questions re python-fu
Hi,
A coupla questions from the newb...
I am trying to write my first python-fu plug-in and I cannot get it to install. Here"s how I am pushing it to the plugins dir:
cp VanDerWalt.py ~/.gimp-2.4/plug-ins/python-fu-vanderwalt.py chmod +x ~/.gimp-2.4/plug-ins/python-fu-vanderwalt.py
Then I look for it under /Filters/Render/ and it is not there.
It"s a color filter that attempts to extract the bluest pixels, like this:
RED, GRN, BLU = 0, 1, 2
bluemask = (image[...,BLU] > 1.4*image[...,GRN]) & \
(image[...,BLU] > 1.4*image[...,RED])
blue_layer = gimp.layer(bluemask, width, height, RGBA_IMAGE, 100, NORMAL_MODE)
image.addlayer(blue_layer, 0)
Q1) Is this even close? Q2) can I continue to use numpy (as I was with wx.Python) or do these images have to be treated with scipy?
This is a volunteer project for the International Environmental Data Rescue Org (http://iedro.org), so if somebody wants to help me with it... the script is attached though it has not run yet :-o
It is for converting rasterized weather charts (stripcharts) to vector data for weather modeling.
paul
newb questions re python-fu
On Mon, Sep 22, 2008 at 10:29 AM, paul taney wrote:
Hi,
A coupla questions from the newb...
I am trying to write my first python-fu plug-in and I cannot get it to install. Here"s how I am pushing it to the plugins dir:
cp VanDerWalt.py ~/.gimp-2.4/plug-ins/python-fu-vanderwalt.py chmod +x ~/.gimp-2.4/plug-ins/python-fu-vanderwalt.py
Then I look for it under /Filters/Render/ and it is not there.
It"s a color filter that attempts to extract the bluest pixels, like this:
RED, GRN, BLU = 0, 1, 2 bluemask = (image[...,BLU] > 1.4*image[...,GRN]) & \ (image[...,BLU] > 1.4*image[...,RED])
blue_layer = gimp.layer(bluemask, width, height, RGBA_IMAGE, 100, NORMAL_MODE) image.addlayer(blue_layer, 0)
Q1) Is this even close? Q2) can I continue to use numpy (as I was with wx.Python) or do these images have to be treated with scipy?
Hi Paul,
I found a few mistakes here and there. The main one is that Python is very strict about indentation. After that, the "import Interpolate" line I changed to "from scipy import interpolate as ma" - I'm not sure if that is correct or not. Lastly, there were some items like "PF_ITEM("foo", _("foo"), "foo")" that I changed to "PF_ITEM("foo", "foo", "foo")" and also I added "Vanderwalt" to the end on the plug-in resgistration. Oh yeah - I also added an 'except' in somewhere befor a "finally"...
So... now it still does not run correctly, but at least it registers with GIMP :|
BTW - starting GIMP from the command line will show syntax errors in py-fu scripts.... Also editors like scite and eric (among others) show indentation problems in Python by default - these are probably in your repositories.
HTH,
Chris
newb questions re python-fu
Thanks very much, Chris.
I am using your file now and made a coupla repairs, afaict. But it still doesnt install. Now I may know why, as running it straight up gives No module named gimpfu!
I am on a Mac. Did the gimp2.4.5...dmg not compile gimpfu? Answer may be: Look for a dot .so file:
find /Applications/Gimp.app/ -name gimpfu\* | grep \.so /Applications/Gimp.app//Contents/Resources/lib/gimp/2.0/python/gimpfu.py /Applications/Gimp.app//Contents/Resources/lib/gimp/2.0/python/gimpfu.pyc /Applications/Gimp.app//Contents/Resources/lib/gimp/2.0/python/gimpfu.pyo == false positive.
What should I do next?
paul ----
% cd /Users/paultaney/gimp/gimp-2.4.7/plug-ins/pygimp/plug-ins
% ./python-fu-Vanderwalt.py
Traceback (most recent call last):
File "./python-fu-Vanderwalt.py", line 20, in
from gimpfu import * # imports the symbols gimp, pdb, register and main
ImportError: No module named gimpfu
----
Then I look for it under /Filters/Render/
and it is not there.
...is still the case. I am also pushing it twice, like: % cp python-fu-vanderwalt.py ~/.gimp-2.4/plug-ins % chmod +x ~/.gimp-2.4/plug-ins/python-fu-vanderwalt.py % cp python-fu-vanderwalt.py ~/gimp/gimp-2.4.7/plug-ins/pygimp/plug-ins % chmod +x ~/gimp/gimp-2.4.7/plug-ins/pygimp/plug-ins/python-fu-vanderwalt.py
RED, GRN, BLU = 0, 1, 2
bluemask = (image[...,BLU] > 1.4*image[...,GRN])& \
(image[...,BLU] > 1.4*image[...,RED])
blue_layer = gimp.layer(bluemask, width, height,
RGBA_IMAGE, 100, NORMAL_MODE)
image.addlayer(blue_layer, 0)
Q1) Is this even close? Q2) can I continue to use numpy (as I was with
wx.Python) or do these images have to be treated with scipy?
Hi Paul,
I found a few mistakes here and there. The main one is that Python is
very strict about indentation. After that, the "import Interpolate"
line I changed to "from scipy import interpolate as ma" - I'm not sure
if that is correct or not. Lastly, there were some items like
"PF_ITEM("foo", _("foo"),
"foo")" that I changed to
"PF_ITEM("foo",
"foo", "foo")" and also I added
"Vanderwalt" to the end on the plug-in resgistration. Oh yeah - I also added an 'except' in somewhere befor
a "finally"...So... now it still does not run correctly, but at least it registers
with GIMP :|BTW - starting GIMP from the command line will show syntax errors in
py-fu scripts.... Also editors like scite and eric (among others)
show indentation problems in Python by default - these are probably in
your repositories.HTH,
Chris
newb questions re python-fu
On Mon, Sep 22, 2008 at 12:37 PM, paul taney wrote:
Thanks very much, Chris.
I am using your file now and made a coupla repairs, afaict. But it still doesnt install. Now I may know why, as running it straight up gives No module named gimpfu!
AFAIK, you can't run gimp-fu scripts outside of GIMP. There is a python-fu console (XTNS->Python-Fu->Console) that will allow you to type/paste code in.
When it doesn't register, is there any console output from GIMP?
Chris
newb questions re python-fu
Thanks very much, Chris.
I am using your file now and made a coupla repairs,
afaict.
But it still doesnt install. Now I may know why, as
running
it straight up gives No module named gimpfu!
AFAIK, you can't run gimp-fu scripts outside of GIMP. There is a
python-fu console (XTNS->Python-Fu->Console) that will allow you to type/paste code in.When it doesn't register, is there any console output from GIMP?
No, but if I try to import it in the console I get something revealing:
import python-fu-vanderwalt
File "", line 1
import python-fu-vanderwalt
^
SyntaxError: invalid syntax
I would not be suprised if python objects to minus signs in module names, so I have fixed that in my push script:
% cat push.sh cp python-fu-vanderwalt.py ~/.gimp-2.4/plug-ins/python_fu_vanderwalt.py chmod +x ~/.gimp-2.4/plug-ins/python_fu_vanderwalt.py cp python-fu-vanderwalt.py ~/gimp/gimp-2.4.7/plug-ins/pygimp/plug-ins/python_fu_vanderwalt.py chmod +x ~/gimp/gimp-2.4.7/plug-ins/pygimp/plug-ins/python_fu_vanderwalt.py
Still, it does not appear in the Xtns browser or /Filters/Render.
Maybe it has to be Capitalized , as in the script...
Nope. That"s not it; I just tested for that, but it is something REALLY STUPID. Je garantir.
paul
newb questions re python-fu
On Mon, Sep 22, 2008 at 5:41 PM, paul taney wrote:
Thanks very much, Chris.
I am using your file now and made a coupla repairs,
afaict.
But it still doesnt install. Now I may know why, as
running
it straight up gives No module named gimpfu!
AFAIK, you can't run gimp-fu scripts outside of GIMP. There is a
python-fu console (XTNS->Python-Fu->Console) that will allow you to type/paste code in.When it doesn't register, is there any console output from GIMP?
No, but if I try to import it in the console I get something revealing:
import python-fu-vanderwalt
File "", line 1
import python-fu-vanderwalt
^
SyntaxError: invalid syntaxI would not be suprised if python objects to minus signs in module names, so I have fixed that in my push script:
% cat push.sh cp python-fu-vanderwalt.py ~/.gimp-2.4/plug-ins/python_fu_vanderwalt.py chmod +x ~/.gimp-2.4/plug-ins/python_fu_vanderwalt.py cp python-fu-vanderwalt.py ~/gimp/gimp-2.4.7/plug-ins/pygimp/plug-ins/python_fu_vanderwalt.py chmod +x ~/gimp/gimp-2.4.7/plug-ins/pygimp/plug-ins/python_fu_vanderwalt.py
Still, it does not appear in the Xtns browser or /Filters/Render.
Maybe it has to be Capitalized , as in the script...
Nope. That"s not it; I just tested for that, but it is something REALLY STUPID. Je garantir.
Hi Paul,
I did not look at it very carefully, but there are still indentation errors. I recommend opening it in Eric - it will literally show a "bug" on the line(s) in question. You're also missing a comma on line 92...
Chris
newb questions re python-fu
Hi Chris,
It was a versions problem: I am not running my local copy of 2.4.7, I am running the one that the .dmg installed at /Applications/Gimp.app.
Now that I"ve got that straight, I can run new scripts at
/Applications/Gimp.app/Contents/Resources/lib/gimp/2.0/plug-ins
but it will not recognize any installed at ~/.gimp-2.0/plug-ins.
I can live with that.
Sorry about the missing comma; it was late when I added that line. I am running Komodo, so I do see the parser"s hints as a rule.
Thanks again, paul
--- On Mon, 9/22/08, Chris Mohler wrote:
From: Chris Mohler
Subject: Re: [Gimp-developer] newb questions re python-fu To: "paul taney"
Cc: "gimp"
Date: Monday, September 22, 2008, 6:51 PM On Mon, Sep 22, 2008 at 5:41 PM, paul taney wrote:Thanks very much, Chris.
I am using your file now and made a coupla
repairs,
afaict.
But it still doesnt install. Now I may know
why, as
running
it straight up gives No module named gimpfu!
AFAIK, you can't run gimp-fu scripts outside
of GIMP.
There is a
python-fu console (XTNS->Python-Fu->Console)that
will allow you to type/paste code in.
When it doesn't register, is there any console
output
from GIMP?
No, but if I try to import it in the console I get
something revealing:
import python-fu-vanderwalt
File "", line 1
import python-fu-vanderwalt
^
SyntaxError: invalid syntaxI would not be suprised if python objects to minus
signs in module names,
so I have fixed that in my push script:
% cat push.sh cp python-fu-vanderwalt.py
~/.gimp-2.4/plug-ins/python_fu_vanderwalt.py
chmod +x ~/.gimp-2.4/plug-ins/python_fu_vanderwalt.py cp python-fu-vanderwalt.py
~/gimp/gimp-2.4.7/plug-ins/pygimp/plug-ins/python_fu_vanderwalt.py
chmod +x
~/gimp/gimp-2.4.7/plug-ins/pygimp/plug-ins/python_fu_vanderwalt.py
Still, it does not appear in the Xtns browser or
/Filters/Render.
Maybe it has to be Capitalized , as in the script...
Nope. That"s not it; I just tested for that, but
it is something
REALLY STUPID. Je garantir.
Hi Paul,
I did not look at it very carefully, but there are still indentation
errors. I recommend opening it in Eric - it will literally show a
"bug" on the line(s) in question. You're also missing a comma on line
92...Chris
/Filters/Render/Stroke to SVG...
When it doesn't register, is there any console output from GIMP?
Chris
I"ve got things working now and use numpy to convert bluelines to SVG lines or a python tuple that gets written out.
It could be of general interest for vectorizing if it treated a selection.
But I am converting scanned stripcharts, and the ink is blue... One y per x is all I need, and there would be a slick way to do that with numpy; I"m just using a stride for line thinning.
The part I dont understand is this; I pass my bluemask to (Fremlin"s) write_out(drawable, image) as the image, it fails the assertion and does not post...
numpy.array((image*256).round(0),"B")
def write_out(drawable, image):
"""by John Fremlin"""
byte_image = numpy.array((image*256).round(0),"B") # B is a ubyte
width = drawable.width
height = drawable.height
bpp = drawable.bpp
sys.stderr.write("write_out::drawable.width=%i drawable.height=%i drawable.bpp=%i\n" % (width, height, bpp))
pr = drawable.get_pixel_rgn(0, 0, width, height, True) assert(byte_image.size == width * height * bpp) pr[:,:] = byte_image.tostring()
/Filters/Render/Stroke to SVG...
Hi Paul,
On Fri, Sep 26, 2008 at 2:19 AM, paul taney wrote:
When it doesn't register, is there any console output from GIMP?
Chris
I"ve got things working now and use numpy to convert bluelines to SVG lines or a python tuple that gets written out.
It could be of general interest for vectorizing if it treated a selection.
But I am converting scanned stripcharts, and the ink is blue... One y per x is all I need, and there would be a slick way to do that with numpy; I"m just using a stride for line thinning.
The part I dont understand is this; I pass my bluemask to (Fremlin"s) write_out(drawable, image) as the image, it fails the assertion and does not post...
numpy.array((image*256).round(0),"B")
Which assertion fails?
def write_out(drawable, image):
"""by John Fremlin"""
byte_image = numpy.array((image*256).round(0),"B") # B is a ubyte width = drawable.width
height = drawable.height
bpp = drawable.bpp
sys.stderr.write("write_out::drawable.width=%i drawable.height=%i drawable.bpp=%i\n" % (width, height, bpp))pr = drawable.get_pixel_rgn(0, 0, width, height, True) assert(byte_image.size == width * height * bpp) pr[:,:] = byte_image.tostring()
You are passing an RGB array to this function. Are you certain that your destination drawable does not have an alpha channel (thus requiring you to pass an RGBA array)?
David
/Filters/Render/Stroke to SVG...
--- On Thu, 9/25/08, David Gowers wrote:
From: David Gowers
Hi Paul,
On Fri, Sep 26, 2008 at 2:19 AM, paul taney wrote:
When it doesn't register, is there any console
output
from GIMP?
Chris
I"ve got things working now and use numpy to
convert bluelines to SVG lines or a python tuple that gets written out.
It could be of general interest for vectorizing if it
treated a selection.
But I am converting scanned stripcharts, and the ink
is blue... One y per x is all I need, and there would be a slick way to do that with numpy; I"m just using a stride for line thinning.
The part I dont understand is this; I pass my bluemask
to (Fremlin"s) write_out(drawable, image) as the image, it fails the assertion and does not post...
numpy.array((image*256).round(0),"B")
Why does he multiply the image by 256 and elsewhere divide image/256?
Which assertion fails?
Line 207: assert(byte_image.size == width * height * bpp) fails, right before the blit.
def write_out(drawable, image):
"""by John Fremlin"""
byte_image =numpy.array((image*256).round(0),"B") # B is a ubyte
width = drawable.width
height = drawable.height
bpp = drawable.bpp
sys.stderr.write("write_out::drawable.width=%idrawable.height=%i drawable.bpp=%i\n" % (width, height, bpp))
pr = drawable.get_pixel_rgn(0, 0, width, height,
True)
assert(byte_image.size == width * height * bpp) pr[:,:] = byte_image.tostring() # blit
You are passing an RGB array to this function. Are you certain that
your destination drawable does not have an alpha channel (thus requiring you to pass an RGBA array)?
I have added a test for that, as best I know how; but it still fails at 207.
if drawable.has_alpha:
img = gimp.Image(width, height, RGBA_IMAGE)
new_layer = gimp.Layer(img, new_layer_name, width, height,
RGBA_IMAGE, opacity, NORMAL_MODE)
else:
img = gimp.Image(width, height, RGB_IMAGE)
new_layer = gimp.Layer(img, new_layer_name, width, height,
RGB_IMAGE, opacity, NORMAL_MODE)
/Filters/Render/Stroke to SVG...
Hi Paul.
On Fri, Sep 26, 2008 at 8:56 AM, paul taney wrote:
Why does he multiply the image by 256 and elsewhere divide image/256?
He's expecting an image with values ranging 0..1. If the values you are providing are 0..255, you'll need to remove both of those.
Which assertion fails?
Line 207: assert(byte_image.size == width * height * bpp) fails, right before the blit.
def write_out(drawable, image):
"""by John Fremlin"""
byte_image =numpy.array((image*256).round(0),"B") # B is a ubyte
width = drawable.width
height = drawable.height
bpp = drawable.bpp
sys.stderr.write("write_out::drawable.width=%idrawable.height=%i drawable.bpp=%i\n" % (width, height, bpp))
pr = drawable.get_pixel_rgn(0, 0, width, height,
True)
assert(byte_image.size == width * height * bpp) pr[:,:] = byte_image.tostring() # blit
You are passing an RGB array to this function. Are you certain that
your destination drawable does not have an alpha channel (thus requiring you to pass an RGBA array)?I have added a test for that, as best I know how; but it still fails at 207.
if drawable.has_alpha: img = gimp.Image(width, height, RGBA_IMAGE) new_layer = gimp.Layer(img, new_layer_name, width, height, RGBA_IMAGE, opacity, NORMAL_MODE) else:
img = gimp.Image(width, height, RGB_IMAGE) new_layer = gimp.Layer(img, new_layer_name, width, height, RGB_IMAGE, opacity, NORMAL_MODE)
This will not necessarily help, because your vanderwalt() routine is still producing an RGB image always.
David