% LFSelectWhiteImage - selects a white image from a Lytro calibration folder based on zoom, focus
%
% Usage:
% [WhiteImageProcessedFname, WhiteImageFName, WhiteTextFname, ActualZoomStep, ActualFocusStep] = ...
% LFSelectWhiteImage( DesiredZoomStep, DesiredFocusStep, CalibFilesPath, WhiteFileDatabaseFname )
%
%
% Lytro cameras come loaded with a database of white images. These are taken through a diffuser,
% and at different zoom and focus settings. They are useful for removing vignetting (darkening near
% edges of images) and for locating lenselets in light field images.
%
% To decode a light field image, it is important that the appropriate white image be selected. The
% role of this function is to select the white image that most closely matches the zoom and focus
% settings associated with a light field picture. It prioritizes zoom over focus at the moment,
% though it is unclear whether this is optimal.
%
% This function assumes you have extracted the white images into a folder and run
% LFUtilProcessLytroCalData to build a database of available white images.
%
% Input DesiredZoomStep and DesiredFocusStep are the zoom and focus settings for which you wish to
% locate the appropriate white image.
%
% Input CalibFilesPath is the path to the white images, which must include a white image database
% file.
%
% Optional Input WhiteFileDatabaseFname is the filename of the white image database. The default
% value is `WhiteFileDatabase.mat', to match the output of LFUtilProcessLytroCalData.
%
% Output WhiteImageProcessedFname is the names of the grid model file associated with the white
% image, as generated LFUtilProcessLytroCalData.
%
% Output WhiteImageFName is the filename of the white image.
%
% Output WhiteTextFname is the filename of the metadata file associated with the white image.
%
% Outputs ActualZoomStep and ActualFocusStep are the zoom and focus settings associated with the
% white image.
%
% Refer the documentation accompanying this toolbox for more information.
%
% See also: LFUtilProcessLytroCalData, LFExampleDecodeLenseletImage
% Part of LF Toolbox v0.1, released 26-Apr-2013
% Copyright (c) 2013, Donald G. Dansereau
function [WhiteImageProcessedFname, WhiteImageFName, WhiteTextFname, ActualZoomStep, ActualFocusStep] = ...
LFSelectWhiteImage( DesiredZoomStep, DesiredFocusStep, CalibFilesPath, WhiteFileDatabaseFname )
if( ~exist('WhiteFileDatabaseFname', 'var') )
WhiteFileDatabaseFname = 'WhiteFileDatabase.mat';
end
load(fullfile(CalibFilesPath, WhiteFileDatabaseFname), 'WhiteFileInfo', 'WhiteImageFileNames', 'WhiteTextFileNames', 'WhiteImageProcessedFnames');
% Find the closest to our desired settings, prioritizing zoom
ZoomDiff = abs([WhiteFileInfo.ZoomStep] - DesiredZoomStep);
BestZoomDiff = min(ZoomDiff);
BestZoomIdx = find( ZoomDiff == BestZoomDiff );
% Of those that are closest in zoom, find the one that's closest in focus
FocusDiff = abs([WhiteFileInfo(BestZoomIdx).FocusStep] - DesiredFocusStep);
[~,BestFocusIdx] = min(FocusDiff);
BestOverallIdx = BestZoomIdx(BestFocusIdx);
WhiteImageFName = WhiteImageFileNames(BestOverallIdx).name;
WhiteTextFname = WhiteTextFileNames(BestOverallIdx).name;
WhiteImageProcessedFname = WhiteImageProcessedFnames{BestOverallIdx};
ActualFocusStep = WhiteFileInfo(BestOverallIdx).FocusStep;
ActualZoomStep = WhiteFileInfo(BestOverallIdx).ZoomStep;
% Uncomment this section to see a plot of available and selected zoom/focus settings
% figure(1);
% clf
% plot([WhiteFileInfo.ZoomStep], [WhiteFileInfo.FocusStep],'.');
% hold on
% plot(ActualZoomStep, ActualFocusStep,'ro');