I am working on image warping. I have matrix D and I, I want to get J by using function interp2 The definition of J is
,
where D and I have the same size.
Obviously, some values in matrix J is not assigned, I want to assign them with values by using interp2.
This is what I've tested for transform without using interp2
for i=1:1:h
for j = 1:1:w
J(i,j+img_d(i,j)) = img_c(i,j);
end
end
J has a lot of value un-assigned. Interp2 provides some interpolation algorithms, but I don't know how to use.
Then I tried the following:
img_d = imread('1_d.png');
img_c = imread('1_c.png');
[h,w] = size(img_d);
for i = 1:1:h
for j = 1:1:w
J(i,j+img_d(i,j)) = img_c(i,j,1);
end
end
[Xq,Yq] = meshgrid((1:1:w),(1:1:h));
V = interp2(J,Xq,Yq,'spline');
And matlab reports errors:
Error using griddedInterpolant Sample values must be a single or double array.
Error in interp2>makegriddedinterp (line 228) F = griddedInterpolant(varargin{:});
Error in interp2 (line 112) F = makegriddedinterp({X,Y},V,method,extrap);
The error is because that the dimension of J is not the same as the meshgrid, how to fix this?
This is what I implemented for backward warping
img_d = imread('1_d.png');img_c = imread('1_c.png');
[h,w] = size(img_d);
J_1 = zeros(h,w);
J_2 = zeros(h,w);
J_3 = zeros(h,w);
for i = 1:1:h
for j = 1:1:w
min_value = j;
col = 1;
for k = 1:1:w
temp = j-(k + img_d(i,k));
if temp < min_value
min_value = temp;
col = k;
end
end
J_1(i,j) = img_c(i,col,1);
J_2(i,j) = img_c(i,col,2);
J_3(i,j) = img_c(i,col,3);
end
end
J = cat(3,J_1,J_2,J_3);
Too slow.....
matlab
's help? – lrnzcigD
? Integers, floats? – DanD
is all integers then it's basically just jumbling up the elements. I suggest you make a 3-by-3 toy example with all inputs and outputs to make your question clearer – Dan