필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Wy error..? Need correction...

조회 수: 1 (최근 30일)
Lalit Patil
Lalit Patil 2013년 1월 24일
마감: MATLAB Answer Bot 2021년 8월 20일
Idistorted = imread('1.bmp');
a = 0.1; b = 0.1; c = 0.01; d = 0.001;
fx = 1800;
fy = 1800;
cx = 360;
cy = 240;
K = [fx 0 cx; 0 fy cy; 0 0 1];
I = zeros(size(Idistorted));
[i j] = find(~isnan(I));
Xp = inv(K)*[j i ones(length(i),1)]';
r2 = Xp(1,:).^2+Xp(2,:).^2;
x = Xp(1,:);
y = Xp(2,:);
x = x.*(1+a*r2 + b*r2.^2) + 2*c.*x.*y + d*(r2 + 2*x.^2);
y = y.*(1+a*r2 + b*r2.^2) + 2*d.*x.*y + c*(r2 + 2*y.^2);
u = reshape(fx*x + cx,size(I));
v = reshape(fy*y + cy,size(I));
I = interp1(Idistorted, u, v);
  댓글 수: 2
Walter Roberson
Walter Roberson 2013년 1월 24일
What error are you seeing? What is the error message? On which line?
Lalit Patil
Lalit Patil 2013년 1월 24일
Last line of code shows error.
??? Error using ==> interp1 at 121
X must be a vector.

답변 (2개)

Wayne King
Wayne King 2013년 1월 24일
interp1 is 1-D interpolation. If you want to perform interpolation on 2-D data, see the help for interp2

Walter Roberson
Walter Roberson 2013년 1월 24일
What are you expecting when you attempt to use a 1 dimensional interpolation on data that is at least 2 dimensional (if it is grayscale) and possibly 3 dimensional (if it is RGB) ?
yi = interp1(x,Y,xi) interpolates to find yi, the values of the underlying function Y at the points in the vector or array xi. x must be a vector.
Notice that second sentence.
Also a question: your code has
x = x.*(1+a*r2 + b*r2.^2) + 2*c.*x.*y + d*(r2 + 2*x.^2);
y = y.*(1+a*r2 + b*r2.^2) + 2*d.*x.*y + c*(r2 + 2*y.^2);
In that code, you use the current values of x and y in the first line, and you write the result over-top of x. And then in the second line, you use the now-changed value of x, along with the unchanged value of y, to compute a new y that you then use to overwrite y. Is that your desired sequence? Because it is not clear from the structure of the code that you want the two lines to have results that depend on the order you execute the two, but with you overwriting the variables that way, you would get different results if you switched the two lines around. With the code appearing to be symmetric, it appears to me that you want the "x" on the right hand side of the first line to refer to the same values as the "x" on the right hand side of the second line.
Another question: you have
I = zeros(size(Idistorted));
[i j] = find(~isnan(I));
you just initialized I to all 0, so isnan(I) is going to be false for all of I, so ~isnan(I) is going to be true for all of I, so the result of the find() will be the coordinates of everything in I. If that is what you want, then why confuse things with the isnan() and why not just do
[i j] = find(true(size(I));
or why not build the coordinate list with ndgrid() ?

이 질문은 마감되었습니다.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by