Skip to content

Commit

Permalink
importing LFToolbox at v0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Donald Dansereau committed Nov 16, 2017
0 parents commit 490994a
Show file tree
Hide file tree
Showing 70 changed files with 8,333 additions and 0 deletions.
100 changes: 100 additions & 0 deletions LFBuild2DFreqFan.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
% LFBuild2DFreqFan - construct a 2D fan passband filter in the frequency domain
%
% Usage:
%
% [H, FiltOptions] = LFBuild2DFreqFan( LFSize, Slope1, Slope2, BW, FiltOptions )
% H = LFBuild2DFreqFan( LFSize, Slope, BW )
%
% This file constructs a real-valued magnitude response in 2D, for which the passband is a fan.
%
% Once constructed the filter must be applied to a light field, e.g. using LFFilt2DFFT. The
% LFDemoBasicFilt* files demonstrate how to contruct and apply frequency-domain filters.
%
% A more technical discussion, including the use of filters for denoising and volumetric focus, and
% the inclusion of aliases components, is included in:
%
% [2] D.G. Dansereau, O. Pizarro, and S. B. Williams, "Linear Volumetric Focus for Light Field
% Cameras," to appear in ACM Transactions on Graphics (TOG), vol. 34, no. 2, 2015.
%
% Inputs:
%
% LFSize : Size of the frequency-domain filter. This should match or exceed the size of the
% light field to be filtered. If it's larger than the input light field, the input is
% zero-padded to match the filter's size by LFFilt2DFFT.
%
% Slope1, Slope2 : Slopes at the extents of the fan passband.
%
% BW : 3-db Bandwidth of the planar passband.
%
% [optional] FiltOptions : struct controlling filter construction
% SlopeMethod : only 'Skew' is supported for now
% Precision : 'single' or 'double', default 'single'
% Rolloff : 'Gaussian' or 'Butter', default 'Gaussian'
% Order : controls the order of the filter when Rolloff is 'Butter', default 3
% Aspect2D : aspect ratio of the light field, default [1 1]
% Window : Default false. By default the edges of the passband are sharp; this adds
% a smooth rolloff at the edges when used in conjunction with Extent2D or
% IncludeAliased.
% Extent2D : controls where the edge of the passband occurs, the default [1 1]
% is the edge of the Nyquist box. When less than 1, enabling windowing
% introduces a rolloff after the edge of the passband. Can be greater
% than 1 when using IncludeAliased.
% IncludeAliased : default false; allows the passband to wrap around off the edge of the
% Nyquist box; used in conjunction with Window and/or Extent2D. This can
% increase processing time dramatically, e.g. Extent2D = [2,2]
% requires a 2^2 = 4-fold increase in time to construct the filter.
% Useful when passband content is aliased, see [2].
%
% Outputs:
%
% H : real-valued frequency magnitude response
% FiltOptions : The filter options including defaults, with an added PassbandInfo field
% detailing the function and time of construction of the filter
%
% See also: LFDemoBasicFiltGantry, LFDemoBasicFiltIllum, LFDemoBasicFiltLytroF01, LFBuild2DFreqFan, LFBuild2DFreqLine,
% LFBuild4DFreqDualFan, LFBuild4DFreqHypercone, LFBuild4DFreqHyperfan, LFBuild4DFreqPlane, LFFilt2DFFT, LFFilt4DFFT,
% LFFiltShiftSum

% Part of LF Toolbox v0.4 released 12-Feb-2015
% Copyright (c) 2013-2015 Donald G. Dansereau

function [H, FiltOptions] = LFBuild2DFreqFan( LFSize, Slope1, Slope2, BW, FiltOptions )

FiltOptions = LFDefaultField('FiltOptions', 'SlopeMethod', 'Skew'); % 'Skew' only for now

DistFunc = @(P, FiltOptions) DistFunc_2DFan( P, Slope1, Slope2, FiltOptions );
[H, FiltOptions] = LFHelperBuild2DFreq( LFSize, BW, FiltOptions, DistFunc );

