【发布时间】:2020-07-29 17:54:58
【问题描述】:
我需要将三角形图像(右上图,红色)转换到另一个位置(右上图,绿色)。在this example 之后,我正在尝试估计仿射矩阵并将其应用于转换。但结果不对(左下图)。
在下面的代码中,我试图从uv_coords_src(右上图,红色)转换为uv_coords_dst(右上图,绿色)
import numpy as np
from skimage import io
from skimage import draw
from skimage import transform
from skimage import img_as_float
from skimage import data
from matplotlib import pyplot as plt
uv_coords_src = np.array([[239,287], [101,340], [96,196]])
uv_coords_dst = np.array([[253,179], [170,70], [263,46]])
img = img_as_float(data.chelsea())
mask = draw.polygon2mask(image_shape=img.shape, polygon=uv_coords_src)
mask_out = draw.polygon2mask(image_shape=img.shape, polygon=uv_coords_dst)
masked_image = img * mask
masked_image_out = img * (mask + mask_out)
tform3 = transform.AffineTransform()
tform3.estimate(uv_coords_src, uv_coords_dst)
warped = transform.warp(masked_image, tform3, output_shape=img.shape)
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(nrows=2, ncols=2)
ax1.imshow(img, cmap='gray')
ax2.imshow(masked_image_out, cmap='gray')
ax3.imshow(warped, cmap='gray')
plt.show()
请帮我解决它。
【问题讨论】:
标签: transformation scikit-image affinetransform