Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image #Import the Image module from the PIL library
- image = Image.open("houses.png") #Create a path to the image file
- rgb_image = image.convert('RGB') #Convert the image to RGB
- width, height = image.size #Assign the image's width and height to variables
- output_image = Image.new('RGB', (width,height)) #Create a grid for the output image
- out = Image.new('RGB', (width,height))
- pixelAmount = 8
- for row in range(0, height - pixelAmount, pixelAmount):
- for col in range(0, width - pixelAmount, pixelAmount):
- r, g, b = rgb_image.getpixel((col, row))
- for o in range(row, row + pixelAmount):
- for p in range(col, col + pixelAmount):
- out.putpixel((p,o), (r,g,b))
- out.save("pixelation_image_out.png")
- out.show()
Advertisement
Add Comment
Please, Sign In to add comment