Online · Kaunas · Lithuania

Python Coding Classes for Children in Kaunas

Python coding classes for children in Kaunas introduce clean, readable syntax so students focus on programming logic—through text adventures, quizzes and interactive tools.

Python Kaunas

Chapter 160 — Computer Vision Basics: The Math Behind How AI Understands Images

1. Introduction: Digitizing the Analog World

In artificial intelligence, the modern landscape is divided into three primary paradigms: Data Science, Computer Vision (CV), and Natural Language Processing (NLP). Among these, Computer Vision represents a massive pillar dedicated to processing and understanding visual media—specifically images and videos.

  ┌─────────────────────────────────────────────────────────────┐
  │                 The Three Major AI Paradigms                │
  ├─────────────────────────────────────────────────────────────┤
  │  1. Data Science              ──► Tabular & Structured Data │
  │  2. Computer Vision (CV)      ──► Images & Video Streams    │
  │  3. Natural Language Processing ──► Text & Speech Sequences │
  └─────────────────────────────────────────────────────────────┘
    

Analog vs. Digital Representation

  • The Analog Real World: Human eyes perceive light as a continuous, analog stream of varying brightness and wavelengths across physical space.
  • The Digital Computer World: Computers cannot process continuous analog signals; they operate strictly on quantitative numerical structures.
  • Sampling & Digitization: To allow a computer to perceive an image, the continuous real-world light field is sampled onto a finite 2D spatial grid. Each individual cell within this discrete grid is assigned numerical values representing light intensity.

2. Mathematical Representation of a Digital Image

Formally, a digital image is modeled as a discrete two-dimensional spatial function, denoted as I(x, y):

I(x, y) = Light Intensity at Spatial Coordinate (x, y)

  • I: Represents the light intensity (brightness or color value) at a specific coordinate.
  • (x, y): Represents the discrete spatial location on the image plane.
  ┌─────────────────────────────────────────────────────────────┐
  │                  Image Coordinate System                    │
  ├─────────────────────────────────────────────────────────────┤
  │  Origin (0,0)                                               │
  │    ┌───────────────────────────────► X-axis (Width n)       │
  │    │ (0,0)   (0,1)   (0,2) ...                              │
  │    │ (1,0)   I(i,j)                                         │
  │    │ (2,0)                                                  │
  │    ▼                                                        │
  │  Y-axis (Height m)                                          │
  └─────────────────────────────────────────────────────────────┘
    

The Pixel (Picture Element)

  • Definition: A pixel (short for picture element) is the smallest discrete building block of a digital image.
  • Matrix Representation: Mathematically, a digital image is stored in computer memory as a 2D matrix or 2D array of size m × n:
    • m: Represents the height of the image (total number of rows).
    • n: Represents the width of the image (total number of columns).
    • I(i, j): Denotes the pixel intensity value at row i and column j.

Standard Coordinate Conventions:

  • Origin (0, 0): Positioned at the top-left corner of the image matrix.
  • Horizontal Axis (x-axis): Extends from left to right along the image width (columns).
  • Vertical Axis (y-axis): Extends from top to bottom down the image height (rows).

3. Grayscale Images & 8-Bit Pixel Intensity Mapping

A grayscale image contains no color hues—only varying levels of brightness across a single channel (the Gray Channel). Each pixel is represented by a single scalar numerical value.

  ┌─────────────────────────────────────────────────────────────┐
  │              8-Bit Pixel Intensity Scale (0–255)            │
  ├─────────────────────────────────────────────────────────────┤
  │  Pixel Value = 0   ──► Pure BLACK (Minimum Intensity)       │
  │  Pixel Value = 128 ──► Mid-Tone GRAY                        │
  │  Pixel Value = 255 ──► Pure WHITE (Maximum Intensity)       │
  └─────────────────────────────────────────────────────────────┘
    

The 8-Bit Storage Standard:

Computer memory stores grayscale pixel values using 8 bits (1 byte) per pixel:

Total Intensity Levels = 28 = 256 Discrete Levels (Ranging from 0 to 255)

  • 0: Represents pure black (zero light intensity).
  • 255: Represents pure white (maximum light intensity).
  • 1 to 254: Represent 254 intermediate shades of gray. For instance, 1 is an almost unnoticeable off-black, 128 is a neutral gray, and 254 is an off-white.

Using 8 bits per pixel maximizes memory efficiency by utilizing a full byte cleanly.

4. Color Images (RGB) & 3D Tensors

Natural color perception is constructed by combining three fundamental primary additive color channels: Red (R), Green (G), and Blue (B).

  ┌─────────────────────────────────────────────────────────────┐
  │                3D Color Image Tensor Layout                 │
  ├─────────────────────────────────────────────────────────────┤
  │                                                             │
  │    Height (m) × Width (n) × 3 Color Channels (R, G, B)      │
  │                                                             │
  │         ┌───────────┐  Red Channel Matrix (R)               │
  │       ┌───────────┐ │  Green Channel Matrix (G)             │
  │     ┌───────────┐ │ │  Blue Channel Matrix (B)              │
  │     │  Pixel    │ │ │                                       │
  │     │ (i, j)    │ │ │  Each pixel (i,j) stores vector:      │
  │     │           │ │─┘  [ R(i,j), G(i,j), B(i,j) ]           │
  │     └───────────┘─┘                                         │
  └─────────────────────────────────────────────────────────────┘
    

Pixel Vector Representation:

In a color image, every spatial location (i, j) stores a vector of three numerical values:

Pixel(i, j) = [ R(i, j), G(i, j), B(i, j) ]

