I need to find an way to reduce a square image to 256 big pixels with python, preferably with the matplotlib and pillow libraries.
Got any ideas ?
解决方案
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')
Original Image
Result
Paddington is so cute - he just needed to be pixellated!
If you take him down to 32x32 pixels (instead of 16x16) and then resize back up, you get:
Keywords:
Pixelate, pixellate, pixelated, pixellated, Paddington, Python, Pillow, PIL, image, image processing, nearest neighbour interpolation.
本文介绍了一种使用Python和PIL/Pillow库将图像像素化的方法。通过先将图像缩小到较低分辨率(例如16x16像素),然后放大回原始大小来实现像素效果。


被折叠的 条评论
为什么被折叠?



