作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我需要找到一种使用 python 将正方形图像缩小到 256 个大像素的方法,最好使用 matplotlib 和 pillow 库。
有什么想法吗?
最佳答案
九个月过去了,我现在可以拼凑一些 Python - 根据您最初关于如何使用 Python 和 PIL/Pillow 对图像进行像素化的请求。
#!/usr/local/bin/python3
from PIL import Image
# Open image
img = Image.open("artistic-swirl.jpg")
# Resize smoothly down to 16x16 pixels
imgSmall = img.resize((16,16), resample=Image.Resampling.BILINEAR)
# Scale back up using NEAREST to original size
result = imgSmall.resize(img.size, Image.Resampling.NEAREST)
# Save
result.save('result.png')
原始图片
结果
如果将其缩小到 32x32 像素(而不是 16x16),然后重新调整大小,您会得到:
关于python - 如何用python将方形图像像素化为256个大像素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47143332/
出于好奇,我尝试了一些原型(prototype)制作,但似乎只允许在第一个位置使用子例程的原型(prototype) &。 当我写作时 sub test (&$$) { do_somethin
我需要开发一个类似于 Android Play 商店应用程序或类似 this app 的应用程序.我阅读了很多教程,发现几乎每个教程都有与 this one 类似的例子。 . 我已经开始使用我的应用程
考虑一个表示“事件之间的时间”的列: (5, 40, 3, 6, 0, 9, 0, 4, 5, 18, 2, 4, 3, 2) 我想将这些分组到 30 个桶中,但桶会重置。期望的结果: (0, 1,
我是一名优秀的程序员,十分优秀!