CS计算机代考程序代写 Id1=imreadbw(‘img1.jpg’);

Id1=imreadbw(‘img1.jpg’);
Kd1 = [388.6 0 343.7;0 389.4 234.6;0 0 1];
w1 = 0.92646;
figure(1)
subplot(121)
imagesc(Id1), axis image, colormap gray
title(‘Distorted Image’);
g_ATAN_1 = @(r) (1./(w1*r) .* atan(2*tan(w1/2)*r));
K_new = [250 0 512; 0 250 384; 0 0 1];
tic
[u,v] = meshgrid(0:1023,0:767);
N_img = 1024*768;
uv_hom = [u(:) v(:) ones(N_img, 1)];

X_generic = K_new/uv_hom;
r = sqrt(X_generic(1,:).^2 + X_generic(2,:).^2);
X_d1 = [g_ATAN_1(r).*X_generic(1:2,:); ones(1,N_img)];
uv_d1_hom = Kd1 * X_d1;

[Hd1,Wd1] = size(Id1);
[grid_u_d1, grid_v_d1] = meshgrid(0:Wd1-1, 0:Hd1-1);
Inew = interp2(grid_u_d1, grid_v_d1,Id1, uv_d1_hom(1,:), uv_d1_hom(2,:), ‘linear’, 0);
Inew = reshape(Inew,size(u));

toc
subplot(122)
imagesc(Inew), axis image, colormap gray

title(‘Undistorted Image’)