1. Advanced Techniques in Image Preprocessing and Enhancement: From
Traditional Methods to Deep Learning Approaches
DAC Seminar-02
DAC MEMEBERS K. Lokesh Reddy
Dr. Rohini[CSE DEPT] 23STRCHH010006
Dr. L. Laxmi[DSAI DEPT] Research Scholar
Dr. P. Pavan Kumar[DSAI DEPT] CSE DEPT
1
3. 3
Introduction
Image preprocessing and enhancement play a crucial role in preparing images for
various applications by improving their quality and extracting key features. This involves
fundamental techniques like resizing, cropping, and normalization, which adjust dimensions,
remove unwanted regions, and ensure consistency in pixel values. Enhancements such as
contrast and brightness adjustments, along with gamma correction, improve visibility, while
noise reduction methods like Gaussian blur, median filtering, and bilateral filtering preserve
important details.
Advanced techniques include sharpening, edge detection, and histogram equalization
to refine image features. Additionally, modern deep learning approaches, including
Convolutional Neural Networks (CNNs), Generative Adversarial Networks (GANs), Vision
Transformers, and autoencoders, are explored for tasks like super-resolution, denoising, and
artifact removal. The integration of traditional image processing with cutting-edge deep
learning techniques enhances image quality, benefitting fields like medical imaging,
photography, and machine learning.
4. 4
Common Preprocessing Techniques for Optimal Image Enhancement
1. Resizing in Deep Learning
Definition: Resizing refers to changing the dimensions of data inputs (images, signals, or others) to meet the size
requirements of a deep learning model.
Add a visually appealing image, such as a pipeline diagram showing preprocessing steps.
Include your name, organization, or event details (if applicable).
Neural networks require uniform input dimensions for matrix operations.
Helps align input data with pre-trained model architectures.
Example: Input images must be resized to 224x224 for ResNet.
Resizing Methods: Libraries and Tools:
Popular Libraries:
OpenCV (cv2.resize): Efficient for large datasets.
PIL/ Pillow: Intuitive and supports many formats.
TensorFlow/Keras (tf.image.resize): Tensor-compatible.
PyTorch (torchvision.transforms.Resize): Integrates well with Data Loader.
5. 5
from google.colab import drive
drive.mount('/content/drive')
#resize
import cv2
from google.colab.patches import cv2_imshow
# Load the image
image = cv2.imread('/content/drive/MyDrive/sample
data/hand.png')
cv2_imshow(image)
# Resizing without maintaining aspect ratio
resized = cv2.resize(image, (200, 200))
# Resizing while maintaining aspect ratio
(h, w) = image.shape[:2]
aspect_ratio = w / h
new_width = 300
new_height = int(new_width / aspect_ratio)
resized_aspect = cv2.resize(image, (new_width,
new_height))
# Display
cv2_imshow(resized)
cv2_imshow(resized_aspect)
7. 7
2. Normalization
Ensures consistency, especially important in machine learning where models require normalized data for better
learning performance.
Adjusts the pixel values to a common scale, often in the range [0, 1] or [-1, 1].
Deep learning models, especially convolutional neural networks (CNNs), rely on numerical data (images, in this case) for
training. Since the raw pixel values in an image can range from 0 to 255 (in 8-bit color channels), these values might not be
ideal for neural networks
8. 8
#normalization
import numpy as np
import scipy.ndimage as ndi
from skimage import exposure
import matplotlib.pyplot as plt
# Load sample image
image = cv2.imread('/content/drive/MyDrive/sample
data/forearm.png')
cv2_imshow(image)
# Resize image (optional, to ensure uniform
dimensions)
image_resized = cv2.resize(image, (224, 224))
# 1. Pixel Value Scaling (to [0, 1])
image_scaled = image_resized / 255.0
plt.imshow(image_scaled, cmap='gray')
plt.title("Pixel Value Scaling [0, 1]")
plt.axis("off")
11. 11
Histogram Equalization
Description: This technique improves the contrast of an image
by spreading out the most frequent intensity values.
Purpose: Enhances contrast, especially in images that are too
bright or too dark.
Histogram Equalization is a technique used to improve the
contrast of an image by stretching the intensity values of pixels
so that the histogram of the image is more evenly distributed
across the entire range of pixel values. The primary goal is to
enhance the global contrast of an image, especially when the
image’s contrast is poor due to lighting or other issues.
17. 17
#cropping
# Load sample image
image = cv2.imread('/content/drive/MyDrive/sample data/humurus.png')
cv2_imshow(image)
image_resized = cv2.resize(image, (224, 224))
# Define manual ROI (example: crop to center region)
x, y, width, height = 50, 50, 150, 150 # Replace with desired coordinates
image_cropped = image[y:y+height, x:x+width]
plt.imshow(image_cropped, cmap='gray')
plt.title("Manually Cropped Image")
plt.axis("off")
Cropping
Description: Removes unwanted areas from the image.
Purpose: Focuses on the most important region and eliminates distracting parts.
Image cropping refers to extracting a portion of the image by defining a Region of Interest (ROI).
This is typically done to focus on a particular area of an image that contains important features or
objects. Cropping can be performed manually by specifying the coordinates of the rectangle you
want to extract or automatically based on some algorithm.
Tools: Most image editing software (Photoshop, GIMP, etc.).
19. 19
#Automatic Cropping (Bounding Box Detection)
# Perform edge detection
edges = cv2.Canny(image_resized, threshold1=50, threshold2=150)
# Find contours from the edges
contours, _ = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
# Find the bounding box of the largest contour
if contours:
largest_contour = max(contours, key=cv2.contourArea)
x, y, w, h = cv2.boundingRect(largest_contour)
cropped_image = image_resized[y:y+h, x:x+w]
else:
cropped_image = image_resized # Fallback to the original if no contours are
found
plt.imshow(cropped_image, cmap='gray')
plt.title("Automatically Cropped Image")
plt.axis("off")
20. 20
Image segmentation
is a key technique in image preprocessing, where the goal is to
partition an image into multiple segments (regions) to make it
more meaningful and easier to analyze. These segments, or
regions, typically represent different structures or objects in the
image, and segmentation helps isolate them from the
background or other irrelevant parts of the image.
Thresholding-based Segmentation:
This method divides the image into different regions based on
pixel intensity levels. The simplest form is binary segmentation,
where the image is divided into two regions: foreground and
background.
•Global Thresholding: A single threshold value is used to
classify all pixels as either foreground or background.
•Adaptive Thresholding: The threshold value changes
based on the local neighborhood of each pixel.