DEV Community

Rose Umutesi
Rose Umutesi

Posted on

# Understanding Computer Vision: From Pixels to Object Detection

Introduction

Computer vision is a field of artificial intelligence that enables computers to process and understand images and videos. It can be used in different areas, such as detecting vehicles, analyzing medical images, and identifying plant diseases.

During the Introduction to Computer Vision — Live Demo in the kLab TekHer AI Program, Cohort 2, I explored how computer vision works through practical experiments using Python and pretrained YOLO models. I worked with a sample bus image and my own photo to explore image processing, classification, object detection, and segmentation. I also tested how changes in brightness and image resolution affected the model's predictions.

In this blog, I explain what I did, the results I observed, and what I learned from the experiment.

1. How does a computer see an image?

When we look at a photograph, we can easily recognize objects such as people, buses, and buildings. A computer processes an image differently. A digital image is represented by numbers stored in an array, and a computer vision model uses patterns learned from data to make predictions.

For example, an RGB image has three color channels: red, green, and blue. Each pixel contains a value for each channel.

I used Python to load the bus image and inspect its numerical values.

import numpy as np
from PIL import Image

img = np.array(Image.open(IMAGE_PATH).convert("RGB"))

print("Image shape:", img.shape)
print("Data type:", img.dtype)
print("Minimum value:", img.min())
print("Maximum value:", img.max())
Enter fullscreen mode Exit fullscreen mode

My output was:

Image shape: (1080, 810, 3)
Data type: uint8
Minimum value: 0
Maximum value: 255
Enter fullscreen mode Exit fullscreen mode

This means the image had 1080 rows, 810 columns, and three color channels. The data type uint8 stores integer values between 0 and 255 for each channel.

For example, a pixel with values [197, 184, 168] represents a color formed by combining its red, green, and blue values.

What I learned: An image is not just a photograph to a computer. It is numerical data that can be inspected and processed using Python. Understanding this helped me see how computers can work with images.

2. Applying filters to images

After exploring how images are represented, I tested how filters can change them. A filter applies a mathematical operation to image pixels to create an effect, such as smoothing an image or highlighting its edges.

Grayscale

Grayscale removes the original color information and represents the image using shades of gray. I created a simple grayscale image by averaging the three color channels.

gray = img.mean(axis=2)

plt.imshow(gray, cmap="gray")
plt.title("Grayscale Image")
plt.axis("off")
plt.show()
Enter fullscreen mode Exit fullscreen mode

Blur

A blur filter smooths an image by averaging nearby pixel values. I used a 5 × 5 kernel for this experiment.

blur_kernel = np.ones((5, 5)) / 25
blurred = convolve(gray, blur_kernel)

plt.imshow(blurred, cmap="gray")
plt.title("Blurred Image")
plt.axis("off")
plt.show()
Enter fullscreen mode Exit fullscreen mode

The kernel is a small matrix that moves across the image and combines neighboring pixel values.

Edge detection

Edges are areas where brightness changes sharply. I used Sobel filters to highlight changes in horizontal and vertical directions.

sobel_x = np.array([
    [-1, 0, 1],
    [-2, 0, 2],
    [-1, 0, 1]
])

sobel_y = sobel_x.T

edges = np.hypot(
    convolve(gray, sobel_x),
    convolve(gray, sobel_y)
)

plt.imshow(edges, cmap="gray")
plt.title("Detected Edges")
plt.axis("off")
plt.show()
Enter fullscreen mode Exit fullscreen mode

I also tested sharpening, which emphasizes differences between neighboring pixels and can make details appear clearer.

These operations relate to image enhancement, where image properties are adjusted to change the visual result. The Pillow documentation explains how enhancement factors can be used to modify properties such as brightness and sharpness. Pillow ImageEnhance documentation

What I learned: Different filters highlight different information. Grayscale removes color, blur smooths details, edge detection highlights boundaries, and sharpening emphasizes details. This helped me understand some of the basic operations used in image processing.





Computer vision experiment screenshot 1 Computer vision experiment screenshot 3

Computer vision experiment screenshot 2

3. Image classification: What is in the image?

Image classification assigns a category to an entire image. It answers a question such as, “What does this picture most likely contain?”

The Ultralytics documentation describes classification as categorizing an image based on its content. This is different from identifying the exact location of each object in the image. Ultralytics YOLO tasks documentation

I used a pretrained YOLO classification model:

from ultralytics import YOLO

classifier = YOLO("yolo11n-cls.pt")
results = classifier(IMAGE_PATH, verbose=False)

