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

[gridout,nointerpolations]=getmisscrnrs(grid,debug)
function [gridout,nointerpolations]=getmisscrnrs(grid,debug)
% GETMISSCRNRS fills in the gaps in the grid by linear interpolation.
% 
% GETMISSCRNRS successively inerpolates missing points by fitting a least
% square line of the row and column the missing point belongs to and then
% storing the point as the intersection of the two lines.
% 
% USAGE:
%     [gridout,nointerpolations]=getmisscrnrs(grid);
% 
% INPUTS:
%     grid: output of FILTERGRID
% 
% OUTPUTS:
%     gridout: grid with the missing corners interpolated
% 
%     nointerpolations: the number of interpolations is used to detect the
%     quality of the chessboard detection by FINDCORNERS

% Modified by Donald G. Dansereau 2013, bugfix for unequal number of valid x, y entries

%Function that interpolates the positions of missing corners
if ~exist('debug','var') || isempty(debug)
    debug=0;
end

% comment the line to allow debugging
debug=0;

gridout=grid;
nointerpolations=0;

for x=1:size(gridout,1)
    for y=1:size(gridout,2)
        if gridout(x,y,1)==0
            nzerrowx=gridout(x,:,1);
            nzerrowy=gridout(x,:,2);
            nzercolx=gridout(:,y,1);
            nzercoly=gridout(:,y,2);
            valid_row_entries = find(nzerrowx>0 & nzerrowy>0);
            valid_col_entries = find(nzercolx>0 & nzercoly>0);
            nzerrowx=nzerrowx(valid_row_entries);
            nzerrowy=nzerrowy(valid_row_entries);
            nzercolx=nzercolx(valid_col_entries);
            nzercoly=nzercoly(valid_col_entries);
            if length(nzerrowx)<2 || length(nzercolx)<2
                % cannot process grid
                gridout=[];
                return;
            end
            nointerpolations=nointerpolations+1;
            P1=polyfit(nzerrowy,nzerrowx,1);
            P2=polyfit(nzercolx,nzercoly,1);
            eqnsmat=[1,-P1(1);-P2(1),1];
            bmat=[P1(2);P2(2)];
            gridout(x,y,:)=eqnsmat\bmat;
            if debug
                close all;
                figure;
                hold on;
                plot(nzerrowy,polyval(P1,nzerrowy));
                plot(polyval(P2,nzercolx),nzercolx);
                plot(gridout(:,:,2),gridout(:,:,1),'+');
            end
        end
    end
end

Contact us