0% found this document useful (0 votes)
4 views40 pages

Computer Vision 1

The document provides an overview of computer vision, defining it as a field of artificial intelligence that enables machines to interpret images and videos. It discusses various applications, types of computer vision techniques, and the significance of image representation, including binary, grayscale, and color images. Additionally, it explains convolution, edge detection, and the inefficiencies of multilayer perceptrons in processing large images, emphasizing the importance of local pattern recognition in image analysis.

Uploaded by

dohamahfoud2003
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views40 pages

Computer Vision 1

The document provides an overview of computer vision, defining it as a field of artificial intelligence that enables machines to interpret images and videos. It discusses various applications, types of computer vision techniques, and the significance of image representation, including binary, grayscale, and color images. Additionally, it explains convolution, edge detection, and the inefficiencies of multilayer perceptrons in processing large images, emphasizing the importance of local pattern recognition in image analysis.

Uploaded by

dohamahfoud2003
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Advanced

Convolutional
Neural Network
Vision par Ordinateur
2025/2026

Pr. DOUZI SAMIRA


[Link]@[Link]
Computer Vision
Definition

Computer vision is a field of artificial intelligence that


enables machines to understand and interpret images or
videos from the real world. It involves techniques such
as image classification, object detection, segmentation,
and tracking, and is widely used in areas like
autonomous driving, facial recognition, medical imaging,
and industrial automation..

02
Computer Vision

Applications :

• Facial recognition
• Autonomous Vehicles
• Medical diagnosis
• Surveillance and security

03
Types of Computer Vision
01 Classification
04 Real-time object
tracking

02 Object Detection
05 Gesture
recognition

03 Image segmentation
06 Neural Style
Transfer

04
Types of Computer Vision
01- Classification

05
Types of Computer Vision
01- Classification

06
Types of Computer Vision
02- Object Detection

07
Types of Computer Vision
03- Images Segmentation

08
Types of Computer Vision
04- Real-time object tracking

09
Types of Computer Vision
05- Gesture recognition

10
Types of Computer Vision
06- Neural Style Transfer

11
What is an image?
An image is a visual
representation of an object, scene,
or concept, usually in the form of a
pixel matrix in computing.

Each pixel contains information,


often represented by numbers, that
indicates color or light intensity.
Together, they form a data matrix.

12
What is an image?
In computer science and computer vision:
An image is typically represented as a 2D (or 3D) matrix containing numerical values.
There are several types of digital images, each represented numerically as matrices depending on
their color structure and purpose. The most common types are:
▪ Binary Images
▪ Grayscale Images
▪ Color Images (RGB)
1. Binary Image
A binary image is the simplest form of image where each pixel has only two possible values: 0 or
1. Typically, 0 represents black and 1 represents white. Binary images are useful in tasks such as
document scanning, segmentation masks, and object detection, where only the presence or
absence of information matters.
Example: A binary image of size 50×50 is represented as a 2D matrix of shape 50 × 50, where
each element is either 0 or 1.
What is an image?
2. Grayscale Image
In a grayscale image, each pixel represents the intensity of light, ranging from 0 (black) to 255 (white).
Intermediate values (e.g., 64, 128, 200) correspond to different shades of gray. These images are often used in
medical imaging, industrial inspection, and preprocessing pipelines because they reduce computational
complexity.
Example:
A grayscale image with dimensions 100×200 is represented as a 2D matrix of shape 100 × 200, where each
element is a value from 0 to 255.
3. Color Image (RGB)
A color image contains three color channels: Red, Green, and Blue (RGB). Each pixel is represented as a
triplet [R, G, B], where each component ranges from 0 to 255. The mix of these values defines the final color
of the pixel. RGB images are standard in photography, video, and many computer vision tasks such as object
recognition, scene understanding, and facial detection.
Example:
A color image of size 100×200 is represented as a 3D matrix of shape 100 × 200 × 3, where each pixel has a
vector like [123, 200, 150] representing its red, green, and blue intensity levels.
What is an image?

