0

I'm looking for a way to get image pixels as numpy array from actual image files (.png, .jpeg, .tif, etc.) without loading them into Blender. I know there are tons of image processing modules and packages but afaik none of them is included in Blender, so they can not be used for add-ons. Anyway including the whole someone's 3rd party module in the add-on just for this task doesn't seem like a solution.

The question is: is there a way to access image files pixel data using only built-in modules? I need to do just a simple image processing (blending several images into a single one) and getting access to image pixels bypassing Blender API would allow to use threading or multiprocessing (which Blender API doesn't support at the moment) to speed up this process.

UPD. As I see now it is more complicated than it seemed at first. Each image file type has its own file layout. You can easily get the bytes sequence from file with built-in img_file = open().read() and then convert bytes to floats for example with memoryview(img_file[:]).cast('f') but you need to know exactly what bytes in the file represent pixel data and in what order to decode them properly. Trying to get through OpenEXR file layout which I exactly need for my add-on seems beyond my ability at the moment.

Andrey Sokolov
  • 1,111
  • 10
  • 25
  • 1
    You can use third party modules in blender, check the following link https://blender.stackexchange.com/questions/5287/using-3rd-party-python-modules – Ivan Domenech Sep 15 '20 at 10:11
  • Thank you very much, it definitely may be useful. Though I am still not sure whether installing third party modules together with add-on and changing original blender python files is a good practice. – Andrey Sokolov Sep 15 '20 at 10:25
  • 1
    The only bundled package that can help you is numpy in Blender. Although you will need to deal with all possible file format and the data for various type of images. It is not that bad to install new module inside Blender with addon if you do "inform" user that you are going to download and install required packages. – HikariTW Sep 15 '20 at 13:36
  • Thank you. What I need is information about how to gain access to pixel data in Open EXR files. I can open the file and read all its bytes but I don't know how to determine which of them represent exact pixel data or at least where to get any info about it. – Andrey Sokolov Sep 15 '20 at 16:00
  • 1
    OpenEXR is kind of complicate to read from file without additional library, you can try to extract the color data from it for sure – HikariTW Sep 16 '20 at 04:22

0 Answers0