Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Opencv 如何通过变换矩阵在python中执行图像变换操作(旋转、缩放、平移)_Opencv_Image Processing_Matrix_Computer Vision_Python Imaging Library - Fatal编程技术网

Opencv 如何通过变换矩阵在python中执行图像变换操作(旋转、缩放、平移)

Opencv 如何通过变换矩阵在python中执行图像变换操作(旋转、缩放、平移),opencv,image-processing,matrix,computer-vision,python-imaging-library,Opencv,Image Processing,Matrix,Computer Vision,Python Imaging Library,我想在没有任何其他外部库(PIL,CV2)函数调用的情况下对图像执行矩阵变换操作,如旋转、缩放和平移 我正在尝试基本的矩阵变换方法。但我面临一些问题,比如旋转时有洞,图像被裁剪 我想沿着中心执行以上所有操作。这里需要一些指导 旋转逻辑: newImage = np.zeros((2*row, 2*column, 3), dtype=np.uint8) radAngle = math.radians(int(input("angle: "))) c, s = math.cos(radAngle),

我想在没有任何其他外部库(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]

旋转图像中出现孔洞的原因是将原始图像的每个像素指定给旋转图像中计算出的像素位置。因此,旋转图像中的一些像素被忽略。 你应该反过来做。 对于旋转图像中的每个像素,从原始图像中查找其值。
请参阅答案。

在旋转图像中出现孔的原因是您将原始图像的每个像素指定给旋转图像中计算的像素位置。因此,旋转图像中的一些像素被忽略。 你应该反过来做。 对于旋转图像中的每个像素,从原始图像中查找其值。 请参阅答案。

可能的副本