4. Multispectral and Hyperspectral Images in Medical Imaging

In advanced medical imaging, we often go beyond standard RGB or grayscale images by using
multispectral or hyperspectral images. These types of images capture information across
many wavelengths of light, often including non-visible bands such as infrared or ultraviolet.
Unlike RGB images, which have only three channels (Red, Green, Blue), multispectral images
may contain 5–10 channels, while hyperspectral images can contain dozens to hundreds of
spectral bands.

Each pixel in a hyperspectral image is represented not just by three values, but by a spectrum —
a detailed signature of how that pixel reflects or absorbs light at different wavelengths. This
makes it possible to detect subtle variations in tissue composition, oxygenation, or cellular
structure that are invisible in regular images.
What is an image?
In cancer diagnostics, hyperspectral imaging can be used during endoscopic
procedures to differentiate between healthy and malignant tissues. A hyperspectral
image might be represented as a 3D array of shape (height, width, N), where N is the
number of spectral bands — e.g., 256, 512, or even more.
This powerful imaging technique is valuable in histopathology, surgical guidance,
and non-invasive disease screening, but it also introduces challenges in data
processing due to its high dimensionality.
What is an image?

Example:
[255, 0, 0] → pure red
[0, 255, 0] → pure green
[0, 0, 255] → pure blue
[255, 255, 0] → yellow (red + green)
[0, 255, 255] → cyan (green + blue)
[255, 0, 255] → magenta (red + blue)
[255, 255, 255] → white
[0, 0, 0] → black
[200, 55, 0] → an orange hue
[85, 85, 85] → a medium gray
Why are MLPs inefficient for large images?
Multilayer Perceptrons (MLPs) are inefficient for large images mainly due to the massive number of
parameters required and their inability to exploit the spatial structure of image data.

1. MLPs require input to be flattened into a 1D vector. For example, a 224×224×3 image (like those in
ImageNet) becomes a vector of 150,528 elements. Each neuron in the first hidden layer would need
a weight for every single pixel, which leads to an enormous number of parameters.
2. MLPs treat each pixel independently and do not capture local spatial patterns or relationships.

128 x 128 = 16.384 valeurs 1000x1000 = 1 000 000 valeurs

13
Another way of looking at images?
Instead of treating each pixel independently, what if we could first process small
details locally, and then combine that information to understand the full image?

Alternative approach (used in CNNs and modern vision models):


▪ Capture local patterns:
Use small filters (e.g., 3×3 kernels) to detect simple features like edges, corners,
textures in small regions of the image.
▪ Build hierarchies:
Combine simple features into more complex ones—edges form shapes, shapes
form objects.
▪ Understand the full image:
By stacking layers and increasing the receptive field, the model eventually sees
the whole image but in a structured and efficient way.
14
Another way of looking at images?
Introduction to Convolution
Convolution is a fundamental operation in computer vision and deep learning. It allows us to analyze an
image by applying a filter (or kernel) that moves—or slides—across the image.
This filter is typically a small matrix (e.g., 3×3 or 5×5), and it captures local patterns such as:
▪ Edges (vertical, horizontal, diagonal),
▪ Textures (repetitive patterns),
▪ or color transitions.

16
How does Convolution work?
▪ At each position, the filter multiplies its values with the corresponding pixel
values in the image (element-wise multiplication), then sums them up.
▪ This produces a single number representing the presence or strength of a pattern
in that local region.
▪ The filter then moves (or "convolves") over to the next part of the image,
repeating the process.

17
How does Convolution work?