print(results[0].probs.top5)
Enter fullscreen mode Exit fullscreen mode

When I tested the bus image, the top predictions were:

Predicted label Confidence
Minibus 57.1%
Police van 33.7%
Trolleybus 4.2%
Recreational vehicle 1.4%
Streetcar 0.6%

The model predicted minibus with the highest confidence, followed by police van.

I also tested my own photo. The top predictions included grocery_store at 16.6%, French_horn at 16.4%, and restaurant at 8.6%. These labels did not clearly describe my photo, and the confidence scores were low.

What I learned: Classification can provide useful predictions, but it does not always produce the correct or most meaningful label. I learned to examine the model's predictions and confidence scores instead of automatically accepting its first answer.
Computer vision experiment screenshot

4. Object detection: What is in the image, and where?

Object detection goes a step further than classification. It identifies objects and shows their locations using rectangular boxes called bounding boxes. The model can return a label, a confidence score, and coordinates for each detected object.

According to the Ultralytics documentation, object detection identifies and locates objects in images or video frames using bounding boxes. This makes it useful when we need to know both what an object is and where it appears. Ultralytics YOLO tasks documentation

I loaded a pretrained YOLO detection model and tested it on the bus image.

detector = YOLO("yolo11n.pt")

results = detector(IMAGE_PATH, conf=0.4, verbose=False)

annotated_image = results[0].plot()[:, :, ::-1]

plt.imshow(annotated_image)
plt.title("Object Detection")
plt.axis("off")
plt.show()
Enter fullscreen mode Exit fullscreen mode

The model detected one bus at 94% confidence and four people at confidence scores of 89%, 88%, 86%, and 62%.

This was more informative than classification because I could see the locations of the detected objects.

Testing different confidence thresholds

I changed the confidence threshold to see how the results changed.

Confidence threshold What I observed
0.1 (10%) The bus and people were detected, along with a skateboard at 12% confidence.
0.4 (40%) The model detected the bus and four people.
0.9 (90%) Only the bus at 94% confidence remained.

A lower threshold allows more possible detections, including predictions that may be incorrect. A higher threshold removes lower-confidence predictions but may also exclude real objects.

What I learned: The confidence threshold affects which predictions are kept. Choosing a threshold involves balancing the possibility of missing real objects against the possibility of accepting incorrect detections.

5. Image segmentation: Understanding object shapes

Image segmentation provides more detailed information about the pixels belonging to an object. Instead of drawing only a rectangle around a person or bus, a segmentation model produces a mask that follows the object's visible shape.

Ultralytics explains that instance segmentation extends detection by producing pixel-level masks for individual objects. This detail can be useful in applications such as agricultural analysis and medical imaging. Ultralytics YOLO tasks documentation

I used a pretrained YOLO segmentation model:

segmenter = YOLO("yolo11n-seg.pt")

results = segmenter(IMAGE_PATH, conf=0.4, verbose=False)

annotated_image = results[0].plot()[:, :, ::-1]

plt.imshow(annotated_image)
plt.title("Image Segmentation")
plt.axis("off")
plt.show()
Enter fullscreen mode Exit fullscreen mode

In my experiment, the notebook reported approximately 44% mask coverage for the bus image. It also produced masks for objects including the bus and several people.

The 44% value came from the mask calculation in my notebook. It should not be treated as an exact measurement of the real-world area occupied by the objects.

What I learned: Classification, detection, and segmentation solve different problems. Classification predicts what an image may contain, detection shows where objects are located, and segmentation provides more detail about their visible shapes. The right task depends on what information we need.
Computer vision experiment screenshot

6. Testing the models on my own photo

One of the most interesting parts of the experiment was testing the models on my own photo instead of only using the sample images.

At a confidence threshold of 0.4, the detection model returned six person boxes. However, some boxes overlapped, so six detections did not necessarily mean six different people.

The classification model also returned unexpected labels, including grocery_store and French_horn. This helped me compare the output of classification with the output of object detection and segmentation.

What I learned: Testing a model on new images is important because its predictions may differ from what we expect. I also learned that detection counts need to be interpreted carefully, especially when bounding boxes overlap.

7. How brightness and resolution affected detection

I wanted to understand whether changing image quality would affect the model's predictions. I therefore tested different brightness levels and image resolutions.

Brightness experiment

I tested brightness factors of 0.3, 0.7, 1.0, and 1.5. A factor of 1.0 represented the original brightness, while lower and higher factors made the image darker and brighter.

Brightness factor Person detections
0.3 4
0.7 6
1.0 6
1.5 5

The number of person detections changed when I adjusted the brightness. This showed that a change to the input image could affect the model's output.

