KEY NOTE:A person can just once see an image or a picture and at a moment be able to describe where, which and what is in that picture.
--->You can probably ask youself how Machines just get to see an image and be able to describe all features about it right away!!
This is what we are going to see: "computer vision:how machines see,process and understand images "
What is Computer Vision?
Computer vision is a field of artificial intelligence (AI) that teaches computers to see, process, and understand visual information from digital images and videos
for example: when you uplaod a car-photo, A computer doesn't automatically know what a car is just because it sees a picture. A machine learning model must learn patterns from training images.
humans just see a picture as it is but machine just see it in numbers
what computer vision do?
-
Image classifiction
Predicts what an image contains
-
Object detection
Identifies objects and locates them wih bounding boxes
-
Image segmentation
Classifies individual pixels into regions or objects.
-
Video analysis and tracking
Detects objects across video frames and follows their movement
Images as tensors in pytorch
You have already learned about tensors in PyTorch. A tensor is a data structure that can store numbers in one or more dimensions.
Different shapes , according to the image:
1.Grayscale image
--->usually represented by 2D array of pixel values
Shape:(height * width)
2.Color image
---> usually represented by three colors channels(Red,Green,Blue)
Shape:(height*width*3)
3.A batch of color images
---> several images grouped together for model processing
shape:(batch*channels*height*width)
how to load the image in pytorch
We'll use three tools:
- Pillow (PIL): opens and reads image files.
- PyTorch: stores image data in tensors and prepares it for a model.
- Matplotlib: displays the image and helps us visualize it.
1.Prepare the environment
import torch
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
from google.colab import files
Library ** Purpose**
torch Creates and manipulates tensors
numpy Works with numerical arrays
matplotlib Displays images
PIL.Image Opens and reads image files
files Lets you upload a file to Colab
2.upload a photo
uploaded = files.upload()
this will provide you with upload option.
3.Three-channel color image
image = Image.open(filename).convert("RGB")
The convert("RGB") instruction ensures that we work with a three-channel color image, even if the original file was grayscale or used a different color format.
4.Convert the image into numbers
# Convert the image into a NumPy array
image_array = np.array(image)
Computer Vision: Filters and Finding Edges
Computer Vision techniques process those numbers to find useful patterns, such as:
- Brightness and colors: Which parts are light, dark, or different colors?
- Edges: Where does the cat end and the background begin?
- Textures and shapes: What patterns form the ears, eyes, and body?
- Objects: Does the image contain a cat, a person, a car, or something else?
What is an image filter?
--->A filter is a mathematical operation applied to an image's pixels.
Different kernel values produce different effects: some smooth an image, some detect edges, and others emphasize fine details.
Sobel X and Sobel Y: detecting changes in two directions:
Sobel X and Sobel Y are not two types of objects or two separate kinds of images. They are two filters that measure brightness changes in different directions.
--->The Sobel operator uses two (3 \times 3) kernels.
Sx=[
[-1 0 1],
[-2 0 2],
[-1 0 1]
]
----> Sobel X measures how quickly brightness changes as we move from left to right
Sy=[
[-1 -2 -1],
[0 0 0],
[1 2 1]
]
---->Sobel Y measures how quickly brightness changes as we move from top to bottom.
How does a Sobel filter actually calculate an edge?
eg:Suppose the left side is dark and the right side is bright:
I=[
[10 10 100],
[10 10 100],
[10 10 100]
]
Grayscale: removing color information
It simplifies the image when color is not the main thing we need. We can focus on brightness differences, shapes, and boundaries.
example:
Pic1: Original color image
Pic2: Grayscale image
A color image commonly has three channels: Red, Green, and Blue (RGB). Each pixel has three values.
A grayscale image represents each pixel with one brightness value rather than three color values.
Blur: reducing noise and tiny details
Blur makes an image smoother by combining information from neighboring pixels.
Why do we use blur before detection?
For example: Imagine we have a photo of leaf. and the leaf has a clear boundary but its surface contains some details and also other things such as small trees and others.
if we detect edges immediately , the computer might detect both leaf boundaary and mant tiny surface details yet we want a leaf.
Soo **Blurring **reduces some of those small variations, allowing the stronger boundaries to stand out.
1.Original photo of a leaf 2.Blurred Image
2.Blurred Image
KEY NOTE:too much blur can remove real details and make edges less precise.
What is an edge?
An edge is a location where image intensity changes significantly.
Consider these grayscale pixel values across a row:
[
[20,\ 20,\ 22,\ 21,\ 220,\ 225,\ 224]
]
The values change only slightly at first, then jump from (21) to (220).
That large change could indicate a boundary between a dark object and a bright background.
Types of edges:
Vertical edges:A boundary that runs vertically, such as the left or right side of a door.
Horizontal edges:A boundary that runs horizontally, such as the top of a table.
Diagonal edges:Boundaries that run diagonally, such as a sloping roof or the side of a tilted object.
Soft or gradual edges:Brightness changes gradually rather than suddenly, for example because of shadows, soft lighting, or a blurry boundary.
Sharpening: making details stand out
Sharpening emphasizes local differences between neighboring pixels. It can make boundaries and fine details appear clearer.
eg1: without shapening:
eg2:with shapening:
What does sharpening contribute?
Makes some boundaries look more defined.
Emphasizes small details and textures.
Can make a slightly soft image appear clearer.
Take this:
The big idea to remember is that filters let us transform an image into a form that emphasizes particular information. Grayscale focuses on brightness, blur smooths variations, Sobel measures directional changes, Canny extracts refined edges, and sharpening emphasizes local detail. These are foundational tools for understanding how more advanced Computer Vision systems process visual information.
Still learning, still exploring, and growing in Computer Vision.......







Top comments (3)
I really enjoyed reading your blog! 🥰 It helped me understand computer vision better and made me more curious about how computers can learn to understand images. One thing I learned is that computer vision is not just about recognizing pictures, but also about processing visual information to solve real-world problems. I think adding more practical coding examples, screenshots of the results, and a small beginner-friendly project would make the blog even more interesting and easier to follow. Overall, great work sharing your learning journey! 👏❤️
I really liked how you explained computer vision step by step, from understanding images as numbers and tensors to applying filters such as grayscale, blur, Sobel, and sharpening. The practical examples and images make the concepts easier for beginners to understand. I especially liked the explanation of Sobel X and Sobel Y because it clearly shows how filters detect changes in different directions.
You could improve the flow by organizing the practical steps and code examples more clearly, so readers can easily follow along and try them themselves. It would also help to include the complete code for applying some of the filters and showing their results. A few spelling and grammar corrections, along with consistent formatting of headings and code, would make the article more polished. Also, clarifying that image filters are basic image-processing techniques, while many modern computer vision models learn features automatically, would strengthen the explanation.
Overall, this is a detailed and useful beginner-friendly introduction to computer vision. I appreciate how you combined theory with practical examples to explain how computers process images. Keep up the great work!
Wooow. This was so amazing. You demonstrated very well on how the computers see numbers whereby the human eye just sees an image. This showed how much you were very interested in learning this and please keep up the spirit as the are more things to learn and dive in.