def apply_SL2C_elt_to_image(M_SL2C, src_image, out_size=None):
s_im = np.atleast_3d(src_image)
in_size = s_im.shape[:-1]
if out_size is None:
out_size = in_size
#We are going to find the location in the source image that each pixel in the output image comes from
#least squares matrix inversion (find X such that M @ X = I ==> X = inv(M) @ I = inv(M))
Minv = np.linalg.lstsq(M_SL2C, np.eye(2))[0]
#all of the x,y pairs in o_im:
pts_out = np.indices(out_size).reshape((2,-1)) #results in a 2 x (num pixels) array of indices
pts_out_a = angles_from_pixel_coords(pts_out, out_size)
pts_out_s = sphere_from_angles(pts_out_a)
pts_out_c = CP1_from_sphere(pts_out_s)
pts_in_c = np.dot(Minv, pts_out_c) # (2x2) @ (2xn) => (2xn)
pts_in_s = sphere_from_CP1(pts_in_c)
pts_in_a = angles_from_sphere(pts_in_s)
pts_in = pixel_coords_from_angles(pts_in_a, in_size)
#reshape pts into 2 x image_shape for the interpolation
o_im = get_interpolated_pixel_color(pts_in.reshape((2,)+out_size), s_im, in_size)
return o_im
sphere_transforms_numpy.py 文件源码
python
阅读 28
收藏 0
点赞 0
评论 0
评论列表
文章目录