I guess I might as well try and make my first 2.5 script.
Does anyone know how to get the pixel value from an image texture using the Blender 2.5 API?
I guess I might as well try and make my first 2.5 script.
Does anyone know how to get the pixel value from an image texture using the Blender 2.5 API?
I just found out how to read and write the pixels in an image.
Still testing though
Sorry the Python is mostly in dutch and is somewhat clums. I; just stumbled over your question and I have no time to translate the lot now.
Annyway here it is:
import Blender
from Blender import Texture,Image,Material
scene = Blender.Scene.GetCurrent()
for ob in scene.objects:
print ob
if ob.name == ‘Bomen’:
bomen = ob
print 'Gevonden bomen? = ', bomen
#Get proper material
materials = bomen.getMaterials(0)
for mat in materials:
print mat
if mat.name == ‘MijnKaart’:
MijnKaart = mat
print 'Materiaal Kaart gevonden = ', MijnKaart
#Get proper MaterialTexture (MTex)
Textures = MijnKaart.getTextures()
for Mtex in Textures:
print Mtex
if Mtex <> None:
print Mtex.tex.name
if Mtex.tex.name == ‘Kaart’:
MijnTexture = Mtex
print 'Texture van de kaart gevonden = ', MijnTexture
print 'BestandsNaam van kaart = ', MijnTexture.tex.image.filename
#Get size of Image
Kaart = MijnTexture.tex.image
MaxCoord = Kaart.getMaxXY()
MaxX = MaxCoord[0]
MaxY = MaxCoord[1]
print ‘Grootte van deze afbeelding = ‘,MaxX,’,’,MaxY
#Read all pixels in the image
for xpos in range (0,MaxX-1):
for ypos in range (0,MaxY-1):
rgbA = Kaart.getPixelHDR(xpos,ypos)
#print xpos,’,’,ypos,’,’,rgbA (don’t run this line; printing take a lot of time)
if you do it with english name and working properly
can you upload a new working script
this might a good example for further use in futur!
Happy blendering
I shall do so in a view day’s.
But this isn’t for Blender 2.5 is it?
I thought “import Blender” no longer works in 2.5?
You are right, I haven 2.49a
Didn’t know there was a 5.0
You are right, I have 2.49a
Didn’t know there was a 5.0
Atom,
pixel access is not in the API yet.
Hey Blenderers,
I got things working now, though maybe not like some of you like it to.
There is indeed no way to get the RGB-value of a point on an object on a simpel way
(say: you throw a ray on the object, get its hitposition and get its RGB-value).
But there is a way to get the RGBA-value of pixels on a plane.
That is what this reply is about.
Ok what did I do:
Okay, this is not straight forward simple, but it works.
I build in a lot of debug-controls and left them in, so you can see what the results are during the running of the script (also check the console).
To test the lot I made another script (SendData) that sends the RGB-value to a memory-mapped file called ‘MyMapping’.
This file is shared with a little program called ‘GetBlenderRGB.exe’. This is an ‘always-on-top’ program that shows you the RGB-values just found and the corresponding color.
To test for your self:
http://members.home.nl/j.j.balster/Blender/GetBlenderRGB.exe
http://members.home.nl/j.j.balster/Blender/Pick_RGBA.blend
I hope this works as well for you as it worked for me and satisfies some of your needs.
Greeting to you all
JBal
I just want the pixel value of an image texture, not an object in the scene. Say I have a 64x64 image. I want the RGBA value for any given coordinate, like 32,17. I also would need the width and height of the image as well.
I basically need all the code for the material portion as well.
Say I have the name of a material, and I am talking about API 2.5, I will need to be able to fetch the material and determine if there is a texture associated with it. Then I need to be able to examine the texture and see if it’s type is an image. Then I need to examine the image for the width, height and and RGBA value for a given pixel within the image itself.
I might misunderstand you, but is’nt this just what my script does?
(appart from the check for the pressence of a picture. I skip this because I know for sure there is a picture).
JBal
by the way:
Did you run the test?
What do you think of it?