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
2
Contents
• Resizing
• Normalization
• Histogram Equalization
• Edge Detection
• Cropping
• Image segmentation
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
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
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)
6
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
#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")
9
10
#2. local_contrast_normalization
def local_contrast_normalization(image):
local_mean = ndi.uniform_filter(image, size=7)
local_std = ndi.uniform_filter(image**2, size=7)**0.5
return (image - local_mean) / (local_std + 1e-5)
image_lcn = local_contrast_normalization(image_resized)
plt.imshow(image_lcn, cmap='gray')
plt.title("Local Contrast Normalization")
plt.axis("off")
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.
12
#Histogram equalization
image_equalized = exposure.equalize_hist(image_resized)
plt.imshow(image_equalized, cmap='gray')
plt.title("Histogram Equalization")
plt.axis("off")
13
Edge Detection
Description: Detects significant transitions in intensity (edges).
Purpose: Highlights the boundaries of objects in the image.
Tools: Canny Edge Detector, Sobel Operator.
14
#Edge Detection
# Load sample image
image = cv2.imread('/content/drive/MyDrive/sample
data/finger.png')
cv2_imshow(image)
# Resize image (optional, for uniform dimensions)
image_resized = cv2.resize(image, (224, 224))
# 1. Canny Edge Detection
edges_canny = cv2.Canny(image_resized,
threshold1=50, threshold2=150)
plt.imshow(edges_canny, cmap='gray')
plt.title("Canny Edge Detection")
plt.axis("off")
15
16
# 2. Sobel Edge Detection
sobel_x = cv2.Sobel(image_resized, cv2.CV_64F, 1,
0, ksize=3) # Horizontal edges
sobel_y = cv2.Sobel(image_resized, cv2.CV_64F, 0,
1, ksize=3) # Vertical edges
sobel_combined = cv2.magnitude(sobel_x, sobel_y) #
Combine both directions
plt.imshow(sobel_combined, cmap='gray')
plt.title("Sobel Combined")
plt.axis("off")
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.).
18
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
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.
21
#segmentation
#Thresholding-Based Segmentation
# Load sample image
# Load sample image
image = cv2.imread('/content/drive/MyDrive/sample data/humurus.png')
cv2_imshow(image)
image_resized = cv2.resize(image, (224, 224))
# Convert the image to grayscale before applying adaptive thresholding
image_gray = cv2.cvtColor(image_resized, cv2.COLOR_BGR2GRAY)
# Apply adaptive thresholding
adaptive_thresh = cv2.adaptiveThreshold(image_gray, 255,
cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
cv2.THRESH_BINARY, 11, 2)
plt.imshow(adaptive_thresh, cmap='gray')
plt.title("Thresholding-Based Segmentation")
plt.axis("off")
22

More Related Content

PPT
Image_Processing_LECTURE_c#_programming.ppt
ODP
Image Processing with OpenCV
PDF
PPTX
Image Augmentation Techniques and example
PPTX
Topic 1_PPT.pptx
PPTX
Image enhancement lecture
PPTX
Pertemuan2 - Computer Vision (Image Preprocessing)
PPTX
Digital image forgery detection
Image_Processing_LECTURE_c#_programming.ppt
Image Processing with OpenCV
Image Augmentation Techniques and example
Topic 1_PPT.pptx
Image enhancement lecture
Pertemuan2 - Computer Vision (Image Preprocessing)
Digital image forgery detection

Similar to Presentation-lokesh IMAGES for research.pptx (20)

PDF
Templateless Marked Element Recognition Using Computer Vision
PPTX
05 contours seg_matching
PPTX
OpenCV In Mobile Technology | Computer Vision on Mobile
PPTX
Image Enhancement Techniques using OpenCV – Python.pptx
PPTX
Image Enhancement Techniques using OpenCV – Python.pptx
PPT
Digital Image Processing
PPTX
AI Unit-5 Image Processing for all ML problems
PDF
F017614146
PDF
An Efficient Approach of Segmentation and Blind Deconvolution in Image Restor...
PDF
Labcamp - working with image processing
PPTX
ImageProcessingWithMatlab(HasithaEdiriweera)
PPT
Key stages of digital image processing.ppt
PDF
Final Report for project
PDF
PPTX
Introduction to OpenCV
PPTX
COLOUR DETECTION MODEL PPT.pptx.........
PPTX
Eugene Khvedchenya. State of the art Image Augmentations with Albumentations.
PPTX
Fundamentals Image and Graphics
PDF
Basics of image processing using MATLAB
DOCX
Computer graphics
Templateless Marked Element Recognition Using Computer Vision
05 contours seg_matching
OpenCV In Mobile Technology | Computer Vision on Mobile
Image Enhancement Techniques using OpenCV – Python.pptx
Image Enhancement Techniques using OpenCV – Python.pptx
Digital Image Processing
AI Unit-5 Image Processing for all ML problems
F017614146
An Efficient Approach of Segmentation and Blind Deconvolution in Image Restor...
Labcamp - working with image processing
ImageProcessingWithMatlab(HasithaEdiriweera)
Key stages of digital image processing.ppt
Final Report for project
Introduction to OpenCV
COLOUR DETECTION MODEL PPT.pptx.........
Eugene Khvedchenya. State of the art Image Augmentations with Albumentations.
Fundamentals Image and Graphics
Basics of image processing using MATLAB
Computer graphics
Ad

