Practice: CNN Vision Filter Design
Practice working with image data and understanding computer vision concepts.
10 min•By Priygop Team•Updated 2026
Practice: Image as Numbers
Practice: Image as Numbers
# Practice: Work with images as number grids
def create_gradient_image(width, height):
"""Create a gradient image from left (dark) to right (bright)."""
image = []
for row in range(height):
r = []
for col in range(width):
pixel = int(col / (width - 1) * 255)
r.append(pixel)
image.append(r)
return image
def image_stats(image):
"""Calculate basic statistics about an image."""
flat = [px for row in image for px in row]
total = len(flat)
total_brightness = sum(flat)
return {
"width": len(image[0]),
"height": len(image),
"total_pixels": total,
"min_brightness": min(flat),
"max_brightness": max(flat),
"avg_brightness": total_brightness / total,
}
# Create and analyze a gradient image
gradient = create_gradient_image(10, 5)
print("Gradient Image (0=dark, 255=bright):")
for row in gradient:
visual = "".join(
" " if px < 85 else ("." if px < 170 else "#")
for px in row
)
print(f" |{visual}|")
print()
stats = image_stats(gradient)
print("Image Statistics:")
for key, value in stats.items():
print(f" {key}: {value if isinstance(value, int) else f'{value:.1f}'}")
print()
# Apply a simple brightness adjustment
factor = 0.7 # darken
darkened = [[int(px * factor) for px in row] for row in gradient]
print(f"After darkening (factor={factor}):")
for row in darkened:
visual = "".join(
" " if px < 85 else ("." if px < 170 else "#")
for px in row
)
print(f" |{visual}|")Diagram
Loading diagram…
Educational visual guide for practice cnn vision filter design.