【发布时间】:2013-10-21 14:52:56
【问题描述】:
我必须:
编写函数mirrorClockWise(source),以顺时针方向镜像源的每个四分之一。左上角的四分之一镜像到右上角的四分之一。右上四分之一镜像到右下四分之一。
这是我的代码,唯一的问题是右上角与应有的不同,因为它镜像的是已经镜像的左上角,而不是原始的左上角。
如果有什么我可以解决的,请告诉我...
def topLeft(source):
mirrorPoint = getWidth(source) / 2
width = getWidth(source)
for y in range(0,getHeight(source)/2):
for x in range(0,mirrorPoint):
leftPixel = getPixel(source,x,y)
rightPixel = getPixel(source,width - x - 1,y)
color = getColor(leftPixel)
setColor(rightPixel,color)
def topRight(source):
mirrorPoint = getHeight(source) / 2
height = getHeight(source)
for x in range(getWidth(source)/2,getWidth(source)):
for y in range(0,mirrorPoint):
topPixel = getPixel(source, x, y)
bottomPixel = getPixel(source, x, height - y - 1)
color = getColor(topPixel)
setColor(bottomPixel,color)
def bottomRight(source):
mirrorPoint = getWidth(source) / 2
width = getWidth(source)
for y in range(getHeight(source)/2,getHeight(source)):
for x in range(mirrorPoint,width):
leftPixel = getPixel(source,x,y)
rightPixel = getPixel(source,width - x - 1,y)
color = getColor(leftPixel)
setColor(rightPixel,color)
def bottomLeft(source):
mirrorPoint = getHeight(source) / 2
height = getHeight(source)
for x in range(0,getWidth(source)/2):
for y in range(mirrorPoint,height):
topPixel = getPixel(source, x, y)
bottomPixel = getPixel(source, x, height - y - 1)
color = getColor(topPixel)
setColor(bottomPixel,color)
def mirrorClockWise(source):
bottomLeft(source)
bottomRight(source)
topRight(source)
topLeft(source)
【问题讨论】:
-
from PIL import Image; im = Image.open('path/to/image'); im2 = im.rotate(-90) -
@ffriend,那会旋转图像,而不是执行单独的象限镜像操作,对吧?