python - 在 Python 中使用 for 循环垂直翻转图像

标签 python image loops for-loop flip

我尝试垂直翻转图像,但保存的图像最终是同一个图像。我认为执行 new_image.set_pixel(height-1)-r.... 会将像素发送到转置的垂直部分。你能给我一些关于我做错了什么的指导吗?

def flip_vert(filename):

img = load_image(filename)
height = img.get_height()
width = img.get_width()
new_img = Image(height, width)

for r in range(height):
    for c in range(width):
        temp = img.get_pixel(r, c)
        temp2 = new_img.get_pixel(r, c)
        new_img.set_pixel((height-1)-r,(width-1)-c,temp)

new_filename = 'flipv_test' + filename
img.save(new_filename)

最佳答案

在最后一行中,您需要:

new_img.save(new_filename)

正如现在所写,您正在保存 img,这是原始版本。

关于python - 在 Python 中使用 for 循环垂直翻转图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37825635/

相关文章:

python - 在 Python-Subprocess 中运行连续的 Shell 命令

python - requests_mock NoMockAddress 异常

xml - 每年使用 XSLT 循环打印

linux - 使用电子表格中的数据标记音频文件

css - 根据div高度调整img高度

java - 如何分解一个数字并将其数字相乘?

python - “函数”对象没有属性 'MY_SETTING'

python - 使用 Python 在所有驱动器中搜索文件

java - JLayeredPane 图像未显示

jquery - 延迟加载图片元素