You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

scikit-image的ski.transform.warp投影变换结果异常求助

投影变换异常问题求助

刚接触图像处理领域,使用Python的scikit-image库做简单投影变换时,遇到结果不符合预期的问题:变换后的图像偶尔会丢失原选中区域左上角的黑块和白色斑块,且输出图像未被裁剪,行列数和原选中区域一致。

我使用的scikit-image代码如下:

# TRANSFORM
imgGray = cv2.cvtColor(cv2.imread(imgPath), cv2.COLOR_BGR2GRAY)

dst = np.array([[1000, 100], 
                [1000, 200], 
                [800, 200], 
                [800, 100]])

src = np.array([[500, 0],
                [500, 200],
                [0, 200],
                [0, 0]])

tform3 = ski.transform.ProjectiveTransform()
tform3.estimate(src, dst)
tf_img_warp = ski.transform.warp(imgGray, tform3, output_shape=(200, 500))


## PLOT
plt.figure(num=None, figsize=(8, 6), dpi=80)
fig, ax = plt.subplots(1,2, figsize=(15, 10), dpi = 80)
ax[0].set_title(f'Original', fontsize = 15)
ax[0].imshow(imgGray)
ax[0].set_axis_off()
ax[1].set_title(f'Transformed', fontsize = 15)
ax[1].imshow(tf_img_warp)
ax[1].set_axis_off()


patch1 = Circle((dst[0][0],dst[0][1]),
                 10, facecolor = color)
patch2 = Circle((dst[1][0],dst[1][1]), 
                 10, facecolor = color)
patch3 = Circle((dst[2][0],dst[2][1]),
                 10, facecolor = color)
patch4 = Circle((dst[3][0],dst[3][1]), 
                 10, facecolor = color)
patch5 = Circle((src[0][0],src[0][1]), 10, 
                 facecolor = color)
patch6 = Circle((src[1][0],src[1][1]), 10, 
                 facecolor = color)
patch7 = Circle((src[2][0],src[2][1]), 10, 
                 facecolor = color)
patch8 = Circle((src[3][0],src[3][1]), 10, 
                 facecolor = color)

ax[0].add_patch(patch1)
ax[0].add_patch(patch2)
ax[0].add_patch(patch3)
ax[0].add_patch(patch4)
ax[1].add_patch(patch5)
ax[1].add_patch(patch6)
ax[1].add_patch(patch7)
ax[1].add_patch(patch8)

多次检查代码未发现错误,尝试改用OpenCV的透视变换也出现同样问题,代码如下:

M = cv2.getPerspectiveTransform(src, dst)
imgWarp = cv2.warpPerspective(img, M, (img.shape[1], img.shape[0]), flags=cv2.INTER_LINEAR)
imgWarp = Image.fromarray(imgWarp)

希望能得到解惑,万分感谢!

内容的提问来源于stack exchange,提问作者XeronJY

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 19:22:53