More from bhargavi804095 (20)

PPTX
Reinforcement learning ppt in machine learning.pptx
PPT
concept on arrays and pointers with examples arrays-pointers.ppt
PPT
Lec3-coa give sthe information abt instruction set.ppt
PDF
computerregisters during data and address communication.pdf
PPT
Computer forensics and cyber security powerpoint presentation
PPT
chapter1-basic-structure-of-computers.ppt
PPTX
Ch10_The_STACK_and_Subroutines_Slides.pptx
PDF
Pointers are one of the core components of the C programming language.
PPTX
Lec26.pptx An array is a linear data structure
DOCX
08-Pointers.docx An array is a linear data structure
PDF
The Greibach normal form is referred to as GNF gnf1.pdf
PPT
java1.pptjava is programming language, having core and advanced java
PDF
Big Data Analytics is not something which was just invented yesterday!
PPT
Apache Spark™ is a multi-language engine for executing data-S5.ppt
PPTX
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
PPT
A File is a collection of data stored in the secondary memory. So far data wa...
PPTX
C++ helps you to format the I/O operations like determining the number of dig...
PPT
While writing program in any language, you need to use various variables to s...
PPT
Python is a high-level, general-purpose programming language. Its design phil...
PPT
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
Reinforcement learning ppt in machine learning.pptx
concept on arrays and pointers with examples arrays-pointers.ppt
Lec3-coa give sthe information abt instruction set.ppt
computerregisters during data and address communication.pdf
Computer forensics and cyber security powerpoint presentation
chapter1-basic-structure-of-computers.ppt
Ch10_The_STACK_and_Subroutines_Slides.pptx
Pointers are one of the core components of the C programming language.
Lec26.pptx An array is a linear data structure
08-Pointers.docx An array is a linear data structure
The Greibach normal form is referred to as GNF gnf1.pdf
java1.pptjava is programming language, having core and advanced java
Big Data Analytics is not something which was just invented yesterday!
Apache Spark™ is a multi-language engine for executing data-S5.ppt
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
A File is a collection of data stored in the secondary memory. So far data wa...
C++ helps you to format the I/O operations like determining the number of dig...
While writing program in any language, you need to use various variables to s...
Python is a high-level, general-purpose programming language. Its design phil...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
Ad

Recently uploaded (20)

