【问题标题】:How to perform image transformation operation(rotate, scale, translate) in python by transformation matrix如何通过变换矩阵在python中执行图像变换操作(旋转、缩放、平移)
【发布时间】:2020-01-22 12:53:20
【问题描述】:

我想在不调用任何其他外部库(PIL、CV2)函数的情况下对图像执行矩阵变换操作,例如旋转、缩放、平移。

我正在尝试使用基本的矩阵变换方法。但是我遇到了一些问题,比如旋转时有孔,图像被裁剪。

我想沿着中心执行上述所有操作。这里需要一些指导。

旋转逻辑:

newImage = np.zeros((2*row, 2*column, 3), dtype=np.uint8)
radAngle = math.radians(int(input("angle: ")))
c, s = math.cos(radAngle), math.sin(radAngle)
mid_coords = np.floor(0.5*np.array(image.shape))
for i in range(0, row-1):
    for j in range(0, column-1):
        x2 = mid_coords[0] + (i-mid_coords[0])*c - (j-mid_coords[1])*s
        y2 = mid_coords[1] + (i-mid_coords[0])*s + (j-mid_coords[1])*c 
        newImage[int(math.ceil(x2)), int(math.ceil(y2))] = image[i, j]

【问题讨论】:

标签: opencv image-processing matrix computer-vision python-imaging-library


【解决方案1】:

旋转图像中出现孔的原因是您将原始图像的每个像素分配给旋转图像中计算的像素位置。因此,旋转图像中的一些像素被遗漏了。 你应该反过来做。 对于旋转图像中的每个像素,从原始图像中找到它的值。 请参考this答案。

【讨论】:

    猜你喜欢
    • 2013-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多