TimeStamp = datestr(now,'ddmmmyyyy_HHMMSS');
FiltOptions.PassbandInfo = struct('mfilename', mfilename, 'time', TimeStamp, 'VersionStr', LFToolboxVersion);

end

%-----------------------------------------------------------------------------------------------------------------------
function Dist = DistFunc_2DFan( P, Slope1, Slope2, FiltOptions )
switch( lower(FiltOptions.SlopeMethod) )
case 'skew'
if( Slope2 < Slope1 )
t = Slope1;
Slope1 = Slope2;
Slope2 = t;
end
R1 = eye(2);
R2 = R1;
R1(1,2) = Slope1;
R2(1,2) = Slope2;

otherwise
error('Unrecognized slope method');
end
P1 = R1 * P;
P2 = R2 * P;
TransitionPt = LFSign(P1(2,:));

CurDist1 = max(0, TransitionPt .* P1(1,:));
CurDist2 = max(0,-TransitionPt .* P2(1,:));

Dist = max(CurDist1, CurDist2).^2;
end


94 changes: 94 additions & 0 deletions LFBuild2DFreqLine.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
% LFBuild2DFreqLine - construct a 2D line passband filter in the frequency domain
%
% Usage:
%
% [H, FiltOptions] = LFBuild2DFreqLine( LFSize, Slope, BW, FiltOptions )
% H = LFBuild2DFreqLine( LFSize, Slope, BW )
%
% This file constructs a real-valued magnitude response in 2D, for which the passband is a line. The cascade of two line
% filters, applied in s,u and in t,v, is identical to a 4D planar filter, e.g. that constructed by LFBuild4DFreqPlane.
%
% Once constructed the filter must be applied to a light field, e.g. using LFFilt2DFFT. The
% LFDemoBasicFilt* files demonstrate how to contruct and apply frequency-domain filters.
%
% A more technical discussion, including the use of filters for denoising and volumetric focus, and
% the inclusion of aliases components, is included in:
%
% [2] D.G. Dansereau, O. Pizarro, and S. B. Williams, "Linear Volumetric Focus for Light Field
% Cameras," to appear in ACM Transactions on Graphics (TOG), vol. 34, no. 2, 2015.
%
% Inputs:
%
% LFSize : Size of the frequency-domain filter. This should match or exceed the size of the
% light field to be filtered. If it's larger than the input light field, the input is
% zero-padded to match the filter's size by LFFilt2DFFT.
%
% Slope : Slopes at the extents of the fan passband.
%
% BW : 3-db Bandwidth of the planar passband.
%
% [optional] FiltOptions : struct controlling filter construction
% SlopeMethod : only 'Skew' is supported for now
% Precision : 'single' or 'double', default 'single'
% Rolloff : 'Gaussian' or 'Butter', default 'Gaussian'
% Order : controls the order of the filter when Rolloff is 'Butter', default 3
% Aspect2D : aspect ratio of the light field, default [1 1]
% Window : Default false. By default the edges of the passband are sharp; this adds
% a smooth rolloff at the edges when used in conjunction with Extent2D or
% IncludeAliased.
% Extent2D : controls where the edge of the passband occurs, the default [1 1]
% is the edge of the Nyquist box. When less than 1, enabling windowing
% introduces a rolloff after the edge of the passband. Can be greater
% than 1 when using IncludeAliased.
% IncludeAliased : default false; allows the passband to wrap around off the edge of the
% Nyquist box; used in conjunction with Window and/or Extent2D. This can
% increase processing time dramatically, e.g. Extent2D = [2,2]
% requires a 2^2 = 4-fold increase in time to construct the filter.
% Useful when passband content is aliased, see [2].
%
% Outputs:
%
% H : real-valued frequency magnitude response
% FiltOptions : The filter options including defaults, with an added PassbandInfo field
% detailing the function and time of construction of the filter
%
% See also: LFDemoBasicFiltGantry, LFDemoBasicFiltIllum, LFDemoBasicFiltLytroF01,
% LFBuild2DFreqFan, LFBuild2DFreqLine, LFBuild4DFreqDualFan, LFBuild4DFreqHypercone,
% LFBuild4DFreqHyperfan, LFBuild4DFreqPlane, LFFilt2DFFT, LFFilt4DFFT, LFFiltShiftSum

