Python 生成像素化的图片

本贴最后更新于 1495 天前,其中的信息可能已经沧海桑田

分享一个 python 的工具,将图片生成像素化的图片。

可以用来生成桌面,图片背景

官方地址:https://github.com/sedthh/pyxelate

安装

pip3 install git+https://github.com/sedthh/pyxelate.git

编写 test.py

from pyxelate import Pyxelate
from skimage import io
import matplotlib.pyplot as plt

img = io.imread("blade_runner.jpg") #图片的地址
# generate pixel art that is 1/14 the size
height, width, _ = img.shape 
factor = 14
colors = 6
dither = True

p = Pyxelate(height // factor, width // factor, colors, dither)
img_small = p.convert(img)  # convert an image with these settings

_, axes = plt.subplots(1, 2, figsize=(16, 16))
axes[0].imshow(img)
axes[1].imshow(img_small)
plt.show()

运行

python3 test.py

image.png

哈哈可能图片的原因,没有官方 GitHub 的效果好

image.png
image.png

更多效果,大家自己挖掘哈

  • Python

    Python 是一种面向对象、直译式电脑编程语言,具有近二十年的发展历史,成熟且稳定。它包含了一组完善而且容易理解的标准库,能够轻松完成很多常见的任务。它的语法简捷和清晰,尽量使用无异义的英语单词,与其它大多数程序设计语言使用大括号不一样,它使用缩进来定义语句块。

    535 引用 • 672 回帖

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...
yuanhenglizhen
笔落兴亡定三端之妙,墨写清白尽六艺之奥