Installing openexr in Matlab

34 views (last 30 days)
Imran Kanjoo
Imran Kanjoo on 12 Oct 2020
Commented: Walter Roberson on 23 Sep 2022
I am trying to install OpenExr to read .exr files but I get some error which do no understand. I have downloaded the scripts from this and this link. In the instruction file, it has been mentioned to put correct paths.
the downloaded files are located as
D:\D\ZJU Data\HDR\softwre\openexr
D:\D\ZJU Data\HDR\softwre\openexr\IlmImf
D:\D\ZJU Data\HDR\softwre\openexr\Half
D:\D\ZJU Data\HDR\softwre\openexr\Iex
D:\D\ZJU Data\HDR\softwre\openexr\IlmThread
D:\D\ZJU Data\HDR\softwre\openexr\Imath
The make.m file is modified for the paths to make the file as below
clc;
verbose = false;
% -----------------------------------------------
build_files = { 'exrinfo.cpp', ...
'exrread.cpp', ...
'exrreadchannels.cpp', ...
'exrwrite.cpp', ...
'exrwritechannels.cpp'};
companion_files = { 'utilities.cpp', ...
'ImfToMatlab.cpp', ...
'MatlabToImf.cpp'};
additionals = {};
if(verbose == true)
additionals = [additionals, {'-v'}];
end
for n = 1:size(build_files, 2)
if(verbose == true)
clc;
end
file = cell2mat(build_files(n));
disp(['Building ', file]);
mex(file, companion_files{:}, ...
'-D:\D\ZJU Data\HDR\softwre\openexr\OpenEXR', ...
'-D:\D\ZJU Data\HDR\softwre\openexr\', ...
'-IlmImf', ...
'-Iex', ...
'-Imath', ...
'-IHalf', ...
'-IlmThread', ...
'-largeArrayDims', ...
additionals{:});
end
clear;
disp('Finished building OpenEXR for Matlab');
But I get the foloowing error
Error using mex
g++: error: Files\MATLAB\R2018b/extern/include -IC:\Program: Invalid argument
g++: error: Files\MATLAB\R2018b/simulink/include -fexceptions -fno-omit-frame-pointer -std=c++11 -O2 -fwrapv -DNDEBUG D:\D\ZJU: Invalid argument
g++: error: Data\HDR\softwre\openexr\exrinfo.cpp -o C:\Users\IMRANK~1\AppData\Local\Temp\mex_230748490719102_4660\exrinfo.obj : Invalid argument
g++: fatal error: no input files
compilation terminated.
I am using MinGW64 compiler.
Can you please tell me what exactly is the error?
  1 Comment
Zaixi Shang
Zaixi Shang on 20 Oct 2020
I am doing the same thing and get similiar problem. The auther of this code doesn't maintain the project anymore...

Sign in to comment.

Answers (2)

Sofía Miñano
Sofía Miñano on 20 Mar 2021
I think you may have mistaken the -D flag in the mex command with the -I and -L flags. From the docs: "The -D options define C preprocessor definitions". The -I flag points to the 'include' directory and the -L and -l flags are used to point to the relevant libraries.
In case it's useful, here are the steps I used to compile the OpenEXR bindings from the site you referenced. I used a Windows 10 machine and Anaconda as package mananger.
1. Get OpenEXR C++ library from Anaconda here. For me it saves the package at: C:\Users\Sofi\Anaconda3\pkgs\openexr-2.5.5-hab3b255_0
2. Get IlmBase from Anaconda here. Saves it at: C:\Users\Sofi\Anaconda3\pkgs\ilmbase-2.5.5-h12d4b20_0
3. Get OpenEXR Bindings for MATLAB from here
4. Modify the make.m script from the MATLAB bindings to point to the correct directories. In particular you need to point to:
- the include libraries of OpenEXR and IlmBase
- the parent folders for the libraries IlmImf, Iex, Imath, Half and IlmThread. I input these paths as -L<libraryfolder> -l<libraryname> (MATLAB expands it to .lib)
- After this, I was getting a 'error LNK2019' when running the make.m script. To fix it you need to:
- add a processor definition for OPENEXR_DLL, with the -D flag for mex
- remove a processor definition for HALF_EXPORT, with the -U flag
This is how the final input to the mex function looked like for me:
mex(file, companion_files{:}, ...
'-DOPENEXR_DLL','-UHALF_EXPORT',... % to fix _toFloat link issue and _eLut link issue
'-Ic:\Users\Sofi\Anaconda3\pkgs\openexr-2.5.5-hab3b255_0\Library\include\OpenEXR',... OpenEXR include
'-Ic:\Users\Sofi\Anaconda3\pkgs\ilmbase-2.5.5-h12d4b20_0\Library\include\OpenEXR',... Ilmbase include
'-Lc:\Users\Sofi\Anaconda3\pkgs\openexr-2.5.5-hab3b255_0\Library\lib\', '-lIlmImf',... %path to IlmImf.lib
'-Lc:\Users\Sofi\Anaconda3\pkgs\ilmbase-2.5.5-h12d4b20_0\Library\lib\','-lIex',... %path to Iex.lib
'-Lc:\Users\Sofi\Anaconda3\pkgs\ilmbase-2.5.5-h12d4b20_0\Library\lib','-lImath',... %path to Imath.lib
'-Lc:\Users\Sofi\Anaconda3\pkgs\ilmbase-2.5.5-h12d4b20_0\Library\lib','-lHalf',... %path to Half.lib
'-Lc:\Users\Sofi\Anaconda3\pkgs\ilmbase-2.5.5-h12d4b20_0\Library\lib','-lIlmThread',... %path to IlmThread.lib
'-largeArrayDims', ...
additionals{:});
After compiling the bindings, I got a dependency error when trying to use the exr functions: 'Invalid MEX-file mexfilename: The specified module could not be found.' To fix it I followed the documentation here. In my case, I needed to add to the system PATH the directories containing the .dll files from OpenEXR, IlmBase and Zlib (which I also got from Anaconda). You can also add these directories to the system path for the current Matlab session using the setenv command. For my case:
setenv('PATH', [getenv('PATH')...
';C:\Users\Sofi\Anaconda3\pkgs\openexr-2.5.5-hab3b255_0\Library\bin'...
';C:\Users\Sofi\Anaconda3\pkgs\ilmbase-2.5.5-h12d4b20_0\Library\bin'...
';C:\Users\Sofi\Anaconda3\pkgs\zlib-1.2.11-h62dcd97_4\Library\bin']);
Alternatively, you can just copy the required .dll files to the same folder the mex file is at.
  2 Comments
Walter Roberson
Walter Roberson on 23 Sep 2022
Also the original poster was having problems due to space in the directory name.

Sign in to comment.


Dinesh Iyer
Dinesh Iyer on 23 Sep 2022
If you are still looking to read EXR files in MATLAB, the Image Processing Toolbox has added EXR reading and writing capabilities in R2022b. The functions available are:
  • exrread
  • exrinfo
  • exrwrite
  • isexr
  • exrHalfAsSingle
Hope this helps.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!