2
$\begingroup$

I save my rendering results as 16-bit png files using Python as follow:

scene = bpy.context.scene
scene.render.image_settings.color_depth = '16'
scene.display_settings.display_device = 'sRGB'
scene.view_settings.view_transform = 'Raw'
scene.sequencer_colorspace_settings.name = 'Raw'
scene.use_nodes = True
for node in scene.node_tree.nodes:
    scene.node_tree.nodes.remove(node)
renderNode = scene.node_tree.nodes.new('CompositorNodeRLayers')

depthOutputNode = scene.node_tree.nodes.new('CompositorNodeOutputFile')
depthOutputNode.format.file_format = 'PNG'
depthOutputNode.format.color_depth = '16'
depthOutputNode.format.color_mode = 'RGB'
depthOutputNode.base_path = 'somePath/'
depthOutputNode.file_slots[0].path = 'fileNameDepth#'

scene.node_tree.links.new(renderNode.outputs[2], depthOutputNode.inputs[0])

bpy.ops.render.render(write_still=True)

However, it seems that Blender stores/exports the rendering in a different format than I expected. I loaded the images in Python after rendering and I found out that the maximum value for all pixels is not more than 255 (8-bits). Does anyone know why this is the case? I wonder, would storing the depth maps in OpenEXR format resolve the issue?

$\endgroup$
2
  • $\begingroup$ What pymodule are you using to open the image? It may not support 16 bit png. I see a 16 bit png saved here. Try opening the image in krita/blender and look at what the image format is. Do you have iv installed? - it is a utility from the openimageio project. $\endgroup$
    – sambler
    Commented Mar 31, 2018 at 5:05
  • $\begingroup$ @sambler I tried a couple of modules by they all assured me that the pixel values never go beyond 255. I tried imageio and scipy.ndimage.imread $\endgroup$
    – Amir
    Commented Mar 31, 2018 at 14:47

1 Answer 1

3
$\begingroup$

It doesn't matter what the bit depth is if the format is output referred. 32, 16, and 8 bit integer, and even in float instances, may result in output referred ranges, typically 0.0 to 1.0. In these instances, the bit depth doesn't increase the range, merely the number of steps between them.

The only real option would be a float format that supports deeper data ranges such as EXR or TIFF. Blender's TIFF support did not appear to support float instances when last examined, and even if it did it may be bound to output referred ranges.

$\endgroup$
7
  • $\begingroup$ While true, that isn't the issue. Blender is being told to save a 16bit image but when opened it appears to be only 8bit. $\endgroup$
    – sambler
    Commented Mar 31, 2018 at 7:55
  • $\begingroup$ What does a referred output mean here? Do you mean that the values are "clamped"? So based on your response, the only way I can get depth maps whose range is realistic is by outputting my rendering results as OpenEXR. Is that correct? $\endgroup$
    – Amir
    Commented Mar 31, 2018 at 14:44
  • 3
    $\begingroup$ If you are attempting to save scene referred emissions or data beyond the 0.0 to 1.0 range, EXR is the only valid option. PNG is a cancer of a format for other reasons as well. $\endgroup$
    – troy_s
    Commented Mar 31, 2018 at 15:07
  • 2
    $\begingroup$ EXR is the only format that will allow you to save the Z-pass unadulterated. $\endgroup$
    – user1853
    Commented Mar 31, 2018 at 15:45
  • $\begingroup$ @troy_s Thanks for your answer. As explained here I cannot currently save my rendering results in OpenEXR format. Could the HDR format be a good alternative for now? Could you also take a look at this question? I have a pretty strong feeling that the uninterpretability issue is highly tied to the problem here. $\endgroup$
    – Amir
    Commented Mar 31, 2018 at 19:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .