0

I want to manipulate some images with Python for a little quiz game. The quiz player should guess the image.

I think an image with only big pixel areas would be fine. I want a similar result like this: https://www.ixxiyourworld.com/media/2387631/ixsp110-van-gogh-petrol-pixel-03.jpg

matt
  • 161
  • 5

1 Answers1

0

Lets try PIL to first downscale the image massively to a given kernel size, then upscale with NEAREST back to the same size -

from PIL import Image
from numpy import asarray

img = Image.open("van_gogh.jpg", mode='r')

factor = 100

kernel = (img.height//factor, img.width//factor)
pixelated = img.resize(kernel,resample=Image.BICUBIC) #downsample
pixelated = pixelated.resize(img.size,Image.NEAREST) #upsample

#Grids
grid_color = [255,255,255]

dx, dy = factor, factor
g = np.asarray(pixelated).copy()

g[:,::dy,:] = grid_color
g[::dx,:,:] = grid_color

pixelated2 = Image.fromarray(g)
pixelated2

enter image description here

Increasing the factor here, will pixelate the image further.

factor = 100

enter image description here

Akshay Sehgal
  • 18,741
  • 3
  • 21
  • 51