使用颜色为 PNG 创建 Alpha 通道?
我有几张声称具有透明背景的图像,但实际上是白色的。我想使用 Python 图像库/PIL 将白色背景颜色设置为实际上透明。
由于 PNG 使用 Alpha 通道,因此我希望通过从图像边缘查找连续的白色区域来创建 Alpha 通道(这样当图像包含白色数据时,我就不会出现透明的“孔”)。
关于如何以这种方式创建 Alpha 通道有什么建议吗?
I have several images that claim to have a transparent background but are actually white. I'd like to use Python Image Library/PIL to set that white background color to actually be transparent.
Since PNG uses an alpha channel, I'd love to create the alpha channel by finding contiguous areas of white from the edges of the image (so I don't get "holes" of transparency when the image contains white data).
Any tips on how to create the alpha channel this way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜你想从外部以螺旋状穿过图像,如果像素是白色,则将其设置为透明,并且更靠近边缘的像素也是白色透明的。在不改变任何像素的情况下完成一整圈后停止。编写这样的循环应该不会太困难。做一些洪水填充,从白色边缘像素播种。
I'd guess you'd want to run across the image in a spiral from the outside, setting a pixel to transparent if it is white, and a pixel further towards the edge isalso whitetransparent. Stop once you've done a whole circle without changing any pixels.Shouldn't be too difficult to write such a loop.Do some kind of flood fill, seeded from the white edge pixels.