Labs ICT
⭐ Pro Login

Computer Vision Basics

Making machines see and interpret images.

Computer Vision Basics

Computer vision teaches machines to "see" β€” interpreting images and videos the way humans do. It's behind facial recognition, self-driving cars, medical imaging, and Instagram filters.

An image is just a grid of numbers. A 224Γ—224 color image is a 224Γ—224Γ—3 tensor (height Γ— width Γ— RGB channels). Each pixel is a number from 0 to 255. The challenge is extracting meaning from these numbers.

Image Representation

Before any processing, you need to understand how images are stored:


    Image as Numbers
    ──────────────────────────────────────────────
    β”‚                                             β”‚
    β”‚  Grayscale: 2D matrix (H Γ— W)              β”‚
    β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                     β”‚
    β”‚  β”‚ 142  89  34  200  β”‚  ← pixel values     β”‚
    β”‚  β”‚ 67  180  95  178  β”‚    (0 = black       β”‚
    β”‚  β”‚ 234 120  45  156  β”‚     255 = white)    β”‚
    β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                     β”‚
    β”‚                                             β”‚
    β”‚  Color: 3D tensor (H Γ— W Γ— 3)              β”‚
    β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                     β”‚
    β”‚  β”‚ R: [142, 89, ...]  β”‚  ← three channels  β”‚
    β”‚  β”‚ G: [67, 180, ...]  β”‚    stacked          β”‚
    β”‚  β”‚ B: [234, 120, ...] β”‚                     β”‚
    β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                     β”‚
    ──────────────────────────────────────────────
    

Image Preprocessing

Neural networks are picky about input. Standard preprocessing steps:

Resizing: All images must be the same size. Common sizes: 224Γ—224, 256Γ—256, 299Γ—299.

Normalization: Scale pixel values to [0,1] or standardize to have mean 0 and std 1. Helps training converge faster.

Data augmentation: Artificially increase dataset size by applying random transformations β€” rotations, flips, crops, color jitter. Helps prevent overfitting.


    Data Augmentation Examples
    ──────────────────────────────────────────────
    β”‚  Original  β”‚  Flipped  β”‚  Rotated  β”‚ Croppedβ”‚
    β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β” β”‚  β”Œβ”€β”€β”€β”€β”€β”€β” β”‚β”Œβ”€β”€β”€β”€β” β”‚
    β”‚  β”‚  🐱  β”‚  β”‚  β”‚  🐱  β”‚ β”‚  β”‚  /🐱 β”‚ β”‚β”‚ 🐱 β”‚ β”‚
    β”‚  β”‚      β”‚  β”‚  β”‚      β”‚ β”‚  β”‚ /    β”‚ β”‚β”‚    β”‚ β”‚
    β”‚  β””β”€β”€β”€β”€β”€β”€β”˜  β”‚  β””β”€β”€β”€β”€β”€β”€β”˜ β”‚  β””β”€β”€β”€β”€β”€β”€β”˜ β”‚β””β”€β”€β”€β”€β”˜ β”‚
    β”‚                                             β”‚
    β”‚  One image β†’ many training samples          β”‚
    ──────────────────────────────────────────────
    

Feature Extraction

Before deep learning, engineers hand-crafted features to detect edges, corners, and textures. While outdated for most tasks, understanding these helps appreciate what CNNs learn automatically.

Edge detection: Identifying boundaries where intensity changes sharply. Simple convolution kernels can detect horizontal, vertical, or diagonal edges.

Corner detection: Finding points where edges meet. Corners are distinctive and useful for matching features across images.

Histogram of Oriented Gradients (HOG): Captures shape information by counting edge directions in local regions. Was the go-to for pedestrian detection before CNNs.


    Edge Detection Kernels
    ──────────────────────────────────────────────
    β”‚ Horizontal    β”‚ Vertical      β”‚ Diagonal    β”‚
    β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”‚
    β”‚ β”‚ -1 -1 -1  β”‚ β”‚ β”‚ -1  0  1  β”‚ β”‚ β”‚ 1  0 -1 β”‚β”‚
    β”‚ β”‚  0  0  0  β”‚ β”‚ β”‚ -1  0  1  β”‚ β”‚ β”‚ 0  1  0 β”‚β”‚
    β”‚ β”‚  1  1  1  β”‚ β”‚ β”‚ -1  0  1  β”‚ β”‚ β”‚-1  0  1 β”‚β”‚
    β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”‚
    ──────────────────────────────────────────────
    

