Python Can';I don’我不知道如何编译所有内容并返回我的图像
不知道如何编译所有内容并返回我的图像Python Can';I don’我不知道如何编译所有内容并返回我的图像,python,python-3.x,python-imaging-library,Python,Python 3.x,Python Imaging Library,不知道如何编译所有内容并返回我的图像 from PIL import Image def open_bird(): filename = 'bird_scrambled.png' #Call File picture = Image.open(filename) #Opens file for use return(picture) def unscramble_left(picture): widt
from PIL import Image
def open_bird():
filename = 'bird_scrambled.png' #Call File
picture = Image.open(filename) #Opens file for use
return(picture)
def unscramble_left(picture):
width, height = picture.size #Call image size, log
for x in range (0, (width/2)): # width is /2
for y in range (0, height): # height remains same
red, green, blue = picture.getpixel((x,y)) # call pixels in x,y grid
picture.putpixel((x,y), (blue,green,red)) # replace pixels rgb -> bgr
return(picture)
def unscramble_top(picture):
width, height = picture.size
for x in range (0, (width/2)):
for y in range (0, (height/2)):
red, green, blue = picture.getpixel((x,y))
for red in picture:
if red >= 127:
red = red - 127
else:
red = red + 127
picture.show()
def put_together():
open_bird()
unscramble_left(picture)
unscramble_top(picture)
基本上,我想在初始函数中设置图片后,从每个函数返回图片。通过解译_left()传递照片,以解译_top;最后让它在最后一个函数put_together()中编译。但是,每次我尝试运行这个函数时,最终都会出现返回值图片在最终的拼凑函数中无法显示的问题。我正在做最后一个函数,因为它需要从一个函数调用。这就是我的问题。它就是不回来了 我不完全确定您想要完成什么,但代码至少现在已经编译好了。我最后编辑了一些东西:
- 看起来你的拼合函数是试图成为程序启动时运行的函数。所以它把它变成了主要的
- 我觉得你好像想把照片传给别人,所以我把它改成了真的
- 此外,我还编辑了几个for循环的范围。考虑到范围必须是从一个整数到另一个整数,我添加了舍入。目前它使用
对值进行四舍五入,但您可能希望使用ceil()
对值进行四舍五入floor()
- 似乎您正在尝试编辑
中的每个像素。所以我编辑了它。最初,您使用它是为了尝试迭代像素,这将不起作用,因为每个pizel只有一个r值、一个g值和一个b值解读\u top
from PIL import Image
from math import ceil
def open_bird():
filename = 'Image.jpeg' # Call File
picture = Image.open(filename) # Opens file for use
return picture
def unscramble_left(picture):
width, height = picture.size # Call image size, log
for x in range(0, ceil(width / 2)): # width is /2
for y in range(0, height): # height remains same
red, green, blue = picture.getpixel((x, y)) # call pixels in x,y grid
picture.putpixel((x, y), (blue, green, red)) # replace pixels rgb -> bgr
return picture
def unscramble_top(picture):
width, height = picture.size
for x in range(0, ceil(width / 2)):
for y in range(0, ceil(height / 2)):
red, green, blue = picture.getpixel((x, y))
if red >= 127:
red = red - 127
else:
red = red + 127
return picture
def main():
picture = open_bird()
picture = unscramble_left(picture)
picture = unscramble_top(picture)
picture.show()
if __name__ == '__main__':
main()
嗨,乔尔,你能描述一下你的问题吗?你能解释一下这个问题吗?你在努力解决什么问题?一般来说,你能说得更具体一点,以便我们能提供帮助吗?你可以编辑并改进你的问题。别忘了实际存储你返回的值,这样你就可以使用它们了。在put_together中,您不存储open_bird的返回值,然后将一个新实例化的picture变量传递给后面的两个函数,该变量将为None。所以picture=open_bird()乔,你能更好地解释一下你的问题吗其他细节可能有助于读者理解问题的目的。快乐编码!