光学成像系统 Part III - BRDF测试数据使用 (二)

发布时间 2023-07-05 10:42:28作者: 小淼博客

一、BRDF实验数据使用方法

1. 数据集-下载

I. 数据集格式(Anisotropic BRDF Data File Format)

解压后的数据集以 .dat 尾缀结束,文件包括了 64Bytes 的文件头,用来表示文件中数据的维度,存储格式等信息,在表头之后的便是对应的数据值,具体如下所示:

\[3 (RGB) \times dim[0] \times dim[1] \times dim[2] \times dim[3] \times (4 bytes \; per \; float). \]

图1 文件 Header 头部分解释

     对于 ParamType=1 的标准数据集,数据集的四个维度 \(dim[0..3]\) ,依次对应了入射光束 \(\theta_{in} ,\varphi_{in}\) , 出射光束 \(\theta_{out} ,\varphi_{diff}\) : \([ theta\_in, theta\_out, phi\_diff, phi\_in ]\)参考理论分析章节,而这些空间角度对应的范围为:

  • \(\theta_{in}\in [0,\pi/2]\)
  • \(\theta_{out}\in [0,\pi/2]\)
  • \(\varphi_{in}\in [0,\pi]\)
  • 如果 Half_data=1: \(\varphi_{diff}\in [0,\pi]\) 否则 \(\varphi_{diff}\in [0,2\pi]\)

? 数据集中测量不可靠的数据,在数据集中用 \(-1\) 标识。

II. 数据集Matlab读取文件

function [B,format]= read_brdf(filename, channel)
% [B, format] = read_brdf(filename, channel)
%
% Output: B - BRDF ( num_channel x dim0 x dim1 x dim2 x dim3 ) , format - struct with tabular format parameters
% Input: filename, channel ( 0 - 'red' , 1 - 'green', 2 - 'blue', -1 - 'All')
%
% Written by Addy Ngan - MIT
%
% Ver 1.01 7/20/2005
% Ver 1.0 6/19/2005

fid = fopen(filename, 'rb');
format.dims = fread(fid,4,'uint32');
% Read in dimensions of the tabulated BRDF

% Standard Parameterization: Theta_In x Theta_Out x Phi_Diff x Phi_In
% Theta_In and Theta_Out range from 0 to pi/2, Phi_Diff range from 0 to pi
% (if half_data == 0) or 2pi (if half_data == 1), Phi_In from 0 to 2pi
% for anisotropic materials.

[modes, count1] = fread(fid,10,'int32');
[expon, count2] = fread(fid,1,'double');

if (count1~=10 || count2~=1)
    error('File error');
else
    format.paramType = modes(3);  % 0 - Rusinkiewicz Parameterization, 1 - Standard Parameterization
    format.binType = modes(4); % 0 - linear binning interval, 1 - reserved
    format.half_data = modes(6)>0; % 0 - Phi_Diff range [0 2pi] , 1 - Phi_Diff range [0 pi]
    format.num_channels = modes(7); % Always 3 for our data (R,G,B)
    format.expon = expon; % reserved
end

num_channels = format.num_channels;

if channel~=-1
    fseek(fid, channel*prod(format.dims)*4, 0);
    num_channels=1;
end

B = fread(fid,num_channels*prod(format.dims),'float=>single');
fclose(fid);

if prod(size(B))<num_channels*prod(format.dims)
    B=0;
    error('Loading failed');
end

% Reshaping the data into desired dimensions
B=reshape(B,[fliplr(format.dims') num_channels]);
p = length(size(B)):-1:1;
B = permute(B,p);
if num_channels ==1
    B = reshape(B, [1 size(B)]);
end

2. 数据集-使用

二、BRDF分布函数使用方法

Reference

  1. 数据集来源:Experimental Analysis of BRDF Models