18
Receptive Field Size
The receptive field is the part of the input image that affects the value of a neuron in the network. In a CNN, the deeper
you go in the layers, the larger the receptive field becomes. At first, a neuron only sees a small area (like 3×3 pixels), but
in deeper layers, each neuron collects information from many smaller regions combined, allowing it to see a bigger part
of the image. This helps the network understand both small details and larger patterns.
Example
Layer 1:
Each neuron in Layer 1 looks at a 3×3 region of the input.
Now imagine 3 neurons from Layer 1 sitting next to each other:
•One looks at pixels (1–3)
•One looks at (2–4)
•One looks at (3–5)
→ Their outputs overlap, but each sees a slightly different part of the image.
Layer 2:
A neuron in Layer 2 looks at 3 adjacent neurons in Layer 1.
But remember—each of those neurons in Layer 1 already sees a 3×3 area in the input.
So, if Layer 2 looks at 3 Layer 1 neurons, and each Layer 1 neuron sees a slightly shifted 3×3 input, then Layer 2 is indirectly seeing a larger portion of the input

▪ Layer 1 neuron at position 1 sees: pixels 1–3


▪ Layer 1 neuron at position 2 sees: pixels 2–4
▪ Layer 1 neuron at position 3 sees: pixels 3–5
So, Layer 2 takes those 3 neurons as input → it now "sees" pixels 1–5 in the input. , Hence, the receptive field of Layer 2 grows to 5×5.
Edge Detection for Computer Vision
Biederman investigated the rate at which humans can recognize the object they’re looking at.
To test this, he drew outlines of common and recognizable objects and split them into two
halves, with each line segment divided in only one of the halves. These outlines were then
shown to participants to test whether they could recognize the original objects while only
seeing half of the original outline. Surprisingly, he observed no difference in terms of the
speed with which people recognized the objects. It was easy for them to recognize an object
via only parts of its edges. This study benefits computer vision by providing an insight: even
if only part of the original image is shown, a system theoretically should still be able to
recognize the whole object or scene.
The goal of edge detection is to identify sudden changes (discontinuities) in an image.
Intuitively, most semantic and shape information from the image can be encoded in
its edges. The edges help us extract information, recognize objects, and recover
geometry and viewpoint. They arise due to discontinuities in surface normal, depth,
surface color, and illumination .
In image processing, we often want to detect edges, which are points where the intensity (or brightness) of
pixels changes abruptly. A derivative gives us a measure of how much a function (like an image intensity)
changes. In digital images, we use discrete approximations of derivatives since the data is sampled.

1D Discrete Derivative Approximations :


Assume we have a 1D signal (e.g., a row or column of an image):
[𝑓 𝑥 − 1 , 𝑓 𝑥 , 𝑓(𝑥 + 1)]
We approximate the derivative at position 𝑥 using these three types:

1. Backward Difference:
𝒅𝒇
=𝒇 𝒙 −𝒇 𝒙−𝟏
𝒅𝒙
Approximates derivative by comparing current and previous pixel.
Example : Filter: [-1, 1,0]
Interpretation: Measures how much the intensity increased compared to the previous pixel.
𝑑𝑓
2. Forward Difference : 𝑑𝑥
=𝑓 𝑥+1 −𝑓 𝑥

Approximates the derivative by comparing the next and current pixel.


Filter: [0, -1, 1]
Interpretation: Measures how much the intensity will increase in the next pixel.

Central Difference :
𝑑𝑓 𝑓 𝑥 + 1 − 𝑓 𝑥 − 1
=
𝑑𝑥 2
Looks at both forward and backward differences.
Filter: [-1, 0, 1] (scaled version: [0.5, 0, -0.5])
Interpretation: Smoother and more symmetric estimate of derivative.
By applying these filters to a 1D signal (e.g., a row of an image), we can detect edges by locating positions
where the output of the derivative is large.
Example: Signal 𝑓 = 10 10 50 50

Applying the central difference at position 𝑥 = 2: 𝑓 𝑥 + 1 = 50, 𝑓 𝑥 − 1 = 10 ⇒ 𝑓 ′ 𝑥 = 40


A large value indicates a strong edge. After filtering, we typically:

▪ Compute the magnitude of the derivative:


Central : ∣ 𝑓′ 𝑥 ∣=∣ 𝑓 𝑥 + 1 − 𝑓 𝑥 − 1 ∣
Forward:
∣ 𝑓 ′ 𝑥 ∣=∣ 𝑓 𝑥 + 1 − 𝑓 𝑥 ∣
Backward:
∣ 𝑓 ′ 𝑥 ∣=∣ 𝑓 𝑥 − 𝑓 𝑥 − 1 ∣

▪ Apply a threshold to identify significant changes by compare the magnitude of the derivative to a chosen
threshold 𝑇:
1 if ∣ 𝑓 ′ 𝑥 ∣≥ 𝑇
Edge 𝑥 = ቐ
0 otherwise
Discrete Derivatives in 2D:
In two-dimensional images, each pixel has two directions of change: horizontal (x) and vertical (y). The gradient vector
represents the rate and direction of change in image intensity at each point.
𝑓𝑥
Gradient Vector: ∇𝑓 𝑥 𝑦 = Where:
𝑓𝑦
𝜕𝑓
𝑓𝑥 = is the partial derivative in the x-direction
𝜕𝑥
𝜕𝑓
𝑓𝑦 = is the partial derivative in the y-direction
𝜕𝑦
These can be approximated using central difference filters:
𝑓𝑥 ≈ 𝑓(x + 1, y) − 𝑓(𝑥 − 1, 𝑦)
𝑓𝑦 ≈ 𝑓(x, y + 1) − 𝑓(𝑥, 𝑦 − 1)
Example : Consider the grayscale intensity values in a small image patch:

10 10 10
Calculate the gradient at the center pixel (2nd row, 2nd column). 𝑓 = 10 50 50
10 50 50
Horizontal Derivative (𝑓𝑥 ) : [-1,0,1]
Apply this to the row containing the center pixel: −1 ⋅ 10 + 0 ⋅ 50 + 1 ⋅ 50 = −10 + 0 + 50 = 40

𝑓𝑥 1 1 = 40
Vertical Derivative (𝑓𝑦 ) —Use Filter:
Apply this to the column containing the center pixel:

10 −1
50 ⋅ 0 = −1 ⋅ 10 + 0 ⋅ 50 + 1 ⋅ 50 = −10 + 0 + 50 = 40
50 1
So:
𝑓𝑦 1 1 = 40

Gradient Vector:
𝑓𝑥 40
∇𝑓 1 1 = =
𝑓𝑦 40

Gradient Magnitude:
∣ ∇𝑓 ∣= 𝑓𝑥2 + 𝑓𝑦2 = 402 + 402 = 3200 ≈ 56.57

Gradient Direction:
𝑓𝑦
𝜃= 𝑡𝑎𝑛−1 = 𝑡𝑎𝑛−1 1 = 45∘
𝑓𝑥
Gradient Magnitude
The gradient magnitude measures the strength of the edge (rate of intensity change):

∣ ∇𝑓 𝑥 𝑦 ∣= 𝑓𝑥2 + 𝑓𝑦2
This scalar value is high where there is a strong edge.
Gradient Direction
The gradient direction indicates the orientation of the edge (perpendicular to edge
𝑓𝑦
direction): 𝜃 𝑥 𝑦 = tan−1
𝑓𝑥
This angle is useful for edge orientation.
Horizontal Edge Detector

A vertical edge detector


Edge Detection Operators
1. Sobel Operator: Vertical Sobel Kernel
1 0 −1
𝐺𝑦 = 2 0 −2
1 0 −1
Emphasizes vertical edges.
Larger weights (2 and -2) in the center row increase response to strong vertical contrast.
Includes smoothing, making it more robust to noise.

2. Prewitt Operator : Vertical Prewitt Kernel


1 0 −1
𝐺𝑦 = 1 0 −1
1 0 −1
Also detects vertical edges.
Uses equal weights in all rows — simpler and faster but less smoothing than Sobel.
More sensitive to noise.
3. Scharr Operator : Vertical Scharr Kernel
3 0 −3
𝐺𝑦 = 10 0 −10
3 0 −3
Vertical Scharr Kernel:
3 0 −3
𝐺𝑦 = 10 0 −10 A refinement of the Sobel operator.
3 0 −3

