Pixels and resolution not for multilayer EXR and Render Result #53768

Open
opened 2018-01-12 10:48:41 +01:00 by Vincent Girès · 34 comments

System Information
CentOS - GTX 1070

Blender Version
2.79

Short description of error
Pixels and resolution are not available with multilayer EXR or Render Result images.

Exact steps for others to reproduce the error
import bpy
data = bpy.data
image = data.images['Render result or multilayer EXR']
print(image.pixels) # length is 0
print(image.resolution) # return always Vector((0.0, 0.0))

It is working with regular EXR file.

**System Information** CentOS - GTX 1070 **Blender Version** 2.79 **Short description of error** Pixels and resolution are not available with multilayer EXR or Render Result images. **Exact steps for others to reproduce the error** import bpy data = bpy.data image = data.images['Render result or multilayer EXR'] print(image.pixels) # length is 0 print(image.resolution) # return always Vector((0.0, 0.0)) It is working with regular EXR file.
Author

Added subscriber: @VincentGires

Added subscriber: @VincentGires

#102806 was marked as duplicate of this issue

#102806 was marked as duplicate of this issue

#90694 was marked as duplicate of this issue

#90694 was marked as duplicate of this issue

#90460 was marked as duplicate of this issue

#90460 was marked as duplicate of this issue
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

true. dont know if you know this already, but a workaround for now could be this
can have a look (, but not sure how involved this task will end up being...)

true. dont know if you know this already, but a workaround for now could be [this ](https://blender.stackexchange.com/questions/2170/how-to-access-render-result-pixels-from-python-script#23309) can have a look (, but not sure how involved this task will end up being...)
Philipp Oeser self-assigned this 2018-01-18 17:55:05 +01:00

Added subscriber: @brecht

Added subscriber: @brecht

@lichtwerk, since you claimed this task, are you working on a solution?

This is indeed a gap in our Python API that would be good to fix, though not strictly a bug so up to you if you want to close it or fix it.

@lichtwerk, since you claimed this task, are you working on a solution? This is indeed a gap in our Python API that would be good to fix, though not strictly a bug so up to you if you want to close it or fix it.
Member

@brecht: yep, I'm behind schedule here, but I will have a look later today

@brecht: yep, I'm behind schedule here, but I will have a look later today
Member

OK, had a first look, but there are remaining questions that I have to wrap my head around.

Getting pixels or size would require aquiring an ImBuf, however the way it is normally done involves an ImageUser (that in turn would have information regarding the corresponding scene, layer, pass, renderslot).
We dont have that from python and I am unsure on what to use as default here. (which scenes renderlayer? which pass, slot?)

And I am still looking at how this "Render Result" is stored in the main database "images". e.g. different scenes RenderResults can have different sizes, however other properties (e.g. display_aspect) are shared across scenes renderResults as it seems...

Long story short: needs a bit more time -- I know, I'm slow... :)

OK, had a first look, but there are remaining questions that I have to wrap my head around. Getting pixels or size would require aquiring an ImBuf, however the way it is normally done involves an ImageUser (that in turn would have information regarding the corresponding scene, layer, pass, renderslot). We dont have that from python and I am unsure on what to use as default here. (which scenes renderlayer? which pass, slot?) And I am still looking at how this "Render Result" is stored in the main database "images". e.g. different scenes RenderResults can have different sizes, however other properties (e.g. display_aspect) are shared across scenes renderResults as it seems... Long story short: needs a bit more time -- I know, I'm slow... :)
Philipp Oeser removed their assignment 2018-02-04 22:21:19 +01:00
Member

Unfortunately I'll only be able to look at this in April again, so let others take over....

Unfortunately I'll only be able to look at this in April again, so let others take over....

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Brecht Van Lommel self-assigned this 2018-03-19 22:40:32 +01:00

This is really a known to do item and not a bug, so closing, feature requests are handled elsewhere.

This is really a known to do item and not a bug, so closing, feature requests are handled elsewhere.
Member

Changed status from 'Archived' to: 'Open'

Changed status from 'Archived' to: 'Open'
Member

also added to TODO here: https:*wiki.blender.org/index.php/Dev:Source/Development/Todo/Scripting
Will have look again if time permits

also added to TODO here: [https:*wiki.blender.org/index.php/Dev:Source/Development/Todo/Scripting ](https:*wiki.blender.org/index.php/Dev:Source/Development/Todo/Scripting) Will have look again if time permits

Added subscriber: @pedroreis.ad

Added subscriber: @pedroreis.ad

I'm currently in a bind at work, and this would be tremendously helpful. I need to access Render Result pixels, and the most lightweight way to do so would be to access them directly. Performance is highly critical for the job at hand, and using GPU offscreen techniques proved to be quite inefficient.

I am willing to help out in this particular task, although it would be my first commit to Blender. I'll become more informed on how to properly contribute code to Blender now, and then try to fix this issue. I'll comment again if I'm blocked somewhere!

I'm currently in a bind at work, and this would be tremendously helpful. I need to access Render Result pixels, and the most lightweight way to do so would be to access them directly. Performance is highly critical for the job at hand, and using GPU offscreen techniques proved to be quite inefficient. I am willing to help out in this particular task, although it would be my first commit to Blender. I'll become more informed on how to properly contribute code to Blender now, and then try to fix this issue. I'll comment again if I'm blocked somewhere!

Managed to do it, but it is a hacky solution, so hacky that I'm just gonna post it here instead of actually going through with a commit.

Basically the fact that the Render Result has no ImageUser makes the ".pixels" query to return empty. To mitigate this I did the following:

https://github.com/dfelinto/blender/pull/48/files

I used an available fork on GitHub to simplify the process. This commit outlines what was done, but it was basically add an ImageUser to the Image struct, and that ImageUser is assigned to in the OpenGL render init phase. In the image_get_render_result, where this function returned null previously, it now uses the new ImageUser assigned to the Image as a way to get render and scene information.

It's really hacky, but it might help other people :)

Managed to do it, but it is a hacky solution, so hacky that I'm just gonna post it here instead of actually going through with a commit. Basically the fact that the Render Result has no ImageUser makes the ".pixels" query to return empty. To mitigate this I did the following: https://github.com/dfelinto/blender/pull/48/files I used an available fork on GitHub to simplify the process. This commit outlines what was done, but it was basically add an ImageUser to the Image struct, and that ImageUser is assigned to in the OpenGL render init phase. In the image_get_render_result, where this function returned null previously, it now uses the new ImageUser assigned to the Image as a way to get render and scene information. It's really hacky, but it might help other people :)
Brecht Van Lommel removed their assignment 2020-01-18 14:24:01 +01:00

