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").
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. Resizing all images to the exact same dimensions (e.g., 224x224 pixels).
- 2. Converting them to Grayscale (if color isn't needed).
- 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
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. 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
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.