Python图像反转
我试图将图像翻转到完全相反的方向(从左到右),但似乎无法理解代码。我知道如何将它们对半镜像,然而,我似乎无法实现完全的翻转。到目前为止,我有:Python图像反转,python,Python,我试图将图像翻转到完全相反的方向(从左到右),但似乎无法理解代码。我知道如何将它们对半镜像,然而,我似乎无法实现完全的翻转。到目前为止,我有: def flip(source): width=getWidth(source)/2 height=getHeight(source) for y in range(0,height): for x in range(0,width): leftPixel=getPixel(source,x,y) rightP
def flip(source):
width=getWidth(source)/2
height=getHeight(source)
for y in range(0,height):
for x in range(0,width):
leftPixel=getPixel(source,x,y)
rightPixel=getPixel(source,width-x-1,y)
color1=getColor(leftPixel)
color2=getColor(rightPixel)
setColor(rightPixel,color1)
setColor(leftPixel,color2)
在这一行中,width
应该是图像的全宽,而不是宽度的一半。我建议将/2
移动到内部循环范围
width = getWidth (source)
height = getHeight(source)
for y in range(height):
for x in range(width / 2):
相对于的函数,您的代码将需要很长时间才能运行。使用已经实现的函数是一种很好的风格:
width = getWidth (source)
height = getHeight(source)
for y in range(height):
for x in range(width / 2):