Convolutional Neural Networks (CNNs)

CNNs are the backbone of computer vision. Instead of processing every pixel independently, they use convolutions to detect local patterns that compose into complex features.


    CNN Feature Hierarchy
    ──────────────────────────────────────────────
    β”‚                                             β”‚
    β”‚  Input Image                                β”‚
    β”‚       β”‚                                     β”‚
    β”‚       β–Ό                                     β”‚
    β”‚  Layer 1-3: Edges, corners, textures        β”‚
    β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”‚
    β”‚  β”‚ β•± ─ β”‚ β•² β”‚ ─ β•± β”‚ ─ β”‚ β•² ─ β•±    β”‚        β”‚
    β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β”‚
    β”‚       β”‚                                     β”‚
    β”‚       β–Ό                                     β”‚
    β”‚  Layer 4-6: Parts (eyes, wheels, leaves)    β”‚
    β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”‚
    β”‚  β”‚ β—―   β—―   ⬑   β—―   ⬑   β—―        β”‚        β”‚
    β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β”‚
    β”‚       β”‚                                     β”‚
    β”‚       β–Ό                                     β”‚
    β”‚  Layer 7-9: Whole objects (faces, cars)     β”‚
    β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”‚
    β”‚  β”‚ 🐱   πŸš—   🌳   🏠   πŸ‘€        β”‚        β”‚
    β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β”‚
    β”‚                                             β”‚
    β”‚  Each layer builds on the previous          β”‚
    ──────────────────────────────────────────────
    

The magic of CNNs: they learn features automatically. You don't need to tell the model to look for edges β€” it discovers that edges are useful on its own.

Key CNN Components

Convolution layer: Slides small filters across the image, computing dot products at each position. Each filter detects a specific pattern.

Pooling layer: Reduces spatial dimensions while keeping important features. Max pooling takes the maximum value in each region β€” keeps the strongest activation.

Batch normalization: Normalizes activations between layers. Speeds up training and stabilizes learning.

Global Average Pooling: Averages each feature map into a single number. Replaces fully connected layers and reduces parameters dramatically.

Classic CNN Architectures

Several architectures have shaped the field:


    Architecture Evolution
    ──────────────────────────────────────────────
    β”‚ Year β”‚ Model        β”‚ Layers β”‚ Top-5 Acc β”‚
    ──────────────────────────────────────────────
    β”‚ 2012 β”‚ AlexNet      β”‚ 8      β”‚ 83.6%     β”‚
    β”‚ 2014 β”‚ VGGNet       β”‚ 19     β”‚ 92.7%     β”‚
    β”‚ 2014 β”‚ GoogLeNet    β”‚ 22     β”‚ 93.3%     β”‚
    β”‚ 2015 β”‚ ResNet       β”‚ 152    β”‚ 96.4%     β”‚
    β”‚ 2017 β”‚ DenseNet     β”‚ 264    β”‚ 96.5%     β”‚
    β”‚ 2019 β”‚ EfficientNet β”‚  ~     β”‚ 97.1%     β”‚
    β”‚ 2020 β”‚ ViT          β”‚  ~     β”‚ 97.5%+    β”‚
    ──────────────────────────────────────────────
    β”‚ Trend: Deeper β†’ Better (until diminishing    β”‚
    β”‚ returns β†’ then architectural innovation)     β”‚
    ──────────────────────────────────────────────
    

ResNet introduced skip connections, allowing training of very deep networks. EfficientNet systematically scales model size, resolution, and depth. ViT applies pure Transformers to images, showing attention mechanisms work beyond text.

Practical Applications

Computer vision is everywhere:

Medical imaging: Detecting tumors, analyzing X-rays, segmenting organs. AI can match or exceed radiologists in specific tasks.

Autonomous vehicles: Understanding the road β€” detecting lanes, pedestrians, signs, other vehicles in real-time.

Manufacturing: Quality control β€” detecting defects in products on assembly lines faster than human inspectors.

Augmented reality: Understanding the environment to overlay digital content β€” like measuring furniture with your phone camera.

The field moves fast. What was cutting-edge two years ago is now a commodity. Start with pre-trained models and transfer learning β€” it's rarely worth training from scratch.

πŸ§ͺ Quick Quiz

What is the main task of computer vision?