【问题标题】:Trying to put 2 images to over lap one another试图将 2 张图像相互重叠
【发布时间】:2021-02-27 20:28:02
【问题描述】:

我有两张照片需要拼成一张。第一个是关于一个有大海的海滩。第二张图片是一个仙人掌,后面有一个非常明亮的绿色屏幕。我需要找到一种方法来调低仙人掌图片中的绿屏,这样我就可以将它放在海滩图片上,让它看起来就像海滩上有仙人掌。我可以更改像素颜色,但似乎无法取出仙人掌图片的亮绿色屏幕颜色。我也可以把两张图片放在一起,但是仙人掌图片的绿屏覆盖了海滩图片的颜色。有谁能帮我看看如何调低仙人掌图片的绿色像素或摆脱绿屏部分? 这是我正在使用的代码。它在谷歌文档中。我迷路了。 这是一个链接,可以查看我需要做什么。最后一张图是应该的样子

https://docs.google.com/document/d/1ZYrigN1LXSMq3_llc6eimZqBh2R9ZVeBmmxSUx63__E/edit?usp=sharing

【问题讨论】:

  • 请添加一些代码来显示您到目前为止所做的尝试。另外,请通过 imgur 链接到原始图片,而不是 Google Drive 链接。

标签: python image loops if-statement nested-loops


【解决方案1】:

在这里您必须更改 (r, g, b) 值以获得最佳掩码。您也可以使用范围。看看这个。

from PIL import Image  
from PIL import ImageFilter  
import os  
 
im1 = Image.open('beach.jpg')
im2 = Image.open('cactus.jpg')
back_im = im1.copy()

for filename in os.listdir("."): 
    if filename[-3:] == "jpg":  
        img = Image.open(filename)  
        img = img.convert("RGBA")  
        pixdata = img.load()  
        for y in range(img.size[1]):  
            for x in range(img.size[0]):  
                r, g, b, a = img.getpixel((x, y))  
                if (r == 76) and (g == 244) and (b == 24):  
                    pixdata[x, y] = (255, 255, 255, 0)  
                if r == 0 and g == 0 and b == 0:  
                    pixdata[x, y] = (255, 255, 255, 0)  

        img2 = img.filter(ImageFilter.GaussianBlur(radius=1)) 
        back_im.paste(img2,mask=img2)
        back_im.save('filename.jpg')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-15
    • 2016-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多