Showing posts with label image representation. Show all posts
Showing posts with label image representation. Show all posts

Wednesday, October 30, 2024

How Images Work as Functions in Computer Vision


Image as a Function in Computer Vision Explained | Complete Beginner to Advanced Guide

Understanding Images as Functions in Computer Vision: Complete Educational Guide

When humans look at an image, we instantly recognize faces, objects, colors, shapes, landscapes, emotions, and scenes. A computer, however, does not naturally understand images the way humans do. To a machine, an image is fundamentally a structured collection of numbers organized mathematically.

In computer vision, digital image processing, artificial intelligence, and machine learning, an image is commonly represented as a mathematical function. This representation allows computers to process, analyze, modify, compress, classify, and understand visual information.

Key Learning Idea:
Humans see pictures. Computers see numerical functions made of pixels, coordinates, and intensity values.


1. Introduction to Computer Vision

Computer vision is a field of artificial intelligence that teaches computers how to interpret visual information from the world.

Applications include:

  • Face recognition
  • Self-driving cars
  • Medical imaging
  • Object detection
  • Image classification
  • Security systems
  • Satellite image analysis
  • Robotics
  • Optical character recognition

Before computers can understand an image, they must first convert visual information into numbers.


2. What Does Image as a Function Mean?

An image is represented mathematically as a function:

\[ f(x,y) \]

Where:

  • \(f\) = image function
  • \(x\) = horizontal coordinate
  • \(y\) = vertical coordinate
  • \(f(x,y)\) = pixel intensity or color value

This means every coordinate in the image has an associated numerical value.

Simple Interpretation

Think of a spreadsheet:

  • Rows represent vertical positions
  • Columns represent horizontal positions
  • Each cell contains a numerical value

That value represents brightness or color.


3. Understanding Pixels

A pixel is the smallest visible unit of a digital image.

The word pixel comes from:

Pixel = Picture + Element

An image contains thousands or millions of pixels.

Examples:

  • 1920 × 1080 image = 2,073,600 pixels
  • 3840 × 2160 image = 8,294,400 pixels

Each pixel stores information about color or brightness.


4. Pixel Coordinates

Each pixel has a coordinate:

\[ (x,y) \]

For example:

  • \((0,0)\) = top-left corner
  • \((100,50)\) = specific location inside image

Coordinate systems help computers identify where information exists.

Coordinate Grid Example

(0,0) (1,0) (2,0)
(0,1) (1,1) (2,1)
(0,2) (1,2) (2,2)

5. Grayscale Images

A grayscale image contains only brightness information.

\[ f(x,y) = intensity \]

Intensity values usually range from:

\[ 0 \rightarrow 255 \]
Value Meaning
0 Black
255 White
128 Gray

Why Grayscale Matters

Grayscale images simplify computation.

Used in:

  • Medical imaging
  • Edge detection
  • Pattern recognition
  • Text extraction

6. RGB Color Images

Color images use three channels:

  • Red
  • Green
  • Blue
\[ f(x,y) = (R,G,B) \]

Each channel typically ranges:

\[ 0 \rightarrow 255 \]

Examples

RGB Value Color
(255,0,0) Red
(0,255,0) Green
(0,0,255) Blue
(255,255,255) White
(0,0,0) Black

7. Images as Matrices

Computers often represent images as matrices.

\[ I = \begin{bmatrix} 12 & 45 & 89 \\ 34 & 78 & 200 \\ 90 & 120 & 255 \end{bmatrix} \]

Each matrix entry represents a pixel value.

Why Matrices Are Important

Matrices enable:

  • Fast computation
  • Linear algebra operations
  • Filtering
  • Transformations
  • Deep learning

8. Mathematical Representation of Images

Continuous Image Function

\[ f(x,y) \]

Represents ideal continuous image.

Discrete Digital Image

\[ f[m,n] \]

Represents sampled digital image.

Intensity Function

\[ 0 \leq f(x,y) \leq L-1 \]

Where:

  • \(L\) = number of intensity levels

For 8-bit images:

\[ L = 256 \]

9. Brightness and Contrast

Brightness Adjustment

\[ g(x,y) = f(x,y) + c \]

Where:

  • \(c\) = brightness constant

Contrast Adjustment

\[ g(x,y) = a \cdot f(x,y) \]

Where:

  • \(a\) = scaling factor

Increasing contrast makes dark pixels darker and bright pixels brighter.


10. Image Filters

Filters modify image pixel values systematically.

Common Filters

  • Blur filter
  • Sharpen filter
  • Edge filter
  • Noise reduction filter

Blur Example

Blur averages neighboring pixels.

\[ g(x,y) = \frac{1}{9} \sum_{i=-1}^{1} \sum_{j=-1}^{1} f(x+i,y+j) \]

11. Convolution Explained

Convolution is one of the most important operations in computer vision.

A kernel slides across the image and modifies pixel values.

\[ g(x,y) = f(x,y) * h(x,y) \]

Where:

  • \(f\) = image
  • \(h\) = filter kernel
  • \(*\) = convolution operation

Example Kernel

