Code covered by the BSD License  

Highlights from
Light Field Toolbox v0.2

image thumbnail

Light Field Toolbox v0.2

by

 

26 Apr 2013 (Updated )

A set of tools for working with light field (aka plenoptic) imagery in Matlab

LFFindFilesRecursive( InputPath, FilePattern )
% LFFindFilesRecursive - Recursively searches a folder for files matching a pattern
% 
% Usage: 
% 
%   [AllFiles, FolderList, PerFolderFiles] = LFFindFilesRecursive( InputPath, FilePattern )
% 
% 
% Inputs:
% 
%   InputPath: the folder to recursively search
%   FilePattern: pattern describing the filenames to match
%
% 
% Outputs:
% 
%   Allfiles: a single list of all files found
%   FolderList: a list of all the folders explored
%   PerFolderFiles: a list of files organied by folder -- e.g. PerFolderFiles{1} are all the files
%                   found in FolderList{1}
% 
% Example:
% 
%   AllFiles = LFFindFilesRecursive( '.', '*__Decoded.mat' )
%   will find all the decoded light fields in the current folder and its subfolders
% 

% Part of LF Toolbox v0.2 released 27-May-2013
% Copyright (c) 2013, Donald G. Dansereau

function [AllFiles, FolderList, PerFolderFiles] = LFFindFilesRecursive( InputPath, FilePattern )

PerFolderFiles = [];
AllFiles = [];

% Clean up the inputpath to omit trailing slashes
if( isempty(InputPath) )
    InputPath = '.';
end
while( InputPath(end) == filesep )
    InputPath = InputPath(1:end-1);
end

%---
FolderList = genpath(InputPath);
if( isempty(FolderList) )
    error(['Input path not found... are you running from the correct folder? ' ...
        'Current folder: %s'], pwd);
end
FolderList = textscan(FolderList, '%s', 'Delimiter', pathsep);
FolderList = FolderList{1};

%---Compile a list of all files---
for( iFolder = 1:length(FolderList) )
    
    %---Search each subfolder for raw lenselet files---
    CurFolder = FolderList{iFolder};
    CurDirList = dir(fullfile(CurFolder, FilePattern));
    
    CurDirList = CurDirList(~[CurDirList.isdir]);
    CurDirList = {CurDirList.name};
    PerFolderFiles{iFolder} = CurDirList;
    
    % Prepend the current folder name for a complete path to each file
    % but fist strip off the leading InputPath so that all files are expressed relative to InputPath
    CurFolder = CurFolder(length(InputPath)+1:end);
    while( ~isempty(CurFolder) && CurFolder(1) == filesep )
        CurFolder = CurFolder(2:end);
    end
    
    CurDirList = cellfun(@(Fname) fullfile(CurFolder, Fname), CurDirList, 'UniformOutput',false);
    
    AllFiles = [AllFiles, CurDirList];
    
end

end

Contact us