Anyone know how to output an uncompressed image in floating point precision?
I’m trying to use the depth buffer output in a separate program and need this precision, but also don’t want to write a reader for the more complex formats (e.g. openEXR). Even just saving the raw values with no header would be fine, but I haven’t found a way to do this after much searching.
You can create a script to do this:
Replace “TEMP.jpg” with the name of your image inside Blender
Replace “imageText.txt” by the file name you wish to output. The file will be located inside your Blender installation directory.
import Blender
from Blender import Image
NAME = "TEMP.jpg"
OUT = "imageText.txt"
image = False
try:
image =Image.Get(NAME)
except:
print "Couldn't find the image specified"
print "!"
if image:
outFile = False
try:
outFile = file(OUT, "w")
except:
print "problem creating the file"
if outFile:
width = image.size[0]
height = image.size[1]
outFile.write(str(width))
outFile.write("x")
outFile.write(str(height))
outFile.write("
")
for i in range(0, width):
for j in range(0,height):
for comp in image.getPixelF(i, j):
outFile.write(str(comp))
outFile.write(",")
outFile.write("
")
This will create a file with the image.
The first line will be widthxheight
all the lines afterwards would be r,g,b,a,
note that the script scans the rows from left to right, and then the rows from top to bottom.
Importing this is easy, since all the pixel data is in normalized floating point values (between 0.0 to 1.0) written as strings
It’s not very memory efficient but it’s certainly easy to import and export =)
Thank you, at least I know this is probably possible now using scripting.
What I’m trying to do is render an animation, and for each frame output a separate file with the depth values for each pixel. Eventually I would also like to output the color data as well, but I’ll take what I can get for now. Currently I’m using compositing to access the z-buffer.
My questions now are:
Do I need to render all the frames from within the script, or can I run the script from the GUI automatically while rendering?
What is the name of the currently rendered image variable? (if needed for #1)
My guess would be that you would need to render from within the script. That’s what my experience with the blender python API tells me, but I could be wrong. So my guess is you have access to the currently rendered frame. I haven’t looked into this yet though.
I’m just curious though, what are you using the z-depth for?
Thanks Scuey, that seems to be the consensus after doing some more reading. I’ve never used python before, so I’ll have to add it to my list of things to learn.
I am trying to simulate scanning methods for a 3D object with different light sources, and I need the actual depth as well as the depth calculated by a program from the rendered images for comparison. Blender is handy for setting up a camera precisely and automating the movement around an object, but without a way to output easily parsable floating point precision images this is mostly useless.
The program needs to be in C# which has no native support for hdr formats, so my choices are to:
Find a library that can read complex formats (haven’t found one yet).
Read in a simple file format directly (easy, but Blender needs to support outputting it).
Force Blender via script to output a file for #2.
I was actually very surprised Blender can’t output any simple floating point formats as this would seem to be absolutely trivial in comparison the other formats it supports. Maybe I’ll try to request this as a future feature.