Resolution experiment

I also resized my photo to different widths and ran the detection model again.

Image width Observed result
48 pixels 1 person detection
128 pixels 4 person detections
320 pixels 3 person detections, plus two unexpected pizza predictions
640 pixels 6 person detections

The smallest image contained much less visual detail, and the model detected fewer people. The unexpected predictions at 320 pixels also showed that a model can make incorrect predictions.

These results describe my experiment. They do not mean that every small or bright image will produce the same results.

What I learned: Image quality can influence computer vision predictions. Changes in brightness may make objects harder to recognize, while reducing resolution can remove useful details. Increasing resolution does not guarantee that every prediction will be correct.

Computer vision result 1 Computer vision result 2 Computer vision result 3

Result 1

person 90% box=(1096,857)-(1674,2446)
person 84% box=(153,976)-(706,2440)
person 64% box=(687,1290)-(1200,2445)
person 48% box=(654,996)-(1139,2442)
person 47% box=(1455,1073)-(1517,1171)
person 43% box=(2,1150)-(85,1359)

Result 2

person 91% box=(1104,857)-(1672,2446)
person 86% box=(152,981)-(703,2441)
person 58% box=(716,1454)-(1202,2446)
person 55% box=(677,1093)-(1195,2446)

Result 3

person 91% box=(1105,860)-(1675,2445)
person 82% box=(151,976)-(727,2441)
person 66% box=(655,999)-(1150,2442)
person 42% box=(1455,1075)-(1517,1172)
person 41% box=(0,1147)-(84,1360)

8. Testing model robustness

Model robustness refers to how well a model continues to perform when its input changes.

The notebook also included tests involving a very dark image, an image rotated upside down, a low-resolution image, and a blurred image. These conditions represent challenges that may occur when images are captured in real life.

My brightness and resolution experiments already showed that the number of detections could change when the input changed. I would need to compare the actual results from the rotation and blur tests before deciding which condition affected the model most.

What I learned: A model that performs well on one clear image may not perform equally well on every image. Testing different conditions helps us identify weaknesses and better understand the limits of a model.

9. My main lessons from the experiment

This practical session helped me connect computer vision concepts with actual code and model predictions. My main lessons were:

  1. Images contain numerical data. I learned how pixels and RGB channels represent colors.
  2. Filters change image information. Grayscale, blur, edge detection, and sharpening helped me understand basic image processing.
  3. Classification and detection are different. Classification predicts a label for an image, while detection identifies objects and their locations.
  4. Segmentation gives more detail. It produces masks that show the visible shapes of objects.
  5. Confidence scores need interpretation. A model can produce uncertain or incorrect predictions.
  6. Image quality matters. Changes in brightness and resolution affected the detections in my experiments.
  7. Testing is important. Examining the outputs helped me notice unexpected predictions and overlapping boxes rather than assuming that the model was always right.

The most valuable part for me was testing the models on my own photo and observing how their predictions changed. It made the concepts easier to understand because I could compare what I expected with what the models actually produced.

Conclusion

This experiment gave me a practical introduction to computer vision. I started by examining an image as numerical data, then applied filters and explored classification, object detection, and segmentation. Finally, I tested how changes in brightness and resolution affected the model's predictions.

I learned that computer vision involves more than identifying objects in a photograph. We also need to understand the task we are solving, examine the results, and test how a model behaves when the input changes.

As I continue learning artificial intelligence and machine learning, I want to build on this knowledge by exploring how computer vision can be applied to practical problems, including identifying plant diseases in agriculture.

Resources

1. Ultralytics — YOLO Tasks Documentation

https://docs.ultralytics.com/tasks/

2. Pillow — ImageEnhance Documentation

https://pillow.readthedocs.io/en/stable/reference/ImageEnhance.html

Top comments (2)

Collapse
 
abijuru_diane profile image
abijuru diana •

Great work! i can really see the effort you put into explaining computer vision, from understanding pixels to object detection. I like how you connected the basic concepts to more advanced applications, making the learning journey easier to follow. Keep exploring practical projects with Python and OpenCV, and continue building on this strong foundation. Your effort and curiosity will take you far! 👏🚀 keep learning,exploring.....

Collapse
 
celia__k profile image
Celia Kaligirwa •

Woooow this was amazing. This showed how much work you've put in learning this and it shows how interested you were in learning this. You've shown even your own demonstartions showing how much work you've put by applying what you learnt on your own image. You also mentioned resources that added information on your research which is truly amazing. Keep up the spirit because there is still more to learn and dive in.