Where R(i, j), G(i, j), and B(i, j) each range independently from 0 to 255.

3D Tensor Transformation:

Combining spatial dimensions with color channels transforms a 2D matrix into a 3D Tensor:

Tensor Dimensions = Height (m) × Width (n) × Channels (c)

  • For standard RGB images, c = 3.
  • Specialized Domains: In medical imaging or remote sensing, additional channels may be included, such as a Depth channel (Z-buffer) or Infrared (IR) data.

Concrete Memory Calculation Example (HD Image):

Consider a standard High Definition (HD) image with a spatial resolution of 1920 × 1080 pixels across 3 color channels:

Total Numerical Elements = 1920 × 1080 × 3 = 6,220,800 numbers

Storing a single uncompressed HD image in computer memory requires 6.22 million numerical values (approximately 6.22 MB).

5. Fundamental Image Mathematical Operations

Because digital images are stored as numerical matrices, image processing algorithms manipulate visuals using matrix arithmetic:

  ┌─────────────────────────────────────────────────────────────┐
  │                 Basic Image Matrix Operations               │
  ├─────────────────────────────────────────────────────────────┤
  │  1. Brightness Adjustment (Scalar Addition):                │
  │     I_new(x, y) = I_old(x, y) + c                           │
  │                                                             │
  │  2. Noise Reduction (Averaging Operation):                  │
  │     I_average = (I₁ + I₂) / 2                               │
  └─────────────────────────────────────────────────────────────┘
    
  1. Brightness Adjustment (Scalar Addition): I_new(x, y) = I_old(x, y) + c. Adding a positive constant factor c to every pixel value increases overall image brightness.
  2. Noise Reduction (Averaging): I_average = (I₁ + I₂) / 2. Averaging pixel intensity values across neighboring pixels or successive image frames reduces random visual noise and smooths the image signal.

6. Summary Comparison Table: Grayscale vs. Color (RGB)

Feature / Metric Grayscale Image Color (RGB) Image
Data Structure 2D Matrix (m × n). 3D Tensor (m × n × 3).
Channel Count 1 Channel (Gray Channel). 3 Channels (Red, Green, Blue).
Values per Pixel 1 Scalar Numerical Value. Vector of 3 Values [R, G, B].
Bit Depth per Channel 8 bits (1 byte). 8 bits per channel (24 bits total per pixel).
Intensity Range 0 (Black) to 255 (White). 0 to 255 per channel.
HD Memory Requirement 1920 × 1080 × 1 = 2.07 Million Numbers. 1920 × 1080 × 3 = 6.22 Million Numbers.

Lesson Q&A

Digital Representation: Computers treat continuous analog images as quantitative structures by sampling them into a discrete 2D matrix or array of size m × n, where m represents the height and n represents the width.

Pixels and Intensity: Each unit cell in this grid is called a pixel (picture element), which is the smallest discrete element of a digital image. Each pixel stores a numerical value I(x, y) that represents the light intensity or color brightness at that specific location.

Coordinate System Convention: In computer vision, the origin (0, 0) is placed at the top-left corner of the image:

  • The x-axis moves horizontally from left to right along the width.
  • The y-axis moves vertically downwards from top to bottom along the height.

Grayscale Images (Single Channel): Grayscale images contain no color and use a single gray channel. Each pixel value is typically stored using 8 bits (1 byte).

  • Range: An 8-bit representation yields 28 = 256 intensity values ranging from 0 to 255.
  • Interpretation: 0 represents pure black (minimum intensity), 255 represents pure white (maximum intensity), and intermediate values (1–254) represent various shades of gray.

Color Images (RGB / 3D Matrix): Color images combine three primary color channels—Red, Green, and Blue (RGB). This converts the image from a 2D matrix into a 3D matrix formatted as (Height × Width × Channels). Each pixel location (i, j) contains three separate scalar values: (Ri,j, Gi,j, Bi,j).

Memory Example: Storing a standard HD image (1920 × 1080 resolution) across 3 color channels requires 1920 × 1080 × 3 ≈ 6.22 million numerical values/bytes in memory.

  1. Increasing Image Brightness: Brightness is increased across an image by adding a constant scalar factor c to every pixel's intensity value: Inew(x, y) = Iold(x, y) + c
  2. Noise Reduction via Pixel Averaging: Image noise can be smoothed out by computing the average intensity across pixels: Iavg = (I1 + I2) / 2

What children can learn

WhatsApp +92 322 421 7059

AI and Robotics Club | The 100 Mission AI & Robotics Hero Journey

Recommended self-paced course for parents & educators

Python for Kids – 12 Pillars on Udemy.

Disclosure: This page contains affiliate links. We may earn from qualifying purchases at no extra cost to you. Links are intended for parents and educators, not as marketing directed at young children.

Academic Code Foundations: Python Syntax and Functions for Kids in Kaunas

Kaunas families benefit from a first text language that stays readable. Classes treat variables as named storage and focus on problem-solving over punctuation. Live sessions plus practice. Enquire WhatsApp +92 322 4217059. No invented Kaunas campus.

Frequently asked questions

Why is Python recommended for young coders in Kaunas?

Python's clean syntax allows students to focus on learning core programming logic without syntax frustration.

What mini projects do kids build in Python?

Projects include text adventure games, math quiz engines, and interactive data tools.

Where can families access self-paced video guides?

Check our website's course directory for verified links to our Python video courses.

Explore related learning

VilniusRobotics · Vilnius TartuPython · Tartu KlaipedaAI · Klaipeda