I'm trying to convert some Matlab code to Python but I'm running into a problem. When I…
- User
I'm trying to convert some Matlab code to Python but I'm running into a problem. When I run the code in Matlab I get a a Matrix with size (1,49) but in Python I get a Matrix of size (49,49).
Here is the Matlab code: [x,y]=meshgrid(1:size(im,2),1:size(im,1)); coords=[x(:)'; y(:)']; homogeneousCoords=[coords; ones(1,prod(size(im)))]; warpedCoords=A*homogeneousCoords; xprime=warpedCoords(1,:);%./warpedCoords(3,:); yprime=warpedCoords(2,:);%./warpedCoords(3,:);
result = interp2(x,y,im,xprime,yprime, 'linear'); Here is the Python code: x, y = np.meshgrid(np.arange(im.shape[1]), np.arange(im.shape[0])) # Verified coords = np.vstack((x.T.ravel(), y.T.ravel())) # Verified homogeneousCoords = np.vstack((coords, np.ones((1, im.size)))) # Likely verified warpedCoords = A @ homogeneousCoords xprime = warpedCoords[0, :] # Verified yprime = warpedCoords[1, :] # Verified
codef_real = interp2d(x, y, im.real, kind='linear') f_imag = interp2d(x, y, im.imag, kind='linear') result_real = f_real(xprime, yprime) result_imag = f_imag(xprime, yprime) result = result_real = (1j * result_imag)What is the problem? How can get the same behavior as Matlab?
- Assistant