gpt4 book ai didi

python - 在 Jython 中通过对角线镜像图像

转载 作者:太空宇宙 更新时间:2023-11-04 03:58:19 26 4
gpt4 key购买 nike

所以我需要镜像一个图像。图像的右上角应该翻转到左下角。我创建了一个将图像的左上角翻转到右下角的函数,但我似乎无法弄清楚如何以其他方式做到这一点。这是代码:

def mirrorPicture(picture):
height = getHeight(canvas)
width = height

# to make mirroring easier, let us make it a square with odd number
# of rows and columns
if (height % 2 == 0):
height = width = height -1 # let us make the height and width odd


maxHeight = height - 1
maxWidth = width - 1

for y in range(0, maxWidth):
for x in range(0, maxHeight - y):
sourcePixel = getPixel(canvas, x, y)
targetPixel = getPixel(canvas, maxWidth - y, maxWidth - x)
color = getColor(sourcePixel)
setColor(targetPixel, color)

return canvas

顺便说一句,我正在使用一个名为“JES”的 IDE。

最佳答案

如果“镜像”是指“对角线翻转”,这应该可行:

def mirrorPicture(picture):
height = getHeight(picture)
width = getWidth(picture)

newPicture = makeEmptyPicture(height, width)

for x in range(0, width):
for y in range(0, height):
sourcePixel = getPixel(picture, x, y)

targetPixel = getPixel(newPicture, y, x)
# ^^^^ (simply invert x and y)
color = getColor(sourcePixel)
setColor(targetPixel, color)

return newPicture

给予:


................ enter image description here ................... enter image description here .....................


对角镜像的相关回答here .

关于python - 在 Jython 中通过对角线镜像图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17099584/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com