Added subscriber: @Andrey_Sokolov

Added subscriber: @Andrey_Sokolov

Is there still no direct way to get pixel data from Render Result and Open EXR Multilayer images through Python API in Blender? It would be extremely useful because reconnecting Viewer to get pixels from each pass in RGBA, convert them to their original passes' types (e.g. Value, Vector, etc.), store in individual images and use pixels from them is pretty time and memory consuming way, especially with animation and dozens of Render Layers with many different passes in the project.

Is there still no direct way to get pixel data from Render Result and Open EXR Multilayer images through Python API in Blender? It would be extremely useful because reconnecting Viewer to get pixels from each pass in RGBA, convert them to their original passes' types (e.g. Value, Vector, etc.), store in individual images and use pixels from them is pretty time and memory consuming way, especially with animation and dozens of Render Layers with many different passes in the project.

Added subscribers: @3di, @PratikPB2123

Added subscribers: @3di, @PratikPB2123
Member

Added subscriber: @derekbarker

Added subscriber: @derekbarker
Member

@pedroreis.ad : your hack would only work for OGLRender afaict.
But if we want to solve this for all Render Results, we would need to make getter functions in RNA_api_image that allow to pass in an ImageUser (this could either be taken from e.g. an Editor like the Image Editor -- or ideally even be created from scratch in python). Something along the lines of https:*docs.blender.org/api/3.4/bpy.types.Image.html#bpy.types.Image.filepath_from_user.
I mean, there would need to be a way to tell which layer/pass we actually want to read from, right?

@brecht : would this be the right approach?

@pedroreis.ad : your hack would only work for `OGLRender` afaict. But if we want to solve this for all Render Results, we would need to make getter functions in `RNA_api_image` that allow to pass in an [ImageUser ](https:*docs.blender.org/api/3.4/bpy.types.ImageUser.html) (this could either be taken from e.g. an Editor like the Image Editor -- or ideally even be created from scratch in python). Something along the lines of https:*docs.blender.org/api/3.4/bpy.types.Image.html#bpy.types.Image.filepath_from_user. I mean, there would need to be a way to tell which layer/pass we actually want to read from, right? @brecht : would this be the right approach?

The right approach is not obvious. Ideally there will be a new data structure that gives full access to views, layers, passes. With ability to iterate over them, read and write pixels, etc. This needs a whole design.

I would rather not have some quick hack.

The right approach is not obvious. Ideally there will be a new data structure that gives full access to views, layers, passes. With ability to iterate over them, read and write pixels, etc. This needs a whole design. I would rather not have some quick hack.

Added subscriber: @tpet

Added subscriber: @tpet

Can we get access to multilayer EXR from python while the new render result data access design is not even a glint in anyone's eye? Perhaps python bindings for the OpenEXR module already in use by Blender?

Can we get access to multilayer EXR from python while the new render result data access design is not even a glint in anyone's eye? Perhaps python bindings for the OpenEXR module already in use by Blender?

