Creating verticies from a black and white image

I want to create a python script that takes a two color png image and create vertices from the black points on it. How can I do that?

i think you need to import an external lib for images
and there are 2 available one for blender and an external lib you can add

then you can play with images

but dodn’t remember right now what then name is

hope somone can come up with the right name

happy 2.5

The library I found (and it will work for what I need it to do) is called the python imaging library (PIL) and can be found here: http://www.pythonware.com/products/pil/

However, in blender when I type “from PIL import Image” I get this error:
Traceback (most recent call last):
File “Text”, line 1, in <module>
ImportError: No module named PIL

How can I fix that? When I open my command line, and type python, I can access PIL just fine.

yes remember PIL that’s an external lib i think you need to do an isntall for this if i remember well
or palce it in same foler the the blend file
and i think it’s not using the same python then blender!

but there is another iamge module from python also which youc an use wihtout external lib!
search the python site it should be there but don’t remember the name !

if you find let us know with site i’ll take note of it this time!

now you need to scan the iamge pixel by pixel then deiced if it is inside a range of color

did you find these command in PIL ?

are you going to share the script your doing - might be intersting for other people too!

and does PIL work in 2.5 ?

Thansk

As far as I can tell, the only image module I can find is PIL.
I typed python setup.py install after I cd’d into the PIL source directory. If I type python, then I type from PIL import Image it works just fine. However, if I type that into blender, it gives me the error message I told you about earlier.

How can I get blender to use PIL?

found the folder for theses image scripts



import Blender
from Blender import *
from Blender import Image, Window 


from math import *
#import PIL
#from PIL import Image
 
#pic = Image.open("c:/santa5.jpg")

#pic = Image.open("C:\Users\RJ\0python\heightmap\img7.jpg")
pic = Image.Load("c:/Capture6.jpg")


width = pic.size[0]
ht = pic.size[1]
me = NMesh.GetRaw()
df = list(pic.getdata())
for i in range (0,ht):
    for j in range (0,width):
        loc = j + (i*width)
        dy = df[loc]
        dz = dy[0]*.1 #grab first tuple
        v = NMesh.Vert(i,j,dz)
        me.verts.append(v)
for u in range (0,ht - 1):
   for w in range (0,width - 1):
      f= NMesh.Face()
      f.v.append (me.verts[u*width+w])
      f.v.append (me.verts[u*width+w+1])
      f.v.append (me.verts[(u+1)*width+w+1])
      f.v.append (me.verts[(u+1)*width+w])
      f.smooth = 1
      me.faces.append(f)
NMesh.PutRaw(me, "piltest", 1)
Blender.Redraw()
print ht
print width



so it’s directly in blender or python module cou can import in blender
don’t know if this script works but try it
i know there is one working but did not have the time to test theses scripts
but NMESH is deprecated anyway so need some changes !

called simply imaged

hope you can find some doc on this !

let me know if you find it !

are you going to share the script your working on?

are you gong to do this in 2.5 ?

happy 2.5

Ok, I tried to run the script on 2.49b on Snow Leopard, and I got the following error:
AttributeError: ‘Blender Image’ object has no attribute ‘getdata’

I am new to python, so I have no idea how to fix this problem.

Do you have any ideas?

well i’m on vista

but as i said i never really used that one

so may be open a new thread forto fin outwhre the doc is for this iamge module
i think this instruction is aprt of this module

and let me know cause i don’t know where it is ?

after may be i can try to help you

happy 2.5

tested this one this morning and it’s working fine in 2.49


 import Blender
from Blender import *
from math import *
import PIL
from PIL import Image
 
#pic = Image.open("c:/santa5.jpg")

#pic = Image.open("C:\Users\RJ\0python\heightmap\img7.jpg")
pic = Image.open("c:/he2.jpg")


width = pic.size[0]
ht = pic.size[1]
me = NMesh.GetRaw()
df = list(pic.getdata())
for i in range (0,ht):
    for j in range (0,width):
        loc = j + (i*width)
        dy = df[loc]
        dz = dy[0]*.1 #grab first tuple
        v = NMesh.Vert(i,j,dz)
        me.verts.append(v)
for u in range (0,ht - 1):
   for w in range (0,width - 1):
      f= NMesh.Face()
      f.v.append (me.verts[u*width+w])
      f.v.append (me.verts[u*width+w+1])
      f.v.append (me.verts[(u+1)*width+w+1])
      f.v.append (me.verts[(u+1)*width+w])
      f.smooth = 1
      me.faces.append(f)
NMesh.PutRaw(me, "piltest", 1)
Blender.Redraw()
print ht
print width
 
 

try it but still need to find doc on this iamge module
i’v open a new thread on this

salutatons

Ok, I got PIL working. Hopefully I can find time to write the code.

are you going to share your script or a part of it
i’d like to make one where your read a jpg get the RGB values for each pixel
and decided to change it if inside a certain range of RGB values

don’t know if you gone have that ?

let me know

happy 2.5

It is going to be for 2.49b, because that is the most recent release of what I consider to be “stable.”

Also, I probably will share my script, once I have something to share.