Convert matlab code to c++:
function rec = interpolate(s,shifts,factor)
n=length(s);
ss = size(s{1});
if (length(ss)==2) ss=[ss 1]; end
% compute the coordinates of the pixels from the N images.
for k=1:ss(3) % for each color channel
for i=1:n % for each image
s_c{i}=s{i}(:,:,k);
s_c{i} = s_c{i}(:);
r{i} = [1:factor:factor*ss(1)]'*ones(1,ss(2)); % create matrix with row indices
c{i} = ones(ss(1),1)*[1:factor:factor*ss(2)]; % create matrix with column indices
r{i} = r{i}+factor*shifts(i,2); %% the problem is here.
c{i} = c{i}+factor*shifts(i,1); %% the problem is here.
rn{i} = r{i}((r{i}>0)&(r{i}<=factor*ss(1))&(c{i}>0)&(c{i}<=factor*ss(2)));
cn{i} = c{i}((r{i}>0)&(r{i}<=factor*ss(1))&(c{i}>0)&(c{i}<=factor*ss(2)));
sn{i} = s_c{i}((r{i}>0)&(r{i}<=factor*ss(1))&(c{i}>0)&(c{i}<=factor*ss(2)));
end
s_ = []; r_ = []; c_ = []; sr_ = []; rr_ = []; cr_ = [];
for i=1:n % for each image
s_ = [s_; sn{i}];
r_ = [r_; rn{i}];
c_ = [c_; cn{i}];
end
clear s_c r c coord rn cn sn
% interpolate the high resolution pixels using cubic interpolation
rec_col = griddata(c_,r_,s_,[1:ss(2)*factor],[1:ss(1)*factor]','cubic');
rec(:,:,k) = reshape(rec_col,ss(1)*factor,ss(2)*factor);
end
rec(isnan(rec))=0;