\[ \begin{bmatrix} 0 & -1 & 0 \\ -1 & 5 & -1 \\ 0 & -1 & 0 \end{bmatrix} \]

This sharpening kernel enhances edges.


12. Edge Detection

Edges occur where pixel intensity changes rapidly.

Sobel Operator

\[ G_x = \begin{bmatrix} -1 & 0 & 1 \\ -2 & 0 & 2 \\ -1 & 0 & 1 \end{bmatrix} \]
\[ G_y = \begin{bmatrix} -1 & -2 & -1 \\ 0 & 0 & 0 \\ 1 & 2 & 1 \end{bmatrix} \]

Gradient Magnitude

\[ G = \sqrt{G_x^2 + G_y^2} \]

Large gradients indicate edges.


13. Object Detection

Object detection identifies specific objects inside images.

Examples:

  • Cars
  • Faces
  • Animals
  • Buildings
  • Traffic signs

Algorithms analyze patterns in:

\[ f(x,y) \]

to detect shapes and structures.


14. Image Compression

Images require large storage space.

Compression reduces file size.

Lossless Compression

No information lost.

Lossy Compression

Some information removed.

JPEG Compression

JPEG uses frequency transformations.

\[ F(u,v) = \sum_{x=0}^{N-1} \sum_{y=0}^{N-1} f(x,y) e^{-j2\pi(\frac{ux+vy}{N})} \]

This is based on Fourier Transform principles.


15. Machine Learning and Images

Machine learning models use image functions as input data.

The model learns patterns from pixel values.

Examples

  • Cat vs dog classification
  • Face recognition
  • Medical diagnosis
  • Autonomous driving
Deep learning transforms image functions into feature representations automatically.

16. CNN and Feature Extraction

Convolutional Neural Networks (CNNs) are specialized for image processing.

CNN Workflow

  • Input image
  • Convolution layer
  • Activation function
  • Pooling layer
  • Feature extraction
  • Classification

Activation Function

\[ ReLU(x) = \max(0,x) \]

Pooling Example

\[ P = \max(x_1,x_2,x_3,x_4) \]

Pooling reduces image dimensions while preserving features.


17. OpenCV Python Examples

Reading an Image

import cv2

image = cv2.imread("photo.jpg")

print(image.shape)

Converting to Grayscale

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

cv2.imshow("Gray", gray)
cv2.waitKey(0)

Edge Detection Example

edges = cv2.Canny(gray,100,200)

cv2.imshow("Edges", edges)
cv2.waitKey(0)

18. CLI Output Examples

CLI Example: Image Information

$ python image_info.py

Image Loaded Successfully

Width: 1920
Height: 1080
Channels: 3

Color Mode: RGB

CLI Example: Edge Detection

$ python edge_detection.py

Applying Sobel Filter...
Edges Detected Successfully

Output saved as:
edges_output.jpg

Interactive Learning Section

Computers process numerical information. Mathematical representations convert visual scenes into numbers that algorithms can analyze systematically.

RGB channels simulate human color vision by combining red, green, and blue light intensities to create millions of colors.

Matrices enable efficient computation using linear algebra, making image filtering, transformations, and deep learning possible.


19. Advanced Mathematical Concepts

Fourier Transform

\[ F(u,v) = \int_{-\infty}^{\infty} \int_{-\infty}^{\infty} f(x,y) e^{-j2\pi(ux+vy)} dxdy \]

Transforms image into frequency domain.

Gaussian Filter

\[ G(x,y) = \frac{1}{2\pi\sigma^2} e^{-\frac{x^2+y^2}{2\sigma^2}} \]

Used for smoothing and noise reduction.

Laplacian Operator

\[ \nabla^2 f = \frac{\partial^2 f}{\partial x^2} + \frac{\partial^2 f}{\partial y^2} \]

Highlights regions of rapid intensity change.

Image Gradient

\[ \nabla f = \left( \frac{\partial f}{\partial x}, \frac{\partial f}{\partial y} \right) \]

Measures directional intensity changes.


20. Final Summary

Images may look simple to humans, but computers interpret them mathematically as structured functions made of coordinates and numerical values.

Representing images as functions allows computers to:

  • Analyze patterns
  • Detect objects
  • Recognize faces
  • Apply filters
  • Compress images
  • Train AI systems
  • Perform medical analysis
  • Enable autonomous navigation

At the heart of computer vision lies the simple but powerful idea:

\[ f(x,y) \]

Every pixel has:

  • A position
  • A numerical value
  • A role in forming the complete image
Final Learning Summary:
  • An image is mathematically represented as a function.
  • Each pixel has coordinates and intensity values.
  • Grayscale images store brightness only.
  • RGB images use red, green, and blue channels.
  • Images are processed using matrices and convolution.
  • Computer vision depends heavily on mathematical transformations.
  • CNNs learn image features automatically.
  • Modern AI systems rely on image functions for visual understanding.

Featured Post

How HMT Watches Lost the Time: A Deep Dive into Disruptive Innovation Blindness in Indian Manufacturing

The Rise and Fall of HMT Watches: A Story of Brand Dominance and Disruptive Innovation Blindness The Rise and Fal...

Popular Posts