Skip to main content
Computer Vision Tutorial
CHAPTER 03 Beginner

Image Processing Basics

Updated: May 14, 2026
15 min read

# CHAPTER 3

Image Processing Basics

1. Introduction

Cameras are not perfect. They capture blurry images when hands shake, grainy images in low light, and washed-out images facing the sun. If you feed a terrible image into an Artificial Intelligence model, the AI will make terrible predictions. Therefore, before we do Computer Vision (understanding the image), we must do Image Processing (cleaning the image). In this chapter, we will learn how to prepare raw images for machine analysis.

2. Learning Objectives

By the end of this chapter, you will be able to:
  • Define Image Processing and its role in the CV pipeline.
  • Understand the concept of Image Preprocessing.
  • Explain what Image Noise is and how to reduce it.
  • Understand Image Enhancement techniques like contrast adjustment.

3. Beginner-Friendly Explanation

Imagine you find an old, dusty, scratched photograph in your attic. You can barely make out the faces in the picture. You scan it into your computer and use Photoshop to adjust the brightness, smooth out the scratches, and sharpen the blurry edges until the faces are clear. Image Processing is doing exactly this, but using Python code to do it automatically to millions of images in a fraction of a second. We are "cleaning the window" so the AI algorithm can see clearly.

4. The Difference Between Image Processing and Computer Vision

  • Image Processing: Input is an Image -> Output is a *modified Image*. (e.g., Taking a dark photo and making it brighter).
  • Computer Vision: Input is an Image -> Output is *Information*. (e.g., Taking a photo and outputting the text "There is a Cat here").
Image processing is the crucial first step (Preprocessing) in any Computer Vision pipeline.

5. What is Image Preprocessing?

Preprocessing involves standardizing your data before feeding it to an AI. If you have 1,000 photos of cars, some might be 4K resolution, some might be tiny thumbnails, and some might be vertical smartphone shots. An AI model requires consistency. Preprocessing usually involves:
  1. 1. Resizing all images to the exact same dimensions (e.g., 224x224 pixels).
  1. 2. Converting them to Grayscale (if color isn't needed).
  1. 3. Normalizing pixel values (scaling 0-255 numbers down to 0.0-1.0 decimals for neural networks).

6. Dealing with "Noise"

In digital imaging, "Noise" refers to random, unwanted variations in brightness or color. It usually looks like ugly static or grain, especially in photos taken at night. To a human, noise is annoying. To an AI looking for exact pixel patterns, noise is catastrophic. We use mathematical filters (like a Gaussian Blur) to "smooth" the image. This averages out the harsh, random static pixels with their neighbors, creating a cleaner (though slightly softer) image.

7. Image Enhancement (Contrast)

Sometimes an image is too dark, or the background blends into the foreground. We use a technique called Histogram Equalization. This algorithm looks at the distribution of light and dark pixels and stretches them out, forcing the darks to be darker and the lights to be lighter. This drastically improves the contrast, making hidden objects suddenly "pop" out to the AI's edge-detection algorithms.

8. Python Example: The Preprocessing Pipeline

Using OpenCV, an image preprocessing pipeline takes just a few lines.
python
12345678910111213141516
import cv2

# 1. Load the raw, noisy, colored image
raw_image = cv2.imread("dark_noisy_car.jpg")

# 2. Convert to Grayscale (Reduces data by 3x)
gray = cv2.cvtColor(raw_image, cv2.COLOR_BGR2GRAY)

# 3. Resize the image to a standard 250x250 square
resized = cv2.resize(gray, (250, 250))

# 4. Enhance contrast using Histogram Equalization
enhanced = cv2.equalizeHist(resized)

# Save the cleaned image ready for the AI
cv2.imwrite("clean_car_ready_for_AI.jpg", enhanced)

9. Mini Project

Identify the Flaw: You are building an AI to read license plates on speeding cars at night. The raw camera footage is extremely dark and grainy. Which two Image Processing techniques must you apply to the footage before the AI attempts to read the letters? *(Answer: You need Noise Reduction to smooth out the nighttime grain/static, and Image Enhancement/Contrast Adjustment to brighten the dark plate so the letters become visible).*

10. Best Practices

  • Don't over-blur: While applying a blur filter removes noise, applying *too much* blur will destroy the sharp edges of the objects in your image, making it impossible for the AI to detect shapes. It is a delicate balance.

11. Common Mistakes

  • Skipping Resizing: Machine Learning models (especially CNNs) have a fixed input size. If you train a model on 500x500 images, and then feed it a 1080p image in the real world, the program will instantly crash. Always resize inputs dynamically!

12. Exercises

  1. 1. Explain the difference between Image Processing and Computer Vision in terms of inputs and outputs.

13. Coding Challenges

Challenge 1: Write pseudocode for an automated security camera script that takes a raw frame, converts it to grayscale, resizes it to 100x100, and passes it to an AI model.
text
123456789101112
Function process_security_camera():
    frame = capture_camera_frame()
    
    // Image Processing Pipeline
    gray_frame = convert_to_grayscale(frame)
    small_frame = resize_image(gray_frame, width=100, height=100)
    
    // Computer Vision
    alert = AI_Model.detect_intruder(small_frame)
    
    If alert == True:
        sound_alarm()

14. MCQs with Answers

Question 1

In the context of computer vision, what does "Image Preprocessing" usually involve?

Question 2

What is digital "Noise" in an image?

15. Interview Questions

  • Q: Why is standardizing image resolution a mandatory preprocessing step for deep learning models?
  • Q: Explain how Histogram Equalization improves an image for Computer Vision tasks.

16. FAQs

Q: Does compressing an image into a JPEG ruin it for AI? A: Heavy JPEG compression introduces "artifacts" (blocky pixelation). This is a form of noise. While modern AI is robust, heavily compressed images will absolutely degrade the accuracy of an object detection model. Raw, uncompressed data is always best.

17. Summary

In Chapter 3, we learned that AI is only as good as the data it looks at. Image Processing is the act of cleaning the window. By converting images to grayscale, resizing them to standard dimensions, reducing static noise, and enhancing contrast, we transform messy, real-world photos into pristine mathematical matrices that AI algorithms can easily digest.

18. Next Chapter Recommendation

Now that we know how to clean the image, how do we actually manipulate the individual numbers inside the matrix? Proceed to Chapter 4: Working with Pixels and Colors to get your hands dirty with matrix math.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·