Yeah, not being able to access pixels is adding multiple seconds to what should be a sub 100ms workflow, and its littering our workspace with files we do not need that we just have to call extra functions to delete in the end. writing to disk to access rendered pixels is a little absurd. Prime example of adding disk to the equation being really dumb is the new tile system in cycles that often renders 2-3x slower than no tiles.

Yeah, not being able to access pixels is adding multiple seconds to what should be a sub 100ms workflow, and its littering our workspace with files we do not need that we just have to call extra functions to delete in the end. writing to disk to access rendered pixels is a little absurd. Prime example of adding disk to the equation being really dumb is the new tile system in cycles that often renders 2-3x slower than no tiles.

Plus there's no way to write the multilayer EXR data back out that I can see. I basically need to edit some of the layers on a multilayer EXR, then overwrite the original with the updated layers. The only way I can think of is to:

  • load a multilayer EXR into a new image block
  • load it into a image node in the compositor
  • connect each of it's sockets to a file output node set to exr (not multilayer)
  • write it out with render.render()
  • load in each of the EXR's individually
  • modify the images
  • refresh the compositor
  • create another file output node, this time multilayer
  • wire all the individual images to it
  • do another render.render() to save all the images back as layers

It's a nightmare.

Plus there's no way to write the multilayer EXR data back out that I can see. I basically need to edit some of the layers on a multilayer EXR, then overwrite the original with the updated layers. The only way I can think of is to: - load a multilayer EXR into a new image block - load it into a image node in the compositor - connect each of it's sockets to a file output node set to exr (not multilayer) - write it out with render.render() - load in each of the EXR's individually - modify the images - refresh the compositor - create another file output node, this time multilayer - wire all the individual images to it - do another render.render() to save all the images back as layers It's a nightmare.

Added subscriber: @EAW

Added subscriber: @EAW

Out of interest, should the EXR issue and the Render result data be two seperate issues? It appears that the render data not being accessible is a feature request, but the EXR issue a bug (because image datablock pixel access works for all other file types). @EAW @lichtwerk ? Might be that the image datablock EXR bug is not being addressed whilst unnecessarily waiting for a redesign of the render result data structure? I'm guessing the image datablock already has the necessary structure that enables the compositor to access the layers and views.

Out of interest, should the EXR issue and the Render result data be two seperate issues? It appears that the render data not being accessible is a feature request, but the EXR issue a bug (because image datablock pixel access works for all other file types). @EAW @lichtwerk ? Might be that the image datablock EXR bug is not being addressed whilst unnecessarily waiting for a redesign of the render result data structure? I'm guessing the image datablock already has the necessary structure that enables the compositor to access the layers and views.

I just spoke with gpt3 chatbot, and he's in agreement that the blender api should allow access to the multilayer EXR pixels as numpy array :D

image.png

and when I asked last night:

import bpy



# Open the EXR file using bpy.data.images.load()

exr_image = bpy.data.images.load("my_exr_image.exr")



# Loop over the layers in the EXR file

for layer in exr_image.layers:

    # Print the layer name and type

    print(layer.name, layer.layer_type)



    # Get the layer data as a NumPy array

    layer_data = layer.get_pixels()
I just spoke with gpt3 chatbot, and he's in agreement that the blender api should allow access to the multilayer EXR pixels as numpy array :D ![image.png](https://archive.blender.org/developer/F13991283/image.png) and when I asked last night: ``` import bpy # Open the EXR file using bpy.data.images.load() exr_image = bpy.data.images.load("my_exr_image.exr") # Loop over the layers in the EXR file for layer in exr_image.layers: # Print the layer name and type print(layer.name, layer.layer_type) # Get the layer data as a NumPy array layer_data = layer.get_pixels() ```

Ton Roosendal suggested he agreed it would be a good for this to be a feature of the blender python api. He recommended to make some noise on right click select if we want this in Blender, so upvote it here:

https://blender.community/c/rightclickselect/27zP/

https://blender.community/c/rightclickselect/A1n7/

Ton Roosendal suggested he agreed it would be a good for this to be a feature of the blender python api. He recommended to make some noise on right click select if we want this in Blender, so upvote it here: https://blender.community/c/rightclickselect/27zP/ https://blender.community/c/rightclickselect/A1n7/

Added subscriber: @cdsousa

Added subscriber: @cdsousa
Brecht Van Lommel added this to the Render & Cycles project 2023-02-07 19:07:34 +01:00
Philipp Oeser removed the
Interest
Render & Cycles
label 2023-02-09 13:59:01 +01:00

Mom, please, can we have those pixels? It has been 10 years. 😭

Mom, please, can we have those pixels? It has been 10 years. 😭
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
11 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#53768
No description provided.