PDF
Module 1 part 1.pdf engineering notes s7
DOCX
An investigation of the use of recycled crumb rubber as a partial replacement...
PPTX
MODULE 02 - CLOUD COMPUTING-Virtual Machines and Virtualization of Clusters a...
PPTX
quantum theory on the next future in.pptx
PDF
ASPEN PLUS USER GUIDE - PROCESS SIMULATIONS
PPTX
Unit IILATHEACCESSORSANDATTACHMENTS.pptx
PPTX
1. Effective HSEW Induction Training - EMCO 2024, O&M.pptx
PDF
25AF1191PC303 MODULE-1 CHAIN SURVEYING SEMESTER III SURVEYING
PPTX
Soft Skills Unit 2 Listening Speaking Reading Writing.pptx
PDF
Artificial Intelligence_ Basics .Artificial Intelligence_ Basics .
PDF
IAE-V2500 Engine for Airbus Family 319/320
PPTX
INTERNET OF THINGS - EMBEDDED SYSTEMS AND INTERNET OF THINGS
PPTX
SE unit 1.pptx by d.y.p.akurdi aaaaaaaaaaaa
PPTX
Design ,Art Across Digital Realities and eXtended Reality
PDF
Introduction to Machine Learning -Basic concepts,Models and Description
PPT
Comprehensive Java Training Deck - Advanced topics
PPTX
Software-Development-Life-Cycle-SDLC.pptx
PPTX
Solar energy pdf of gitam songa hemant k
PDF
B461227.pdf American Journal of Multidisciplinary Research and Review
PPTX
SC Robotics Team Safety Training Presentation
Module 1 part 1.pdf engineering notes s7
An investigation of the use of recycled crumb rubber as a partial replacement...
MODULE 02 - CLOUD COMPUTING-Virtual Machines and Virtualization of Clusters a...
quantum theory on the next future in.pptx
ASPEN PLUS USER GUIDE - PROCESS SIMULATIONS
Unit IILATHEACCESSORSANDATTACHMENTS.pptx
1. Effective HSEW Induction Training - EMCO 2024, O&M.pptx
25AF1191PC303 MODULE-1 CHAIN SURVEYING SEMESTER III SURVEYING
Soft Skills Unit 2 Listening Speaking Reading Writing.pptx
Artificial Intelligence_ Basics .Artificial Intelligence_ Basics .
IAE-V2500 Engine for Airbus Family 319/320
INTERNET OF THINGS - EMBEDDED SYSTEMS AND INTERNET OF THINGS
SE unit 1.pptx by d.y.p.akurdi aaaaaaaaaaaa
Design ,Art Across Digital Realities and eXtended Reality
Introduction to Machine Learning -Basic concepts,Models and Description
Comprehensive Java Training Deck - Advanced topics
Software-Development-Life-Cycle-SDLC.pptx
Solar energy pdf of gitam songa hemant k
B461227.pdf American Journal of Multidisciplinary Research and Review
SC Robotics Team Safety Training Presentation

Presentation-lokesh IMAGES for research.pptx

  • 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
  • 2. 2 Contents • Resizing • Normalization • Histogram Equalization • Edge Detection • Cropping • Image segmentation
  • 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)
  • 6. 6
  • 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")
  • 9. 9
  • 10. 10 #2. local_contrast_normalization def local_contrast_normalization(image): local_mean = ndi.uniform_filter(image, size=7) local_std = ndi.uniform_filter(image**2, size=7)**0.5 return (image - local_mean) / (local_std + 1e-5) image_lcn = local_contrast_normalization(image_resized) plt.imshow(image_lcn, cmap='gray') plt.title("Local Contrast Normalization") 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.
  • 12. 12 #Histogram equalization image_equalized = exposure.equalize_hist(image_resized) plt.imshow(image_equalized, cmap='gray') plt.title("Histogram Equalization") plt.axis("off")
  • 13. 13 Edge Detection Description: Detects significant transitions in intensity (edges). Purpose: Highlights the boundaries of objects in the image. Tools: Canny Edge Detector, Sobel Operator.
  • 14. 14 #Edge Detection # Load sample image image = cv2.imread('/content/drive/MyDrive/sample data/finger.png') cv2_imshow(image) # Resize image (optional, for uniform dimensions) image_resized = cv2.resize(image, (224, 224)) # 1. Canny Edge Detection edges_canny = cv2.Canny(image_resized, threshold1=50, threshold2=150) plt.imshow(edges_canny, cmap='gray') plt.title("Canny Edge Detection") plt.axis("off")
  • 15. 15
  • 16. 16 # 2. Sobel Edge Detection sobel_x = cv2.Sobel(image_resized, cv2.CV_64F, 1, 0, ksize=3) # Horizontal edges sobel_y = cv2.Sobel(image_resized, cv2.CV_64F, 0, 1, ksize=3) # Vertical edges sobel_combined = cv2.magnitude(sobel_x, sobel_y) # Combine both directions plt.imshow(sobel_combined, cmap='gray') plt.title("Sobel Combined") plt.axis("off")
  • 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.).
  • 18. 18
  • 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.
  • 21. 21 #segmentation #Thresholding-Based Segmentation # Load sample image # Load sample image image = cv2.imread('/content/drive/MyDrive/sample data/humurus.png') cv2_imshow(image) image_resized = cv2.resize(image, (224, 224)) # Convert the image to grayscale before applying adaptive thresholding image_gray = cv2.cvtColor(image_resized, cv2.COLOR_BGR2GRAY) # Apply adaptive thresholding adaptive_thresh = cv2.adaptiveThreshold(image_gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 2) plt.imshow(adaptive_thresh, cmap='gray') plt.title("Thresholding-Based Segmentation") plt.axis("off")
  • 22. 22