% Part of LF Toolbox v0.4 released 12-Feb-2015
% Copyright (c) 2013-2015 Donald G. Dansereau

function [H, FiltOptions] = LFBuild2DFreqLine( LFSize, Slope, BW, FiltOptions )

FiltOptions = LFDefaultField('FiltOptions', 'SlopeMethod', 'Skew'); % 'Skew', 'Rotate'

DistFunc = @(P, FiltOptions) DistFunc_2DLine( P, Slope, FiltOptions );
[H, FiltOptions] = LFHelperBuild2DFreq( LFSize, BW, FiltOptions, DistFunc );

TimeStamp = datestr(now,'ddmmmyyyy_HHMMSS');
FiltOptions.PassbandInfo = struct('mfilename', mfilename, 'time', TimeStamp, 'VersionStr', LFToolboxVersion);

end

%-----------------------------------------------------------------------------------------------------------------------
function Dist = DistFunc_2DLine( P, Slope, FiltOptions )
switch( lower(FiltOptions.SlopeMethod) )
case 'skew'
R = eye(2);
R(1,2) = Slope;

case 'rotate'
Angle = -atan2(Slope,1);
R = LFRotz( Angle );
R = R(1:2,1:2);

otherwise
error('Unrecognized slope method');
end
P = R * P;
Dist = P(1,:).^2;
end



101 changes: 101 additions & 0 deletions LFBuild4DFreqDualFan.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
% LFBuild4DFreqDualFan - construct a 4D dual-fan passband filter in the frequency domain
%
% Usage:
%
% [H, FiltOptions] = LFBuild4DFreqDualFan( LFSize, Slope, BW, FiltOptions )
% H = LFBuild4DFreqDualFan( LFSize, Slope, BW )
%
% This file constructs a real-valued magnitude response in 4D, for which the passband is a dual-fan,
% the intersection of 2 2D fans.
%
% Once constructed the filter must be applied to a light field, e.g. using LFFilt4DFFT. The
% LFDemoBasicFilt* files demonstrate how to contruct and apply frequency-domain filters.
%
% A more technical discussion, including the use of filters for denoising and volumetric focus, and
% the inclusion of aliases components, is included in:
%
% [2] D.G. Dansereau, O. Pizarro, and S. B. Williams, "Linear Volumetric Focus for Light Field
% Cameras," to appear in ACM Transactions on Graphics (TOG), vol. 34, no. 2, 2015.
%
% Inputs:
%
% LFSize : Size of the frequency-domain filter. This should match or exceed the size of the
% light field to be filtered. If it's larger than the input light field, the input is
% zero-padded to match the filter's size by LFFilt4DFFT.
%
% Slope : The slope of the planar passband. If different slopes are desired in s,t and u,v,
% the optional aspect parameter should be used.
%
% BW : 3-db Bandwidth of the planar passband.
%
% [optional] FiltOptions : struct controlling filter construction
% SlopeMethod : 'Skew' or 'Rotate' default 'skew'
% Precision : 'single' or 'double', default 'single'
% Rolloff : 'Gaussian' or 'Butter', default 'Gaussian'
% Order : controls the order of the filter when Rolloff is 'Butter', default 3
% Aspect4D : aspect ratio of the light field, default [1 1 1 1]
% Window : Default false. By default the edges of the passband are sharp; this adds
% a smooth rolloff at the edges when used in conjunction with Extent4D or
% IncludeAliased.
% Extent4D : controls where the edge of the passband occurs, the default [1 1 1 1]
% is the edge of the Nyquist box. When less than 1, enabling windowing
% introduces a rolloff after the edge of the passband. Can be greater
% than 1 when using IncludeAliased.
% IncludeAliased : default false; allows the passband to wrap around off the edge of the
% Nyquist box; used in conjunction with Window and/or Extent4D. This can
% increase processing time dramatically, e.g. Extent4D = [2,2,2,2]
% requires a 2^4 = 16-fold increase in time to construct the filter.
% Useful when passband content is aliased, see [2].
%
% Outputs:
%
% H : real-valued frequency magnitude response
% FiltOptions : The filter options including defaults, with an added PassbandInfo field
% detailing the function and time of construction of the filter
%
% See also: LFDemoBasicFiltGantry, LFDemoBasicFiltIllum, LFDemoBasicFiltLytroF01,
% LFBuild2DFreqFan, LFBuild2DFreqLine, LFBuild4DFreqDualFan, LFBuild4DFreqHypercone,
% LFBuild4DFreqHyperfan, LFBuild4DFreqPlane, LFFilt2DFFT, LFFilt4DFFT, LFFiltShiftSum

