Preprocessing for
CNN Models
Session No.:27
Course Name: Deep Learning
Course Code: R1UC526B
Instructor Name: Ms. Garima Verma
Galgotias University 1
Reflect on the
responses of
post session
activity
Galgotias University 2
Key concepts of Lecture 26
Data Augmentation Techniques
• Rotation and Flipping
• Scaling and Zooming
• Random Cropping and Padding
• Shearing and Perspective Transform
Opening Question
“What preprocessing steps do you think are necessary before an
image can be understood by a CNN?”
Galgotias University 4
At the end of this session students will be able to
Learning Outcome 1:
Explain various preprocessing steps in
CNN.
Learning Outcome 2:
Illustrate the advantages and disadvantages
of using preprocessing techniques in CNN.
Galgotias University 5
1 Introduction to Preprocessing
2 Why is preprocessing necessary?
3 Steps of Preprocessing in CNN
4 Example of Preprocessing
Session 5 Activity 1 (Think-Pair-Share)
Outline 6 Advantages and disadvantages of
Preprocessing
7 Activity 2 (Quiz)
8 Conclusion
9 Post session activity
Galgotias University 6
Concept and
Definition for
Learning Activity
1
GSCALE full form and date 7
Introduction to Preprocessing
• Preprocessing is a crucial step before feeding images
into CNNs.
• • It improves model performance, reduces noise, and
ensures uniformity.
• • Helps the model learn better representations.
Galgotias University 8
Introduction to Preprocessing in CNN
• Preprocessing plays a vital role in preparing image data
for Convolutional Neural Networks (CNNs).
It ensures that the data fed into the model is clean,
standardized, and suitable for learning important features
effectively.
CNNs are highly sensitive to input variations, and
preprocessing helps achieve consistency and better
convergence during training.
Galgotias University 9
Introduction to Image
Preprocessing :
• Image preprocessing refers to the set of techniques
applied to raw image data before feeding it into a CNN
model.
These techniques help improve model accuracy, reduce
noise, and enhance feature extraction.
CNNs expect data in a specific format (e.g., fixed image
size, normalized pixel values).
Galgotias University 10
Various steps in Data Preprocessing
Galgotias University 11
Why Preprocessing is Needed
• Raw images vary in size, color scale, and brightness.
• CNNs require consistent input dimensions.
• Preprocessing improves convergence speed and
accuracy.
• Reduces overfitting and improves generalization.
Galgotias University 12
Common Image Preprocessing Steps
:
• The most common preprocessing operations include:
• Image Resizing
• Normalization
• Data Augmentation
• Grayscale Conversion (optional)
• Noise Removal and Filtering
• Image Centering and Cropping
Galgotias University 13
Image Resizing
CNNs require fixed-size inputs.
Common sizes: 224×224, 256×256, 128×128, 32×32.
Why resize?
•CNN architectures expect fixed-size tensors
•Reduces computation cost
•Maintains uniform structure across dataset
Galgotias University 14
Normalization
• Normalization scales pixel values to a specific range
(commonly [0,1] or [-1,1]) to improve numerical stability
during training.
Common methods:
•Min-Max Scaling:
→ values in [0,1]
•Range Scaling:
To [-1,1]
Benefits:
•Speeds up training
•Prevents exploding/vanishing gradients
•Improves convergence
Galgotias University 15
Data Augmentation
Data augmentation increases the diversity of the dataset artificially by applying
transformations such as rotation, flipping, zooming, or shifting.
It helps prevent overfitting and improves generalization.
• Techniques:
• Rotation
• Horizontal/vertical flip
• Zoom
• Random crop
• Translation
• Shear
• Brightness variation
• Cutout or Random Erasing
• Benefits:
• Prevents overfitting
• Increases generalization
• Makes CNN robust to real-world variations
Galgotias University 16
Grayscale Conversion
Converting RGB images to grayscale is beneficial when
color is not an essential feature (e.g., edge detection or
shape-based tasks).
Galgotias University 17
Image Centering and Cropping
Centering aligns the main object in the image, while
cropping removes irrelevant background portions to focus
on the region of interest.
Types:
•Center crop
•Random crop
Purpose:
•Removes unnecessary background
•Helps CNN learn localized features
•Used in augmentations to improve
robustness
Galgotias University 18
Noise Reduction
Noise can affect CNN performance. Filters like Gaussian blur, median filters, or bilateral
filters help reduce noise.
Techniques:
•Gaussian blur
•Median filter
•Bilateral filter
Why?
•Enhances signal-to-noise ratio
•Helps CNN focus on edges and key features
Galgotias University 19
Preprocessing Functions in Keras
• Keras provides utilities for preprocessing image data
efficiently.
Common functions include:
• [Link].load_img()
• [Link].img_to_array()
• [Link].vgg16.preprocess_input()
Galgotias University 20
Using Preprocessing Functions for
CNN Models
• Each pre-trained CNN model has its own specific
preprocessing function.
For example:
• VGG16: [Link].vgg16.preprocess_input()
• ResNet50:
[Link].resnet50.preprocess_input()
Galgotias University 21
Feature Scaling
• Feature scaling ensures that pixel values contribute
equally during learning.
It prevents bias toward features with large numerical
values.
Galgotias University 22
Importance of Standardization
• Standardization ensures consistent data distribution,
leading to faster convergence and stable model
training.
• Why use standardization?
• Reduces effect of lighting variations
• Creates uniform intensity distribution
• Works well for pretrained models like VGG, ResNet
Galgotias University 23
Effect of Preprocessing on Model
Performance
Proper preprocessing improves accuracy, reduces
overfitting, and stabilizes training.
Neglecting preprocessing can lead to poor generalization
and unstable gradients.
Galgotias University 24
Preprocessing Pipeline Example
• A typical CNN preprocessing workflow:
• Read image
• Resize (224×224)
• Convert color space (optional)
• Normalize/standardize
• Augment (only for training)
• Convert to batches
• Feed into the CNN model
Galgotias University 25
Learning Activity 1 Wooclap
activity(Think-pair-share)
• If a dataset contains images
captured in different lighting
conditions, which
preprocessing techniques
should be applied, and how
will they help?
Galgotias University 26
Reflection-
Learning
Activity 1
Galgotias University 27
Concept and
Definition for
Learning Activity
2
Galgotias University 28
Advantages of Preprocessing in CNN
• 1. Improves Model Accuracy
• Preprocessing reduces noise and standardizes inputs, helping the CNN
learn clearer patterns.
• 2. Faster and More Stable Training
• Normalized and standardized images prevent exploding/vanishing
gradients, enabling smoother convergence.
• 3. Reduces Overfitting
• Data augmentation (flip, rotation, zoom) increases dataset diversity
and improves generalization.
• 4. Ensures Consistent Input Size
• Resizing and cropping make all images uniform, matching the model’s
input dimensions.
Galgotias University 29
Cont…
• 5. Removes Irrelevant Information
• Noise removal, denoising, and background removal help the CNN
focus on essential features.
• 6. Handles Lighting and Contrast Variations
• Standardization, CLAHE, and normalization make the dataset
consistent across lighting conditions.
• 7. Enhances Feature Visibility
• Techniques like histogram equalization improve edge and contrast
features.
• 8. Efficient Memory and Computation
• Downsampling or resizing reduces GPU memory usage and speeds up
training.
Galgotias University 30
Disadvantages of Preprocessing in
CNN
• 1. Loss of Important Information
• Resizing, cropping, or denoising may remove fine details that are
crucial for accurate prediction.
• 2. Overprocessing May Harm Performance
• Too much augmentation or filtering can distort the image and confuse
the CNN.
• 3. Additional Computation Time
• Preprocessing large datasets (especially augmentation) requires extra
time and resources.
• 4. Incorrect Preprocessing Reduces Accuracy
• Using the wrong normalization for pretrained models (like
VGG/ResNet) can drastically drop accuracy.
Galgotias University 31
Cont…
• 5. Increased Complexity in Pipeline
• Managing many preprocessing steps (resize → normalize
→ augment → batch) can make the workflow complex.
• 6. Risk of Introducing Bias
• If augmentation or cropping is applied unevenly, the
model may learn biased features.
• 7. Not Always Necessary
• For high-quality, uniform datasets (e.g., MNIST), heavy
preprocessing may be unnecessary and wasteful.
Galgotias University 32
Conclusion
• Preprocessing is a crucial stage that:
• Improves consistency
• Enhances training stability
• Handles noise and variations
• Boosts CNN accuracy
• Prevents overfitting
• Supports efficient training
• A well-designed preprocessing pipeline is key to
successful CNN performance.
Galgotias University 33
Code for Image preprocessing
from [Link] import ImageDataGenerator, load_img,
img_to_array
import [Link] as plt
# Load image
img = load_img("[Link]", target_size=(224, 224))
img_array = img_to_array(img)
# 1. Normalization
img_norm = img_array / 255.0
# 2. Data Augmentation Setup
datagen = ImageDataGenerator(
rotation_range=20,
width_shift_range=0.1,
height_shift_range=0.1,
zoom_range=0.2,
horizontal_flip=True
)
Galgotias University 34
Cont…
# Generate one augmented image
img_aug = datagen.random_transform(img_array)
# Plot original, normalized, and augmented image
[Link](figsize=(10, 4))
[Link](1, 3, 1)
[Link]("Original")
[Link](img_array.astype('uint8'))
[Link]("off")
[Link](1, 3, 2)
[Link]("Normalized")
[Link](img_norm)
[Link]("off")
[Link](1, 3, 3)
[Link]("Augmented")
[Link](img_aug.astype('uint8'))
[Link]("off")
[Link]()
Galgotias University 35
Learning Activity 2:
(Quiz on Wooclap)
Galgotias University 36
Reflection-Learning Activity 2
Galgotias University 37
At the
Ensure end
LOs: At theof
end this session
of this session, students
students will be able will be able to
Learning Outcome 1:
Explain various preprocessing steps in
CNN.
Learning Outcome 2:
Illustrate the advantages and disadvantages
of using preprocessing techniques in CNN.
Galgotias University 38
Summary
•Preprocessing prepares raw images before inputting them into CNN models.
•It ensures all images have uniform size, typically using resizing.
•Normalization/standardization scales pixel values for stable and faster training.
•Data augmentation (flip, rotate, zoom, shift) increases dataset size and reduces overfitting.
•Noise removal techniques like Gaussian blur help clean images and highlight important features.
•Cropping removes irrelevant background and enhances focus on key regions.
•Color space conversion (RGB → grayscale/HSV) is used when color details are unnecessary.
•Preprocessing improves CNN accuracy, consistency, and generalization.
•It reduces training time by simplifying and standardizing the input data.
•Incorrect or excessive preprocessing can distort images and reduce model performance.
Galgotias University 39
Post session activities
Galgotias University 40
Information to next topic of
the course
session no. 28
Applications: Image Classification
Galgotias University 41
Review and Reflection
from students
Galgotias University 42