function images = loadLightField(dirname)
%loads in light field images from the directory dirname
%using the script LFscript in the directory


try
files = dir(fullfile(dirname));

catch err
    disp('Failed to find directory');
    return;
end

fid = fopen([dirname '/LFscript.txt']);
%get height and width
tline = fgetl(fid);
width = str2num(regexprep(tline, 'width ', ''));
tline = fgetl(fid);
height = str2num(regexprep(tline, 'height ', ''));
images = cell(height, width); 

%parse text to load in images
tline = fgetl(fid);
while ischar(tline)
    [isfile remain] = strtok(tline);
    [col remain] = strtok(remain);
    [row remain] = strtok(remain);
    [filename remain] = strtok(remain);
    filename = [dirname '/' filename];
    if(strcmp(isfile, 'file') == 0)
       continue; 
    end
    
    col = str2num(col);
    row = str2num(row);
    if(col+1 <= width && row+1 <= height)
        images{row+1, col+1} = imread(filename);
    else
        disp('OUT OF BOUNDS FROM DECLARED WIDTH/HEIGHT!');
    end
    tline = fgetl(fid);
end

fclose(fid);


end

