Exemplo n.º 1
0
def rotf(t):
    return np.array([[np.cos(t), np.sin(t), 0], [-np.sin(t),
                                                 np.cos(t), 0], [0, 0, 1]])


output_shape = im_gray.shape

print(output_shape)
print(type(output_shape))
output_shape2 = (output_shape[0] * 2, output_shape[1] * 2)

cx = im_gray.shape[1] // 2  #为了取rotation center
cy = im_gray.shape[0] // 2  #为了取rotation center

A = (transf(
    output_shape[1] // 2,
    output_shape[0] // 2,
).dot(scalef(0.8)).dot(rotf(-30 * np.pi / 180)).dot(transf(-cx, -cy)))

# plot a dot at the rotation center
axes[0, 1].plot(cx, cy, 'r+')
#warped_im = warpA_check.warp(im_gray, A, output_shape)
warped_im = warpA.warp(im_gray, A, output_shape)

axes[1, 0].imshow(warped_im, cmap=plt.get_cmap('gray'))
axes[1, 0].set_title('warped')

# write the plot to an image
plt.savefig('./transformed_soln.jpg')
plt.show()
Exemplo n.º 2
0

output_shape = im_gray.shape
cx = im_gray.shape[1] // 2
cy = im_gray.shape[0] // 2

A = (transf(
    output_shape[1] // 2,
    output_shape[0] // 2,
).dot(scalef(0.8)).dot(rotf(-30 * np.pi / 180)).dot(transf(-cx, -cy)))

# plot a dot at the rotation center
axes[0, 1].plot(cx, cy, 'r+')
warped_im = warpA_check.warp(im_gray, A, output_shape)

warped_mine = warpA.warp(im_gray, A, output_shape)

diff = warped_im - warped_mine
print(np.sum(diff))

axes[1, 0].imshow(warped_im, cmap=plt.get_cmap('gray'))
axes[1, 0].set_title('warped')

# write the plot to an image
plt.savefig('../results/transformed_soln.jpg')
plt.show()

plt.imshow(warped_mine, cmap=plt.get_cmap('gray'))
plt.savefig('../results/transformed.jpg')

plt.show()