% Part of LF Toolbox v0.4 released 12-Feb-2015
% Copyright (c) 2013-2015 Donald G. Dansereau

function [H, FiltOptions] = LFBuild4DFreqDualFan( LFSize, Slope1, Slope2, BW, FiltOptions )

FiltOptions = LFDefaultField('FiltOptions', 'Aspect4D', 1);
FiltOptions = LFDefaultField('FiltOptions', 'Extent4D', 1);

if( length(LFSize) == 1 )
LFSize = LFSize .* [1,1,1,1];
end
if( length(FiltOptions.Extent4D) == 1 )
FiltOptions.Extent4D = FiltOptions.Extent4D .* [1,1,1,1];
end
if( length(FiltOptions.Aspect4D) == 1 )
FiltOptions.Aspect4D = FiltOptions.Aspect4D .* [1,1,1,1];
end

FiltOptionsSU = FiltOptions;
FiltOptionsSU.Aspect2D = FiltOptionsSU.Aspect4D([2,4]);
FiltOptionsSU.Extent2D = FiltOptionsSU.Extent4D([2,4]);
Hsu = LFBuild2DFreqFan( LFSize([2,4]), Slope1, Slope2, BW, FiltOptionsSU );

FiltOptionsTV = FiltOptions;
FiltOptionsTV.Aspect2D = FiltOptionsSU.Aspect4D([1,3]);
FiltOptionsTV.Extent2D = FiltOptionsSU.Extent4D([1,3]);
[Htv, FiltOptionsTV] = LFBuild2DFreqFan( LFSize([1,3]), Slope1, Slope2, BW, FiltOptionsTV );

FiltOptions = FiltOptionsTV;
FiltOptions = rmfield(FiltOptions, 'Aspect2D');
FiltOptions = rmfield(FiltOptions, 'Extent2D');

Hsu = reshape(Hsu, [1, size(Hsu,1), 1, size(Hsu,2)]);
Hsu = repmat(Hsu, [LFSize(1),1,LFSize(3),1]);

Htv = reshape(Htv, [size(Htv,1), 1, size(Htv,2), 1]);
Htv = repmat(Htv, [1,LFSize(2),1,LFSize(4)]);

H = Hsu .* Htv;

