如何使用python将正方形图像像素化为256个大像素? [英] How to pixelate a square image to 256 big pixels with python?

查看:502
本文介绍了如何使用python将正方形图像像素化为256个大像素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找到一种方法,使用python(最好是使用matplotlib和枕头库)将正方形图像缩小到256个大像素.

I need to find an way to reduce a square image to 256 big pixels with python, preferably with the matplotlib and pillow libraries.

有什么想法吗?

推荐答案

九个月过去了,现在我可以按照自己关于如何使用Python和PIL/Pillow对图像进行像素化的原始要求,拼凑一些Python.

Nine months pass and I can now cobble together some Python - per your original request on how to pixellate an image with Python and PIL/Pillow.

#!/usr/local/bin/python3
from PIL import Image

# Open Paddington
img = Image.open("paddington.png")

# Resize smoothly down to 16x16 pixels
imgSmall = img.resize((16,16),resample=Image.BILINEAR)

# Scale back up using NEAREST to original size
result = imgSmall.resize(img.size,Image.NEAREST)

# Save
result.save('result.png')

原始图片

结果

帕丁顿是如此可爱-他只需要像素化即可!

Paddington is so cute - he just needed to be pixellated!

如果将他缩小到32x32像素(而不是16x16),然后重新调整大小,则会得到:

If you take him down to 32x32 pixels (instead of 16x16) and then resize back up, you get:

关键字:

像素化,像素化,像素化,像素化,帕丁顿,Python,枕头,PIL,图像,图像处理,最近邻插值.

Pixelate, pixellate, pixelated, pixellated, Paddington, Python, Pillow, PIL, image, image processing, nearest neighbour interpolation.

这篇关于如何使用python将正方形图像像素化为256个大像素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