Places stronger emphasis on the center row.


Offers better rotational symmetry and stability under different orientations.

These operators can also be rotated (transposed) to compute horizontal gradients by using their horizontal versions.
1. Sobel Operator
1 0 −1
Vertical Sobel kernel: 2 0 −2
1 0 −1
▪ Emphasizes vertical edges.
▪ The center row has bigger weights (2 and -2), making it more sensitive to strong vertical contrasts.
▪ Smooths a bit to reduce noise.

2. Prewitt Operator
1 0 −1
Vertical Prewitt kernel: 1 0 −1
1 0 −1
Similar to Sobel but equal weights in all rows.
Simpler, less smoothing, more sensitive to noise than Sobel.

3. Scharr Operator
3 0 −3
Vertical Scharr kernel: 10 0 −10
3 0 −3
A refinement of Sobel.
Places stronger weights in the center row.
Gives better rotation invariance (more stable detection at different angles).
Effects of Noise
If there is excessive noise in an image, the partial derivatives will not be effective for identifying the edges. In order to account for the noise,
the images must first be smoothed. This is a process in which pixel values are recalculated so that they more closely resemble their neighbors.
The smoothing is achieved by means of convolving the image with a filter (e.g., gaussian kernel). There are, of course, some concerns to keep
in mind when smoothing an image. The image smoothing does remove noise, but it also blurs the edges; the use of large filters can result in the
loss of edges and the finer details of the image.
Smoothing with different filters and filter sizes.

The derivative of an edge in a noisy image


Smoothing means reducing noise or variations in pixel intensity by replacing each pixel with a value derived from
its neighborhood.

1. Mean Smoothing (Box Filter)


Replaces each pixel with the average of its neighboring pixels.
Formula (for a 3×3 kernel):

Example Kernel:
1 1 1 1
1 1 1
9
1 1 1
Pros : Simple and fast , Reduces high-frequency noise
Cons : Blurs edges significantly ,Not very robust to outliers

Example : Before mean filter:


0 0 0 𝟐𝟓𝟓 255 255

After mean filter:


0 0 85 170 255 255
᪄ ᪄
Gaussian smoothing (or Gaussian blur) is an image processing technique used to :
•Reduce noise and fine texture
•Smooth the image while still preserving important edges
It works by convolving the image with a Gaussian kernel, which applies a weighted average to each pixel and its
neighbors — closer pixels have more weight.
Gaussian Function (2D)

σ: standard deviation (controls blur amount)


𝑥 𝑦 :position relative to the center pixel

Example :

For each of these positions, we compute:


2
𝑥 +𝑦 2
1 −
𝐺 𝑥 𝑦 = ⋅ 𝑒 2𝜎2
2𝜋𝜎 2
Let’s take a 3×3 part of an image (pixel intensities):
100 100 100
100 200 100
100 100 100

The center pixel (200) is much brighter — maybe noise or a small object.
We want to smooth it out using Gaussian.

We multiply each image pixel by the corresponding kernel weight and sum them:
1
Result at center pixel = ⋅ 100 ⋅ 1 + 100 ⋅ 2 + 100 ⋅ 1 + 100 ⋅ 2 + 200 ⋅ 4 + 100 ⋅ 2 + 100 ⋅ 1 + 100 ⋅ 2 + 100 ⋅ 1
16
1
= ⋅ 100 + 200 + 100 + 200 + 800 + 200 + 100 + 200 + 100
16
1
= ⋅ 2000 = 125
16
So, the bright center pixel (200) is replaced with 125 — smoothing the intensity.

What Happens to the Image?


Before After (Smoothed)
Sharp edges and noise Softer transitions
Isolated bright pixels Averaged with neighbors
High contrast spots Less contrast, more uniform

You might also like