We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
根据要求使用 ImageMagick:
感谢@mf511 的更新。
Using ImageMagick, as requested:
Thanks @mf511 for the update.
cssndrx 答案的更完整版本,使用 numpy 中的切片来提高速度:
等等瞧!
A more complete version of the cssndrx answer, using slicing in numpy to improve speed:
Et voila !
我刚刚发布了一些 Python 和 C 代码,可以满足您的需求。它在github上: http://github.com/maxme/PNG-Alpha-Premultiplier
Python 版本基于 cssndrx 响应。 C版本基于libpng。
I just released a bit of code in Python and in C that does what you are looking for. It's on github: http://github.com/maxme/PNG-Alpha-Premultiplier
The Python version is based on the cssndrx response. C version is based on libpng.
通过 PIL 应该可以做到这一点。以下是步骤的粗略概述:
1) 加载图像并转换为 numpy 数组
2) 修改矩阵。该矩阵是每行内像素列表的列表。像素表示为 [r, g, b, a]。编写您自己的函数将每个 [r, g, b, a] 像素转换为您想要的 [r, g, b] 值。
3)使用将矩阵转换回图像
It should be possible to do this through PIL. Here is a rough outline of the steps:
1) Load the image and convert to numpy array
2) Modify the matrix in place. The matrix is a list of lists of the pixels within each row. Pixels are represented as [r, g, b, a]. Write your own function to convert each [r, g, b, a] pixel to the [r, g, b] value you desire.
3) Convert the matrix back to an image using
仅使用 PIL:
Using PIL only: