Mentions légales du service

Skip to content
Snippets Groups Projects
Commit d8c39e9f authored by DIB Elian's avatar DIB Elian
Browse files

Small fixes for llra

parent 1618a6fb
No related branches found
No related tags found
No related merge requests found
......@@ -4,11 +4,9 @@ function [dX,dY] = pinvUpdate(Value,Mask,Value_,varargin)
p = inputParser; p.KeepUnmatched = true; p.StructExpand = true;
p.addParameter('constrained', false, @islogical);
p.addParameter('relative' , true, @islogical);
p.parse(varargin{:});
constrained = p.Results.constrained;
relative = p.Results.relative;
%% Constants
projSize = size(Value);
......@@ -54,11 +52,6 @@ if constrained
dX = dXdY(1);
dY = dXdY(2);
if relative
dX = dX*u;
dY = dY*v;
end
else
%% Compute jacobian
LFxMat = LF.LFToMat(LFx);
......
function [Value,Mask,Pos,dX,dY] = warp(Value,Mask,Pos,dX,dY,varargin)
function [Value,Mask,Pos,dX,dY,initMask] = warp(Value,Mask,Pos,dX,dY,varargin)
%WARP Summary of this function goes here
% Detailed explanation goes here
......@@ -18,7 +18,7 @@ backproject = p.Results.backproject;
%% Compute reference grid
% Reference size
Size = size(Value);
End = size(Value);
% Mask bounding box
gv = subarrayIdx(Mask);
......@@ -52,8 +52,8 @@ if backproject
minSRX = floor(min(SRX(tempMask))); maxSRX = ceil(max(SRX(tempMask)));
minSRY = floor(min(SRY(tempMask))); maxSRY = ceil(max(SRY(tempMask)));
minSRX = max(minSRX,1); maxSRX = min(maxSRX,Size(3));
minSRY = max(minSRY,1); maxSRY = min(maxSRY,Size(4));
minSRX = max(minSRX,1); maxSRX = min(maxSRX,End(3));
minSRY = max(minSRY,1); maxSRY = min(maxSRY,End(4));
% Reference grid vectors
xgv = minSRX:maxSRX;
......@@ -69,6 +69,7 @@ end
%% Crop reference
Value = Value(gv{:});
Mask = Mask (gv{:});
Pos_ = cellfun(@(x) x(1),gv)-1;
End_ = cellfun(@(x) x(end),gv);
......@@ -148,8 +149,9 @@ MaskInt = griddedInterpolant(gv,Mask ,'nearest' ,'nearest');
Value = ValueInt(Uq,Vq,Xq,Yq);
Mask = MaskInt(Uq,Vq,Xq_Mask,Yq_Mask); Mask = logical(Mask);
% Mask of query coordinates inside reference boundary
refMask = Xq_Mask>Pos_(3) & Xq_Mask<End_(3)+1 & Yq_Mask>Pos_(4) & Yq_Mask<End_(4)+1;
% Mask of query coordinates inside initial and reference boundary
initMask = Xq_Mask>0 & Xq_Mask<End (3)+1 & Yq_Mask>0 & Yq_Mask<End (4)+1;
refMask = Xq_Mask>Pos_(3) & Xq_Mask<End_(3)+1 & Yq_Mask>Pos_(4) & Yq_Mask<End_(4)+1;
% New mask
Mask = Mask & refMask;
......
function [PSNRin,PSNRout,M,MMask,MPos,MDispX,MDispY,...
projM,projValue,projMask,projPos,projDispX,projDispY]...
= warpHLRA(Value,Mask,Pos,DispX,DispY,k,varargin)
%WARPHLRA Disparity Low-Rank update
= warpLRA(Value,Mask,Pos,DispX,DispY,k,varargin)
%WARPLRA Warping low rank approximation
% Compute disparity update that best matches low-rank approximation
%% Parse input
......@@ -15,12 +15,13 @@ keepCompleted = p.Results.keepCompleted;
minMethod = p.Results.minMethod;
%% Forward transform of original values
[projValue,projMask,projPos,projDispX,projDispY] = SR.warp(...
[projValue,projMask,projPos,projDispX,projDispY,initMask] = SR.warp(...
Value,Mask,Pos,DispX,DispY,varargin{:},'direction','forward');
%%
switch minMethod
case 'original'
projValue(~initMask) = nan;
case 'rank'
projValue(~projMask) = nan; %Allow rank completion of unknown pixels
end
......@@ -34,13 +35,9 @@ projSize = size(projValue);
%% Remove unknown entries
projValue(~projMask) = nan;
projDispX(~projMask) = nan;
projDispY(~projMask) = nan;
%% Complete before low-rank approximation
projValue = SR.complete(projValue,'rank');
projDispX = fill_nan(projDispX,[1,1,0,0],'both');
projDispY = fill_nan(projDispY,[1,1,0,0],'both');
%% Compute low-rank approximation
[B,C] = SR.factorize(projValue);
......@@ -52,8 +49,6 @@ projM = LF.MatToLF(MMat,projSize);
%% Remove unknown entries after low-rank approximation
projValue(~projMask) = nan;
projM(~projMask) = nan;
projDispX(~projMask) = nan;
projDispY(~projMask) = nan;
%% Compute inner PSNR
PSNRin = psnr(projM(projMask),projValue(projMask));
......@@ -102,65 +97,3 @@ end
[ValPos,MaskPos] = deal(minPos);
end
function Value = fill_nan(Value,dims,direction)
ndimsval = ndims(Value);
dimsval = 1:ndimsval;
dims = dims(dimsval);
dims = find(dims);
sz = size(Value);
GV = cell(1,ndimsval);
gv = arrayfun(@(dim) 1:dim,sz,'UniformOutput',false);
[GV{:}] = ndgrid(gv{:});
for dim = dims
curdim = dim==dimsval;
repdims = sz;
repdims(~curdim) = 1;
curGV = GV{dim};
if islogical(Value)
Mask = Value;
else
Mask = ~isnan(Value);
end
curGV(~Mask) = nan;
if any(strcmp(direction,{'pre','both'}))
GVmin = repmat(min(curGV,[],dim),repdims);
GV_ = GV;
M = GV{dim}<GVmin;
for d = dimsval
GV_{d} = GV{d}(M);
end
GV_m = GV_;
GV_m{dim} = GVmin(M);
ind = sub2ind(sz,GV_{:});
ind_m = sub2ind(sz,GV_m{:});
Value(ind) = Value(ind_m);
end
if any(strcmp(direction,{'post','both'}))
GVmax = repmat(max(curGV,[],dim),repdims);
GV_ = GV;
M = GV{dim}>GVmax;
for d = dimsval
GV_{d} = GV{d}(M);
end
GV_m = GV_;
GV_m{dim} = GVmax(M);
ind = sub2ind(sz,GV_{:});
ind_m = sub2ind(sz,GV_m{:});
Value(ind) = Value(ind_m);
end
end
end
\ No newline at end of file
function SRSet = warpHLRASet(SRSet,varargin)
%WARPHLRASET Summary of this function goes here
function SRSet = warpLRASet(SRSet,varargin)
%WARPLRASET Summary of this function goes here
% Detailed explanation goes here
[Val,Lab,Pos,DispX,DispY] = SR.SetToFields(SRSet);
......@@ -11,7 +11,7 @@ for it = 1:numel(Lab)
end
for it = 1:numel(Val)
[Val{it},Mask{it},Pos{it},DispX{it},DispY{it}] = SR.warpHLRA(...
[Val{it},Mask{it},Pos{it},DispX{it},DispY{it}] = SR.warpLRA(...
Val{it},Mask{it},Pos{it},DispX{it},DispY{it},varargin{:});
end
......
function [dX,dY,PSNRin,PSNRout,M,MMask,MPos,MDispX,MDispY,...
projM,projValue,projMask,projPos,projDispX,projDispY] = ...
warpHLRAUpdate(Value,Mask,Pos,DispX,DispY,k,varargin)
%WARPHLRAUPDATE Homography Low-Rank Approximation + update
% Compute warping that best matches low-rank approximation
warpLRAUpdate(Value,Mask,Pos,DispX,DispY,k,varargin)
%WARPLRAUPDATE warping + low rank approximation + update
% Compute update that best matches low-rank approximation
[PSNRin,PSNRout,M,MMask,MPos,MDispX,MDispY,...
projM,projValue,projMask,projPos,projDispX,projDispY]...
= SR.warpHLRA(Value,Mask,Pos,DispX,DispY,k,varargin{:});
= SR.warpLRA(Value,Mask,Pos,DispX,DispY,k,varargin{:});
[dX,dY] = SR.pinvUpdate(projValue,projMask,projM,varargin{:});
fprintf('PSNRin: %2.5f, PSNRout: %2.5f\n',PSNRin,PSNRout);
end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment