Published on January 26, 2024By DeveloperBreeze


import numpy as np
from PIL import Image

# Generate a 10x10 grid of random RGB colors
grid_size = (10, 10)
grid = np.random.randint(0, 256, (*grid_size, 3), dtype=np.uint8)
print("Generated a random 10x10 grid of colors.")

# Convert the grid into a PIL Image
image = Image.fromarray(grid)
print("Converted the grid into a PIL Image.")

# Scale up the image to 512x512 pixels using Nearest Neighbor interpolation
scaled_size = (512, 512)
image = image.resize(scaled_size, resample=Image.NEAREST)
print(f"Scaled up the image to {scaled_size} pixels.")

# Save the resulting image as 'result.png'
output_file = 'result.png'
image.save(output_file)
print(f"Image saved as '{output_file}'.")

Comments

Please log in to leave a comment.

Continue Reading:

Matrix Multiplication in Python using NumPy

Published on January 26, 2024

python

Getting Started with ApexCharts

Published on August 21, 2024

Filtering and Selecting Elements in NumPy Array

Published on January 26, 2024

python

Calculate Mean and Standard Deviation of NumPy Array

Published on January 26, 2024

python

Reshape NumPy Array

Published on January 26, 2024

python

Create a NumPy 1D Array

Published on January 26, 2024

python