[英]Change number of colors for each pixel in .gif image?
Is it possible to remape (for example) a 256-colors-gif image into a 128-colors or 64-colors gif image in Python? 是否可以在Python中将256色gif图像重新映射(例如)为128色或64色gif图像?
I tried it using the imageio library 我尝试使用imageio库
import imageio
def myfunction(inputgif, outputgif, duration):
gifimage = imageio.mimread(inputgif)
for i in range(len(gifimage)):
gifimage[i] = gifimage[i]/4
with imageio.get_writer(outputgif, mode='I', duration=duration) as writer:
for x in range(len(gifimage)):
writer.append_data(gifimage[x])
writer.close()
It's working, but, the problem is that the image file still thinks that "his universe" is 256 possible values for the color (from 0 to 255), not from 0 to 64 (since I divided all the values by 4). 它正在工作,但是问题是图像文件仍然认为“他的宇宙”是该颜色的256个可能值(从0到255),而不是0到64(因为我将所有值除以4)。 Which makes the image goes only darker, instead of using a 64 (4 bits) possible colors. 这使得图像仅变暗,而不使用64(4位)可能的颜色。
My goal is to obtain a lossy data compression by decreasing number of colors. 我的目标是通过减少颜色数量来获得有损数据压缩。
The GIF format only supports palette entries on 8 bits. GIF格式仅支持8位的调色板条目。
Even if it supported less, the savings would be marginal: 12.5% for 7 bits, 25% for 6 bits. 即使支持更少,节省的费用也将是微不足道的:7位为12.5%,6位为25%。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.