TimeStamp = datestr(now,'ddmmmyyyy_HHMMSS');
FiltOptions.PassbandInfo = struct('mfilename', mfilename, 'time', TimeStamp, 'VersionStr', LFToolboxVersion);
91 changes: 91 additions & 0 deletions LFBuild4DFreqHypercone.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
% LFBuild4DFreqHypercone - construct a 4D hypercone passband filter in the frequency domain
%
% Usage:
%
% [H, FiltOptions] = LFBuild4DFreqHypercone( LFSize, Slope, BW, FiltOptions )
% H = LFBuild4DFreqHypercone( LFSize, Slope, BW )
%
% This file constructs a real-valued magnitude response in 4D, for which the passband is a hypercone.
%
% Once constructed the filter must be applied to a light field, e.g. using LFFilt4DFFT. The
% LFDemoBasicFilt* files demonstrate how to contruct and apply frequency-domain filters.
%
% A more technical discussion, including the use of filters for denoising and volumetric focus, and
% the inclusion of aliases components, is included in:
%
% [2] D.G. Dansereau, O. Pizarro, and S. B. Williams, "Linear Volumetric Focus for Light Field
% Cameras," to appear in ACM Transactions on Graphics (TOG), vol. 34, no. 2, 2015.
%
% Inputs:
%
% LFSize : Size of the frequency-domain filter. This should match or exceed the size of the
% light field to be filtered. If it's larger than the input light field, the input is
% zero-padded to match the filter's size by LFFilt4DFFT.
%
% Slope : The slope of the planar passband. If different slopes are desired in s,t and u,v,
% the optional aspect parameter should be used.
%
% BW : 3-db Bandwidth of the planar passband.
%
% [optional] FiltOptions : struct controlling filter construction
% SlopeMethod : 'Skew' or 'Rotate' default 'skew'
% Precision : 'single' or 'double', default 'single'
% Rolloff : 'Gaussian' or 'Butter', default 'Gaussian'
% Order : controls the order of the filter when Rolloff is 'Butter', default 3
% Aspect4D : aspect ratio of the light field, default [1 1 1 1]
% Window : Default false. By default the edges of the passband are sharp; this adds
% a smooth rolloff at the edges when used in conjunction with Extent4D or
% IncludeAliased.
% Extent4D : controls where the edge of the passband occurs, the default [1 1 1 1]
% is the edge of the Nyquist box. When less than 1, enabling windowing
% introduces a rolloff after the edge of the passband. Can be greater
% than 1 when using IncludeAliased.
% IncludeAliased : default false; allows the passband to wrap around off the edge of the
% Nyquist box; used in conjunction with Window and/or Extent4D. This can
% increase processing time dramatically, e.g. Extent4D = [2,2,2,2]
% requires a 2^4 = 16-fold increase in time to construct the filter.
% Useful when passband content is aliased, see [2].
%
% Outputs:
%
% H : real-valued frequency magnitude response
% FiltOptions : The filter options including defaults, with an added PassbandInfo field
% detailing the function and time of construction of the filter
%
% See also: LFDemoBasicFiltGantry, LFDemoBasicFiltIllum, LFDemoBasicFiltLytroF01,
% LFBuild2DFreqFan, LFBuild2DFreqLine, LFBuild4DFreqDualFan, LFBuild4DFreqHypercone,
% LFBuild4DFreqHyperfan, LFBuild4DFreqPlane, LFFilt2DFFT, LFFilt4DFFT, LFFiltShiftSum

% Part of LF Toolbox v0.4 released 12-Feb-2015
% Copyright (c) 2013-2015 Donald G. Dansereau

function [H, FiltOptions] = LFBuild4DFreqHypercone( LFSize, BW, FiltOptions )

FiltOptions = LFDefaultField('FiltOptions', 'HyperconeMethod', 'Rotated'); % 'Direct', 'Rotated'

DistFunc = @(P, FiltOptions) DistFunc_4DCone( P, FiltOptions );
[H, FiltOptions] = LFHelperBuild4DFreq( LFSize, BW, FiltOptions, DistFunc );

TimeStamp = datestr(now,'ddmmmyyyy_HHMMSS');
FiltOptions.PassbandInfo = struct('mfilename', mfilename, 'time', TimeStamp, 'VersionStr', LFToolboxVersion);

end

%-----------------------------------------------------------------------------------------------------------------------
function Dist = DistFunc_4DCone( P, FiltOptions )
switch( lower(FiltOptions.HyperconeMethod ))
case 'direct'
Dist = (P(1,:).*P(4,:) - P(2,:).*P(3,:)).^2 * 4;

case 'rotated'
R = 1/sqrt(2) .* [1,0,0,1; 0,1,1,0; 0,1,-1,0; 1,0,0,-1];
P=R*P;
Dist = (sqrt(P(1,:).^2 + P(3,:).^2) - sqrt(P(2,:).^2 + P(4,:).^2)).^2 /2;

otherwise
error('Unrecognized hypercone construction method');
end
end



Loading

0 comments on commit 490994a

Please sign in to comment.