在这种情况下如何使用interp2 ?

时间:2022-11-28 18:54:19

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

我正在研究图像扭曲。我有矩阵D和I,我想通过函数interp2得到J J的定义是

在这种情况下如何使用interp2 ?,

,

where D and I have the same size.

D和I的大小相同。

Obviously, some values in matrix J is not assigned, I want to assign them with values by using interp2.

显然,矩阵J中的一些值没有赋值,我想用interp2来赋值。

This is what I've tested for transform without using interp2

这就是我在不使用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.

J有很多未赋值的值。Interp2提供了一些插值算法,但我不知道如何使用。

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:

和matlab报告错误:

Error using griddedInterpolant Sample values must be a single or double array.

使用griddedintrdedsample值的错误必须是单数组或双数组。

Error in interp2>makegriddedinterp (line 228) F = griddedInterpolant(varargin{:});

interp2>makegriddedinterp(第228行)F = griddedintroant (varargin{:});

Error in interp2 (line 112) F = makegriddedinterp({X,Y},V,method,extrap);

interp2中的误差(第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?

错误在于J的维数和网格的维数不一样,如何修正?

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.....

太慢.....

1 个解决方案

#1


0  

The answer is simple, just reverse the matrix, interp2 is used for imresize

答案很简单,只需反转矩阵,interp2用于调整大小

#1


0  

The answer is simple, just reverse the matrix, interp2 is used for imresize

答案很简单,只需反转矩阵,interp2用于调整大小