diff --git a/README.md b/README.md index dc3d848..174ef1a 100644 --- a/README.md +++ b/README.md @@ -20,3 +20,11 @@ To see some examples, have a look at the tutorial directory. If you want to read Note: This repository was formerly ISET3d-v4, pbrt2iset, and before that we relied on RenderToolbox4. ISET3d was originally developed in Brian Wandell's [Vistalab group](https://vistalab.stanford.edu/) at [Stanford University](stanford.edu), along with co-contributors from other research institutions and industry. + +## Octave Support +- July 14, 2025: Ayush Jamdar. +- New: A function `isOctave` tests if code is being run in Octave and uses modified code accordingly. +- The EXR readers come from OpenEXR and accept only the filename as input. +- We still rely on `.mex` exr io functions but those are built using `mkoctfile`. See `isetcam/imgproc/openexr` +- We have tested `isethdrsensor/scripts/fullSimulation.m` on examples from the ISET HDR dataset using Octave 6.4.0. +- Refer to `isetcam/README.md` for Octave and Conda environment packages. diff --git a/utilities/isOctave.m b/utilities/isOctave.m new file mode 100644 index 0000000..f7f1b70 --- /dev/null +++ b/utilities/isOctave.m @@ -0,0 +1,14 @@ +% Test if running in Octave + +% This function will be called whenever code differs between +% Matlab and Octave, with the goal to extend ISET support + +function retval = isOctave + persistent cacheval; + if isempty (cacheval) + cacheval = (exist ("OCTAVE_VERSION", "builtin") > 0); + end + retval = cacheval; +end + + diff --git a/utilities/pbrt/pbrt-v4/piEXR2ISET.m b/utilities/pbrt/pbrt-v4/piEXR2ISET.m index 63b2e12..f113c04 100644 --- a/utilities/pbrt/pbrt-v4/piEXR2ISET.m +++ b/utilities/pbrt/pbrt-v4/piEXR2ISET.m @@ -94,7 +94,7 @@ nn = nn+1; end try - % New format + % New format: exrread() either from Matlab or Openexr energy = exrread(inputFile,Channels = radianceChannels); catch % keep the old format @@ -109,16 +109,31 @@ case {'depth', 'zdepth'} info = exrinfo(inputFile); - channelNames = info.ChannelInfo.Properties.RowNames; - if contains('P.X',channelNames) - % Modern naming for X,Y,Z coordinates - coordinates = exrread(inputFile,Channels=["P.X","P.Y","P.Z"]); - elseif contains('Px',channelNames) - % Historical naming - coordinates = exrread(inputFile,Channels=["Px","Py","Pz"]); - else - warning('No X,Y,Z channels found. Returning.'); - return; + + if isOctave() + channelNames = info.channels; + if any(strcmp('P.X', channelNames)) + % Modern naming for X,Y,Z coordinates + coordinates = exrread(inputFile); + elseif any(strcmp('Px', channelNames)) + % Historical naming + coordinates = exrread(inputFile); + else + warning('No X,Y,Z channels found. Returning.'); + return; + end + else % Matlab + channelNames = info.ChannelInfo.Properties.RowNames; + if contains('P.X',channelNames) + % Modern naming for X,Y,Z coordinates + coordinates = exrread(inputFile,Channels=["P.X","P.Y","P.Z"]); + elseif contains('Px',channelNames) + % Historical naming + coordinates = exrread(inputFile,Channels=["Px","Py","Pz"]); + else + warning('No X,Y,Z channels found. Returning.'); + return; + end end if isequal(label{ii},'depth') diff --git a/utilities/pbrt/pbrt-v4/piEXR2Mat.m b/utilities/pbrt/pbrt-v4/piEXR2Mat.m index 32d8abd..fbcc795 100644 --- a/utilities/pbrt/pbrt-v4/piEXR2Mat.m +++ b/utilities/pbrt/pbrt-v4/piEXR2Mat.m @@ -18,8 +18,15 @@ % dockerWrapper Support, D. Cardinal, 2022 % +% Check if MATLAB exrread() is available +% This function is available only in Matlab >= R2022b +hasBuiltinExrread = false; +if ~isOctave() && exist('isMATLABReleaseOlderThan', 'file') > 0 + hasBuiltinExrread = ~isMATLABReleaseOlderThan('R2022b'); +end + % tic -if exist('isMATLABReleaseOlderThan','file') > 0 && ~isMATLABReleaseOlderThan('R2022b') +if hasBuiltinExrread % Use Matlab builtin exrread from the image toolbox % Matlab included exrread() in 2022b. We included exread() in @@ -48,9 +55,11 @@ data = exrread(inputFile, Channels = channels); return; -elseif isfile(fullfile(isetRootPath,'imgproc','openexr','exrread.m')) - - % Use the exrread() from ISETCam. +elseif isfile(fullfile(isetRootPath,'imgproc','openexr','exrreadchannels.mex')) + % If Matlab's exrread() isn't available, the user must be using + % openexr's exrread() (either from older Matlab or Octave) + % In this case, the mex file should exist + % Note that this file reader uses arguments different from Matlab's if strcmpi(channelname,'radiance') channels = cell(1,31); @@ -95,7 +104,7 @@ if status disp(result); - error('EXR to Binary conversion failed.') + error('EXR to Binary conversion failed.'); end allFiles = dir([indir,sprintf('/%s_*',fname)]); fileList = [];