Digital Image Processing
Digital Image Processing
1. Eye cannot distinguish more than about 2 dozen gray levels in an image.
2. where each gray scale (generally at least 256 levels for most displays) mapped to a color level
through a LUT.
3. The eye is extremely sensitive to color and can distinguish thousands of color values in a picture.
4. CLUT(Color lookup table)::
A mapping of a pixel value to a color value shown on a display device.
in a grayscale image with levels 0, 1, 2, 3, and 4, pseudo-coloring is a color lookup table that
maps 0 to black, 1 to red, 2 to green, 3 to blue, and 4 to white.
5. Intensity Slicing:-
The technique of intensity slicing or density slicing or color coding is one of the simplest
example of Pseudo-color image processing
6.
7.
8. g(x,y)=T[f(x,y)]
9. The pixel values here are triplets or quartets (i.e group of 3 or 4 values)
10. Si=Ti(r1,r2,…,rn) i=1,2,3,….n
11. ri and Si are variables denoting the color components of f(x,y)
12. and g(x,y) at any point (x,y).
13. n transformations combine to produce a single transformation T
14. If RGB color space is selected then n=3 & r1,r2,r3 denotes the red, blue and green components of the
image.
15. If CMYK color space is selected then n=4 & r1,r2,r3,r4 denotes the cyan, hue, magenta and black
components of the image.
16. Suppose we want to modify the intensity of the given image
using g(x,y)=k*f(x,y) where 0<k<1
17. HSI color space this can be done with the simple transformation
s3=k*r3
where s1=r1 and s2=r2
Only intensity component r3 is modified.
In RGB color space 3 components must be transformed:
si=k*ri i=1,2,3.
In CMY color space 3 components must be transformed:
Color Correction:-
When adjusting the color components of an image it is important to realize that every
action affects the overall color balance of the image
(Perception of one color is affected by its surrounding colors)
Based on the color wheel,
theproportion of any color can be increased by decreasing the amount
of the opposite color in the image
increase by raising the proportion of two immediately
Similarly it can
adjacent colors or decreasing the percentage of the two colors adjacent to
the complement
Suppose for example there is an abundance of magenta in an RGB image, it can decreased by
Image Compression:
Compression is the process of reducing or eliminating redundant and/or irrelevant
information
A compressed image is not directly displayable it must be decompressed before input
to a color monitor.
In case if in a compressed image 1 bit of data represents 230 bits of data in the
original image, then compressed image could be transmitted over internet in 1
minute as compared to original image which will take 4 hours to transmit.
FINAL TERM
1. Introduction to Color Image Processing
Color Image Processing involves manipulating color images to enhance details or extract
useful information.
Pseudo-color Processing (False Color):
Adds colors to grayscale images to highlight differences.
The human eye can see thousands of colors but struggles with subtle( )نرم رنگتیںshades of
gray, so this method helps clarify details.
This technique improves visualization by replacing shades of gray with distinct colors.
3. Intensity Slicing
Divides grayscale intensity levels (e.g., black to white) into smaller sections and assigns
each section a specific color.
5. Color Transformations
Transformation Formula:
Adjust input image colors to create an output image using mathematical rules.
The number of components
(e.g., RGB = 3, CMYK = 4) determines the
transformations applied.
6. Color Complements
Complementary colors (e.g., red and green) are opposite on the color wheel.
Adjusting complements helps balance the overall color in an image.
7. Color Slicing
Highlights specific color ranges while suppressing/ignoring others.
Useful for distinguishing objects from the background in an image.
8. Color Correction:
Fixes color imbalances using:
o Increasing complementary colors to decrease a dominant one.
o Adjusting adjacent colors on the color wheel.
9. Histogram Processing
Adjusts brightness or contrast without changing the image's hue (color) or
saturation (vividness).
HSI (Hue, Saturation, Intensity) is ideal for such tasks.
10. Color Image Smoothing:
Similar to grayscale smoothing but applied to RGB or other color
components.
Uses neighborhood averaging to reduce noise and create a smoother image.
Lecture 10
What is Image Segmentation?
Definition:
Image segmentation splits an image into smaller parts or regions, called segments.
This helps analyze specific parts of the image better.
Purpose:
It's the first step in automated computer vision tasks and helps identify
objects within an image.
Applications:
o Detecting objects more precisely (e.g., cancer cells in medical
imaging).
o Understanding shapes and features of objects in detail.
o Used in traffic systems, self-driving cars, and satellite imaging.
Object Detection vs. Image Segmentation
Object Detection:
Segmentation Approaches
1. Discontinuity-Based:
2. Similarity-Based:
Groups pixels that are similar in color, texture, or other
properties.
Types of Segmentation
1. Local Segmentation:
sharply.
o Uses algorithms like Sobel, Canny, and Prewitt to detect edges.
2. Region-Based:
o Groups regions based on similar pixel values.
o Uses thresholds to classify areas.
3. Clustering:
o Groups pixels into clusters(Bunch) using techniques like K-means.
4. Texture-Based:
o Groups regions with similar texture patterns.
5. Color-Based:
o Groups pixels with similar colors.
Rugged:
Complex but can identify individual objects in detail.
Edge Detection
Region Growing
Starts with initial points (seeds) and grows regions based on
similarity.
Applications:
Finding tumors in medical images or locating targets in satellite images.
Discontinuity Detection
Identifies points, lines, or edges where there are sudden changes in
pixel intensity.
Point Detection:
SURF:
2.Feature Matching:
o Match similar features between images using techniques like:
Euclidean Distance:
Measures how far two features are.
Cross-Correlation:
3. Transformation Estimation:
o Use matched features to calculate how one image needs to be moved or
reshaped to align with the other.
Types of transformations:
Rigid:
Affine:
Projective:
For images taken from different angles.
Non-rigid:
Drawback:
Slow and computationally heavy.
Drawback:
Can be slow and often requires manual intervention.
Drawback:
Drawback:
Requires interpolation, which can reduce accuracy.
6. Genetic Algorithms:
o Inspired by
evolution, this method iteratively finds the best alignment
using a population of solutions.
object recognition,
motion tracking,
creating panoramas, or
Reconstructing 3D models.
4. Robotics
o Helps robots
map their surroundings by combining data from
multiple sensors.
Slides Content
Image Segementation:
1. It is an important starting step in most of the scene analysis problems and automatic pictorial pattern
recognition.
2. Object Detection: But it tells us nothing about the shape of the object. We only get the set of bounding
box coordinates.
3. Image Segementation :This technique gives us a far more granular understanding of the object(s) in the
image.
4. There are many other applications where Image segmentation is transforming industries:
Traffic Control Systems
Self Driving Cars
Locating objects in satellite images
There are even more applications where Image Segmentation is very useful.
5. Global segmentation concerned with dividing the whole image. So, it consists of large number of pixels
as compared to local segmentation.
6. semantic segmentation:
Every pixel belongs to a particular class .All the pixels belonging to a particular class are represented by the same
color (background as black and person as pink).
7. instance segmentation:
has also assigned a particular class to each pixel of the image. However, different
objects of the same class have different colors (Person 1 as red, Person 2 as green,
background as black, etc.).
8. In this case, we use threshold value and set a specific threshold value.
Then pixel value classified according to that threshold value i.e. values below and above the threshold level.
This is called Threshold Segmentation.
9. Region growing is a simple region-based image segmentation method.
10. In Global threshold, we define a single threshold value and divide image into two
regions (object and background).
11. In Local threshold, we define a multiple threshold values and divide image according to that
multiple values into multiple regions.
12. This is used when image contains multiple objects along with the background.
13. Different regions are grouped on basis of similarities. These groups are called clusters.
14. Texture based Segemntation Then through applying Mean-Shift clustering.
15. similar texture patterns judging by the pair-wise region comparison operations.
16. Color Based Segmentation each cluster defines a class of pixels that share similar color properties.
17. Image features yield two different types of problem:
The detection of area of interest in the image, typically contours, and the
description of local regions in the image,
typically for matching in different images.
18.Image Segmentation:
Detection of discontinuities:
Image registration
• SIFT (Scale-Invariant Feature Transform)
• SURF (Speeded-Up Robust Features)
• ORB (Oriented FAST and Rotated BRIEF)
• Harris Corner Detector
• FAST (Features from Accelerated Segment Test)
Boundary Description
In digital image processing, boundary description refers
to the representation and characterization
of the edges or contours( )حلیہof an object in an
image.
It is a key step in object recognition, shape
analysis, and image segmentation.
Chain Codes:
• Chain codes are a way to represent the boundary of a shape or
an object using a sequence of numbers.
• Each number in the sequence represents a direction or a
movement along the boundary.
• Chain codes are used to describe the boundary of a shape or an object
in a compact and efficient way.
Working
Here's how it works:
Boundary Tracing:
The boundary of the shape
or object is traced, and the direction of
movement at each point is recorded.
Chain Code Generation:
The recorded directions are converted into a sequence of
numbers, which represents the chain code.
Boundary Representation:
The chain code is used to represent the boundary of the shape or object.
Polygon approximation:
Douglas-Peucker Algorithm:
This algorithm is a popular method for polygon approximation.
Fourier Descriptors:
Uses Fourier transform to represent the boundary in the frequency
domain, useful for shape analysis.
Shape Signatures:
Represents the boundary
as a 1D function, such as the radial
distance from a centroid.
Why is it Important ?
Object Recognition:
Computers can identify objects by their
shapes.
Image Segmentation:
Dividing an image into meaningful
parts.
Shape Analysis:
Comparing and classifying shapes.
Image Retrieval:
Finding similar images based on
shape.
APPLICATIONS:
• Identifying object shapes in an image.
• Analyzing geometric properties like area, perimeter,
or compactness.
• Feature extraction for machine learning and
computer vision tasks.
BOUNDARY REPRESENTATION:
1. Captures the shape of an object by tracing its edges or
contours.
2. Typically done using boundary pixels or coordinates.
3. Captures the shape of an object by tracing its edges or
contours.
4. Typically done using boundary pixels or coordinates.
• Noise reduction
• Object segmentation
• Boundary detection
• Feature extraction
• Shape analysis
Erosion
Shrinks the boundaries of objects, removing small details and
thinning them.
Opening:
Combines erosion( )کٹاؤfollowed by dilation, effectively
smoothing the object boundaries and removing small objects.
Closing:
Combines dilation followed by erosion, filling in holes and
gaps in objects, and smoothing rough edges.
Opening
Opening smooths object boundaries and removes small
objects.
It is used to remove noise and isolate individual objects.
• Definition:
Erosion followed by dilation.
• • Effect:
Removes small objects/noise.
• • Use Case:
Noise removal in binary images.
• • Visual Example.
Closing:-
Closing fills in holes and gaps in objects, smoothing out their
boundaries. It is used to fill in holes and connect broken objects.
• • Definition:
• • Effect:
• • Use Case:
• • Visual Example.
Gradiant:-
The morphological gradient highlights object edges by subtracting
the eroded image from the dilated image.
It provides a sharp boundary representation.
Top hat
The top hat transformation extracts the "bright"
details in an image
by subtracting the opened image from the original image.
It is useful for detecting small details.
Structuring Element:
• • Definition:
Matrix used for probing the image.
• • Types:
• - Rectangular
• - Circular
• - Custom shapes
• • Importance in Morphological Operations.
Example of morphological Algorithms:
• • Boundary Extraction:
Original - eroded version.
• • Region Filling: Iterative dilation.
• • Convex Hull: Simplifies object contours.
Application in Reallife:
Limitations:
Filtering:
Removing noise.
Feature Extraction:
Convert images into their frequency components (e.g., Fourier Transform) to make
manipulation easier.
3. Key Transforms
o Filtering:
o Reconstruction:
Used in JPEG.
o Noise Reduction:
C. Haar Transform
Purpose:
o Edge Detection:
o Face Detection:
5. Limitations
like Haar, may struggle with high-resolution or highly
Some transforms,
detailed images.
Can introduce artifacts (unwanted distortions) during reconstruction.
By understanding and using image transforms, engineers and researchers can process images more efficiently,
making tasks like compression and enhancement much easier in applications like photography, video
processing, and medical imaging.
Practical
The code in your file performs several digital image processing tasks in Python using libraries like OpenCV,
NumPy, and Matplotlib. Here’s a simple explanation of each part:
The code connects your Google Drive to access files stored there:
This allows the program to load an image (Einstein.jpg) stored on Google Drive.
2. Importing Libraries
cv2: For working with images (reading, modifying, and displaying them).
numpy: For mathematical operations on image data.
matplotlib.pyplot: For showing images with titles.
skimage: Additional utilities for image adjustments.
3. Displaying Images
4. Pseudo Coloring
Pseudo coloring applies a specific color map (e.g., COLORMAP_JET) to a grayscale image to make it visually
appealing:
5. Color Transformations
Here, a custom matrix is applied to enhance or modify the color tones of the image.
7. Color Complement
def color_complement(image):
return 255 - image
Example Output: A negative of the image is produced (dark areas become bright, and vice versa).
8. Color Slicing
Example Output: Parts of the image with colors within a certain range are kept; others are removed.
9. Removing Noise
def remove_noise(image):
denoised = cv2.fastNlMeansDenoisingColored(image, None, 10, 10, 7, 21)
return denoised
General Workflow
This code demonstrates several image segmentation techniques using Python and image processing libraries.
Below is a simplified explanation of each part:
1. Importing Libraries
2. Displaying Images
The display_image function is used to display images with titles. It takes the image and optionally a colormap
(e.g., for grayscale images) and shows the image using Matplotlib.
The code reads an image file (micky.jpg) from Google Drive. If the file cannot be loaded, it displays an error
message. It converts the image from BGR (OpenCV's default format) to RGB for proper display.
4. Color-Based Segmentation
This technique isolates parts of the image based on color intensity ranges.
How it works: A mask is created to include only pixels within a specific color range.
Example: Detecting blue colors:
lower_bound = np.array([0, 0, 50])
upper_bound = np.array([200, 200, 255])
5. Region-Based Segmentation
This approach starts with a "seed point" and expands the region by including neighboring pixels with similar
intensity values.
Example: Using a starting point (50, 50) with a small intensity difference threshold (5).
Flood Fill: The algorithm grows the region like pouring water into a specific area.
6. Texture-Based Segmentation
How it works: Converts the image to grayscale and applies texture analysis (e.g., using Local Binary
Patterns or thresholding).
Example Output: Regions with different surface textures (e.g., smooth vs rough) are separated.
7. Edge-Based Segmentation
This method groups similar pixels into clusters using K-Means Clustering.
How it works:
1. Image data is reshaped into a list of pixel values.
2. The K-Means algorithm groups these pixels into clusters (e.g., 4 clusters).
3. Each cluster represents a region in the image.
Example Output: The image is segmented into different regions based on pixel similarity.
Summary of Techniques
Technique Purpose
Color-Based Segmentation Isolate regions based on color.
Region-Based Segmentation Grow regions from a starting point (seed).
Texture-Based Segmentation Differentiate regions by texture.
Edge-Based Segmentation Highlight object boundaries (edges).
Clustering-Based Segmentation Group pixels into clusters (e.g., using K-Means).
Let me know if you want me to focus on any particular method in more detail!