T11 - Image-Processing-Fundamentals
T11 - Image-Processing-Fundamentals
T11 - Image-Processing-Fundamentals
Fundamentals
Dr. Romik Chatterjee
Vice President of Engineering
Graftek Imaging, Inc.
Agenda
• Objectives and Motivations
• Enhancing Images
• Checking for Presence
• Locating Parts
• Measuring Features
• Identifying and Verifying Components
Class Goals
• Teach the fundamental image processing tools available
in machine vision software
• Provide some background into how the algorithms work
• Accelerate your machine vision learning curve
• What not to expect
– Learn how to develop a complete vision system
– Learn specific, proprietary functions
– 3D vision, color or other advanced topics
– Discussion of the benefits of different application development
environments
Image Processing for Machine Vision
• Objective
– To extract useful information present in an image, in a limited
time
• Secondary
– To display an image for users
• Not
– Improve appearance of image in general
• Used for
– Image pre‐processing
• Minimize variations of information in the image
• Prepare the image for processing and measurement
– Application specific processing
• Use image to count, locate, and measure attributes
Image Types
Grayscale Image
• Grayscale
– 8 bit: pixel values range from 0 to 255
– 12 bit: pixel values range from 0 to 4095
– 16 bit: pixel values range from 0 to 65535
• Color
– Composed of 3 grayscale images (RGB)
• Other types
– Binary: pixel values: 0 and 1
• Commonly used to identify objects of interest
in an image
• Usually the result of image processing step
– Floating point: pixel values range from –
X.xx to X.xx
• Usually a result of a computation
Binary Image
What is an Ideal Image?
• Range of grayscale values
– Spread out between 0 and 255
– No pixels “saturated” at 255 (for most applications)
• Impossible to distinguish between saturated pixels
• Good contrast
– Between the “right” parts of the image
• Repeatable
In short, an ideal image requires the least number of image
processing steps to obtain the result.
Class Organization
Read characters on a textured surface
Motivation
Not possible to cleanly segment characters
Motivation
Results
without
preprocessing
Motivation
Read characters on a textured surface
Motivation
Image after periodic pattern is removed
Motivation
Motivation
Results
without
preprocessing
Results
with
pre‐
processing
Objective of Image Preprocessing
• Process an image so that the resulting image is more
suitable than the original for a specific application
• A preprocessing method that works well for one
application may not be the best method for another
application
Image Preprocessing
• Pre‐processing occurs before the application specific
processing
Application
Acquisition Preprocessing Specific
Processing
• Shading • Intensity
Correction Measurements
• De‐blurring • OCR
• De‐noising • Pattern
• Contrast Matching
Enhancement • Gauging
• Feature • Barcode
Enhancement • Particle Analysis
Enhancement Techniques
• Spatial Domain: pixel‐wise operations
– Brightness, contrast and gamma
– Lookup tables
– Gray morphology
– Filtering (smoothing, median, general convolution)
• Frequency Domain
– Deblurring
– Filtering
Lookup Tables
• A lookup table is a function that maps grayscale
values in an image to new grayscale values, to create
a new result image
255 255 255
200
Result
Result
Result
0
0 255 0 255 0 255
Source Source Source
• Adds a constant
grayscale to all of the
image
• Can improve
appearance but not
useful for most image
processing steps Result
Result
Source Source
Contrast
• Used to increase or decrease
contrast
• Normal = 45 (degree line)
– High = Higher than 45
– Low = Lower than 45
• Typical use is to improve edge
detection
• Sacrifices one range of values to
improve another Result
Result
Source Source
Gamma
• Nonlinear contrast
enhancement
• Higher gamma improves
contrast for larger grayscale
values
• Does not cause saturation
Result
Result
Source Source
Histogram Equalization
• Alters grayscale values of pixels so that
they become evenly distributed across
the full grayscale range
• The function associates an equal
number of pixels per constant grayscale
interval
• Takes full advantage of the available
shades of gray
• Enhances contrast of the image without
modifying the structure Equalized
Histogram Equalization
Cumulative Histogram
Bright
Improved contrast
Dark between characters
and background
Low
Contrast
High
Contrast
Other Lookup Tables
Original
• Smoothing
• Gaussian
Lowpass
• Median
• Nth Order Median
• Gradient
• Laplacian
Highpass • Roberts
• Sobel
Gradient
• Prewitt
Sobel
Frequency Domain Filtering
• Standard filtering can be done in frequency domain
– Low Pass, High Pass, Band Pass, Band Stop, etc.
• Compute the Fourier transform of the image
• Multiply with the transfer function of the filter
• Take the inverse Fourier transform to get the filtered image
Input Output
FFT H(u,v) IFFT
Image Image
I(x,y) F(u,v) F(u,v).H(u,v) R(x,y)
• Low Pass with Gaussian Filter
High Pass Filtering Examples
• Detect edges
• Sharpen image
ENHANCE IMAGES:
IMAGE CALIBRATION
Spatial Calibration
• Corrects for lens and perspective distortion
• Allows the user to take real‐world measurements from
image based on pixel locations.
lens distortion
perspective
Original Image
Histogram of Image
Binary Image
Finding Gray Objects
• Can also set upper and lower limits for pixel values
• Pixels inside the bounds of the limit (blue region) are
set to 1, and those outside the limit are set to 0
Automatic Thresholding
Manual Auto
Threshold Threshold
Local Thresholding
Global Local
Threshold Threshold
B C
Particles and Connectivity
• Thresholding creates binary image:
– Pixels are either ‘0’ or ‘1’
• A particle in a binary image is a group of
connected ‘1’ pixels
• Defining connectivity
– Connectivity‐4: two pixels are considered part
of the same particle if they are horizontally or
vertically adjacent
– Connectivity‐8: two pixels are considered part
of the same particle if they are horizontally,
vertically, or diagonally adjacent.
How Connectivity Affects a Particle
– How many particles with
connectivity‐4?
How Connectivity Affects a Particle
– How many particles with
1
connectivity‐4?
1 1 1
3 1 2
2 2 2
2 2 2 2
3 2 2 2
2
How Connectivity Affects a Particle
– How many particles with
connectivity‐4?
– How many particles with
connectivity‐8?
How Connectivity Affects a Particle
– How many particles with
1
connectivity‐4?
1 1 1
1 1
1 1 1
– How many particles with
connectivity‐8? 1 1 1 1
2
2 1 1 1
1
Binary Morphology
• Binary morphological functions extract and alter the
structure of particles in a binary image
• Morphological functions remove unwanted information
caused by the thresholding process:
– Noise particles
– Particles touching the border of an image
– Particles touching each other
– Particles with uneven borders
Erosion
• Decreases the size of objects in an image
– Removes a layer of pixels along the boundary of the particle
– Eliminates small isolated particles in the background and removes
narrow peninsulas
• Use Erode to:
– Separate particles for counting
Erosion
Dilation
• Increases the size of objects in an image
– Adds a layer of pixels around the boundary of an object (including the inside
boundary for objects with holes)
– Eliminates tiny holes in objects
– Removes gaps or bays of insufficient width
• Use Dilate to:
– Make particles touch
Dilation
Erosion vs. Dilation
Erosion
Dilation
Open
• An erosion followed by a dilation
– Remove small particles and smooth boundaries
– Does not significantly alter the size or shape of particles
– Borders removed by the erosion process are replaced by the dilation process
• Use Open To:
– Eliminate small particles that constitute noise
Open
Close
• A dilation followed by an erosion
– Fills holes and creates smooth boundaries
– Does not alter the size or shape of particles
– Particles that do not connect after the dilation are not changed
• Use Close To:
– Eliminate small holes that constitute noise
Close
Advanced Morphology
• Advanced morphological functions are combinations
of operations, each of which is responsible for a
single operation
• These functions execute the following tasks:
– Separate particles
– Remove small or large particles
– Keep or remove particles identified by morphological
parameters
– Fill holes
– Remove particles from an image border
– Segmenting the image
Particle Filtering
• Keeps or removes particles based on geometric features
– Area, length, aspect ratio and other features are
commonly used to filter
• Typically used on binary images
• Cleans up noisy images
Threshold Particle Filter
Application: Analyze Particles
Original
Threshold
Particle Filter
Class Organization
• Presence Detection
• Counting
• Alignment
• Inspection
How It Works
• Two step process:
– Step 1: Learn Template
• Extract information useful for uniquely characterizing the pattern
• Organize information to facilitate faster search of the pattern in
the image
– Step 2: Match
• Use the information present in the template to locate regions in
the target image
• Emphasis is on search methods that quickly locate matched
regions
Pattern Matching Methods
• Different ways to perform pattern matching based
on the information extracted from the template
• Two common methods:
– Correlation Pattern Matching
• Relies on the grayscale information in the image for
matching
– Geometric Pattern Matching
• Relies on edges and geometric features in the image
for matching
Correlation Pattern Matching
• Grayscale information present
in the image Template (Pattern)
• Directly uses the underlying
grayscale distribution in the
image for matching
• Grayscale values in the
pattern are matched to
regions in the image using
normalized cross‐correlation
• Score ranges from 0‐1000
• Used to allow imperfect match
Correlation Pattern Matching
• When to use:
– Template primarily characterized by grayscale information
– Matching under uniform light changes
– Little occlusion and scale changes in image
– Good for the general case
Good template Bad template
Correlation Pattern Matching
• When NOT to use:
– Non‐uniform lighting
– Occlusion more than 10%
– Scale changes
Geometric Pattern Matching
• Matching tool you can use to locate parts that
contain distinct edge information
• Not useful when template is predominantly defined
by texture
GPM is Tolerant to…
Scale
Changes
Occlusion
Non‐uniform Background
Lighting Changes
GPM – Feature‐based
Target Image
Template
Image
Extract Curves
Extract Features
circles
Match Features
parallel lines
Feature Comparison
Different Illuminations
Different Edges
1D Edge Detection
• Detect edge points along a line
• Basic operation:
– Get pixel values along the
line
– Compute gradient
Pixel Value
information
– Peaks and valleys represent
edge locations Position Along Line (pixels)
– Get first, first & last, best, or
Gradient Value
all edges
Position Along Line (pixels)
Subpixel Accuracy
• Subpixel location of edge can be computed using
parabolic interpolation
Parabolic Fit
Gradient Value
Position Along Line (pixels) Subpixel Location
Edge Detector Tools
• High level tools based on the edge
detectors
• Rake:
– Used to find multiple edges and fit a
shape through them
• Configurable search directions, sub‐
sampling ratios, and display settings
Straight Edge (Line) Detection
• Detect straight lines in an image
– Extension of 1D edge detection
• Straight edge detection options:
– Rake‐based
– Projection‐based
Edge Detection Applications
• Detect
Features
• Alignment
• Gauging
• Inspection
Application: Locating Parts
Failed due
to intensity
Application: Dimension Verification
• Dimensional measurements, such as lengths, distance, and diameter
– Inline gauging inspections are used to verify assembly and
packaging routines
– Offline gauging is used to judge product quality according to a
sample
Class Organization
• 1D and 2D Codes
• Marking methods
• Reading
• Examples
1D Codes
• Applications using 1D bar codes have been around for
over 35 years
• Barcode data is an index into a large central data
storage
• Code is easily read by laser scanners
• Low data capacity in large footprint