Implementation of image deformation, there are two distortion coefficient k1, k2, x, y for the original image pixel coordinates, x ^, ^ y for distortion after image pixels, the coordinates of r ^ 2=x ^ 2 + y ^ 2,
The code is as follows:
K=[0.000002, 0.000003] ';
Figure (2)
I=imread (' peppers. PNG ');
/h, w, c=size (I);
U0=round (w/2, h/2);
% to estimate the deformation after the canvas size
U1=floor (fd (u0, K));
It=zeros ([u1 (2) + 1, 2 * 2 * u1 (1) + 1, c), 'uint8');
% deformationFor y=1: h
For x=1: w
P=(x, y),
P=p - u0;
Pt=round (fd (p, K));
Pt=pt + u1;
It (pt (2), pt (1), :)=I (y, x, :);
End
End
Subplot (1, 2, 1)
Imshow (I), title (' deformation before ');
Subplot (1,2,2)
Imshow (It), title (' deformation after ');
Imwrite (It, 'dst_img. PNG')
The function of pt=fd (p, K)
Rq=sum (p. ^ 2);
A=[rq; rq. ^ 2);
% deformation, a. b * says the elements in the matrix a and b matrix elements in one location at a multiply 1
Pt=(p. * (1 + (A '* K)));
End
The error is:
Error using zeros
Beyond the program allows the biggest variable values,
Error test_Z (line 42)
It=zeros ([u1 (2) + 1, 2 * 2 * u1 (1) + 1, c), 'uint8');
I was a novice, matlab using python implementation also encountered a similar error, certainly bosses to help solve it
CodePudding user response:
Or change a point of view, should be how to initialize the canvas, the problem is out in the u1=floor (fd (u0, K)); This piece of