image processing fundamentals - vision online pattern matching •gauging •barcode...

91
Image Processing Fundamentals Nicolas Vazquez Principal Software Engineer National Instruments

Upload: duongdien

Post on 24-Mar-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Image Processing Fundamentals

Nicolas Vazquez Principal Software Engineer

National Instruments

Page 2: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Agenda • Objectives and Motivations • Enhancing Images • Checking for Presence • Locating Parts • Measuring Features • Identifying and Verifying Components

2

Page 3: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

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

3

Page 4: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

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

4

Page 5: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Image Types

• Grayscale – 8-bit: pixel values range from 0 to 255 – 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

• Usually a result of a computation – Complex

Binary Image

Grayscale Image

5

Page 6: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

What is an Ideal Image?

• Range of grayscale values – Spread out between 0 and 255 – No pixels “saturated” at 255 (for most applications)

• Loss of information, impossible to distinguish between saturated pixels

• Good contrast – Between the parts of the image of interest

• Repeatable

In short, an ideal image requires the least number of image processing steps to obtain the result.

6

Page 7: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Class Organization

Enhance • Filter

noise or unwanted features

• Remove distortion

• Calibrate images

Check • Measure

intensity • Create

particles • Analyze

particles

Locate • Match

patterns • Match

geometry • Set-up

coordinate systems

Identify • Read text

(OCR) • Read 1D

barcodes • Read 2D

codes

Measure • Detect

edges • Measure

distance • Calculate

geometry

Page 8: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Class Organization

Enhance • Filter

noise or unwanted features

• Remove distortion

• Calibrate images

Check • Measure

intensity • Create

particles • Analyze

particles

Locate • Match

patterns • Match

geometry • Set-up

coordinate systems

Identify • Read text

(OCR) • Read 1D

barcodes • Read 2D

codes

Measure • Detect

edges • Measure

distance • Calculate

geometry

Page 9: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Motivation

Read characters on a textured surface

9

Page 10: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Motivation

Not possible to cleanly segment characters

10

Page 11: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Motivation

Results without preprocessing

11

Page 12: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Motivation

Read characters on a textured surface

12

Page 13: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Motivation

Image after periodic pattern is removed

13

Page 14: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Motivation

14

Page 15: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Motivation

Results without preprocessing

Results with pre-processing

15

Page 16: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

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

16

Page 17: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Image Preprocessing

• Pre-processing occurs before the application specific processing

Acquisition Preprocessing Application

Specific Processing

• Shading Correction

• De-blurring • De-noising • Contrast

Enhancement • Feature

Enhancement

• Intensity Measurements

• OCR • Pattern

Matching • Gauging • Barcode • Particle

Analysis

17

Page 18: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Enhancement Techniques • Spatial Domain: pixel-wise operations

– Brightness, contrast and gamma – Lookup tables – Gray morphology – Filtering (smoothing, median, general convolution)

• Frequency Domain – Deblurring – Filtering

18

Page 19: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Brightness

• Adds a constant grayscale to all of the image

• Can improve appearance but not useful for most image processing steps

19

Page 20: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

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

20

Page 21: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Gamma

• Nonlinear contrast enhancement

• Higher gamma improves contrast for larger grayscale values

• Does not cause saturation

21

Page 22: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

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 – For example: reverse, square, power…

Power (x=1.5) Reverse Square

22

Page 23: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Histogram • Indicates the number of pixels at each gray level • Provides a good description of the composition of an image • Helps to identify various populations

23

Pixel values

# Pi

xels

Saturation

Page 24: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

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

Original Image

24

Page 25: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Histogram Equalization

Bright

Dark

Low Contrast

High Contrast

Cumulative Histogram

25

Page 26: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Spatial Filtering

Filter Type Filters

Linear Highpass Gradient, Laplacian

Linear Lowpass Smoothing, Gaussian

Nonlinear Highpass

Gradient, Roberts Sobel, Prewitt, Differentiation, Sigma

Nonlinear Lowpass Median, Nth Order

Gradient

Gaussian

Sobel

Median

26

Page 27: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Gray Morphology Morphology Function

Erosion Min(Neighbors)

Dilation Max(Neighbors)

Open Dilation(Erosion(I))

Close Erosion(Dilation(I))

Erosion

Dilation

Open

Close

27

Page 28: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

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 Image FFT H(u,v) IFFT Output

Image

I(x,y) F(u,v) F(u,v).H(u,v) R(x,y)

Periodic noise Bandstop filtered 28

Page 29: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Low Pass Filter Examples • Low Pass with Frequency Domain Filter

• Low Pass with Gaussian Filter

29

Page 30: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

High Pass Filtering Examples • Detect edges

• Sharpen image

30

Page 31: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

ENHANCE IMAGES: IMAGE CALIBRATION

Page 32: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Types of Calibration • 2D spatial calibration

– Applied only to a plane – Corrects for lens and perspective distortion – Does not improve resolution of a measurement – Cannot compensate for poor lighting or unstable conditions

• 3D spatial calibration: x, y, z • Intensity calibration • Color

32

Page 33: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Spatial Calibration

• Corrects for lens and perspective distortion • Allows the user to take real-world measurements from

image based on pixel locations.

known orientation offset

lens distortion

perspective

33

Page 34: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Calibrating Your Image Setup • Acquire image of a calibration grid with known real-

world distances between the dots • Learn the calibration (mapping information) from its

perspective and distortion • Apply this mapping information to subsequent

images and measurements

34

Page 35: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Image Spatial Calibration Example

Calibration grid

Acquired image

Calibrated measurements

35

Page 36: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Image Correction • Use calibration to adjust image geometry so features are represented properly.

Calibration grid

Acquired image

Corrected Images 36

Page 37: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Class Organization

Enhance • Filter

noise or unwanted features

• Remove distortion

• Calibrate images

Check • Measure

intensity • Create

particles • Analyze

particles

Locate • Match

patterns • Match

geometry • Set-up

coordinate systems

Identify • Read text

(OCR) • Read 1D

barcodes • Read 2D

codes

Measure • Detect

edges • Measure

distance • Calculate

geometry

Page 38: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Region of Interest (ROI) • Region of Interest (ROI)

– A portion of the image upon which an image processing step may be performed – Can be defined statically (fixed) or dynamically (based on features located in the

image) • Used to process only pixels that are interesting

– Increases reliability – Reduces processing time

38

Page 39: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Measure Intensity • Intensity statistics of Region of Interest (Search Area) can

be used as a very simple check for presence/absence

39

Page 40: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Thresholding • Thresholding

– Converts each pixel value in an image to 0 or 1 according to the value of the original pixel

– Helps extract significant structures in an image

40

Page 41: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Histogram and Thresholding

Original Image Binary Image

41

Threshold Range

Histogram of Image

Page 42: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Finding Gray Objects • Can also set upper and lower limits for pixel values • Pixels inside the bounds of the limit (red region) are

set to 1, and those outside the limit are set to 0

42

Page 43: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Automatic Thresholding

43

Page 44: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Global vs. Local Threshold

Global Threshold

Local Threshold 44

Page 45: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

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

45

Page 46: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

How Connectivity Affects a Particle

• Connectivity-4: two pixels are considered part of the same particle if they are horizontally or vertically adjacent

1 1 1

1 2 2 2 2 2 2

2 2 2 2

2 3

2

1

1

2

1 1

1 1 1 1 1

1 1 1 1 1 1

1

1

1 • Connectivity-8: two pixels

are considered part of the same particle if they are horizontally, vertically, or diagonally adjacent.

46

Page 47: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Particle measurements

Measures particle features including: location, orientation, area, perimeter, holes, shape equivalences, moments…

47

Page 48: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

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 – Removing holes within particles – Particles touching the border of an image – Particles touching each other – Particles with uneven borders

48

Page 49: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

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

49

Page 50: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

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 connect particles

Dilation

50

Page 51: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Erosion vs. Dilation

Erosion

Dilation

51

Page 52: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

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

52

Page 53: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Close

Close

• A dilation followed by an erosion – Fills holes and creates smooth boundaries – Does not significantly 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

53

Page 54: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Advanced Morphology • Advanced morphological functions are combinations

of operations, each of which is responsible for a single operation

• These functions execute the following tasks: – Remove small or large particles – Remove particles from an image border – Fill holes – Separate particles – Keep or remove particles identified by morphological

parameters – Segmenting the image

54

Page 55: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Particle Filtering • Keeps or removes particles based on geometric features

– Area, width, height, aspect ratio and other features are commonly used to filter

• Typically used on binary images • Cleans up noisy images

Threshold Particle Filter

55

(Keep Heywood Circularity Factor < 1.1)

Page 56: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Application: Particle counting

Threshold

Particle Filter

Original

Page 57: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Class Organization

Enhance • Filter

noise or unwanted features

• Remove distortion

• Calibrate images

Check • Measure

intensity • Create

particles • Analyze

particles

Locate • Match

patterns • Match

geometry • Set-up

coordinate systems

Identify • Read text

(OCR) • Read 1D

barcodes • Read 2D

codes

Measure • Detect

edges • Measure

distance • Calculate

geometry

Page 58: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

LOCATING PARTS: PATTERN MATCHING

Page 59: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Introduction to Matching • Locates regions of a grayscale image that match a

predefined template – Calculate a score for each matching region – Score indicates quality of match

• Returns the XY coordinates, rotation angle and scale for each match

59

Page 60: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Applications

• Presence Detection • Counting • Locating • Inspection

60

Page 61: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

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 and accurately locate

matched regions

61

Page 62: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

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

62

Page 63: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Correlation Pattern Matching

• Assumes grayscale information present in the image

• Directly uses the underlying grayscale information 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.

Template (Pattern)

63

Page 64: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Good template Bad template

• 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

Correlation Pattern Matching

64

Page 65: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Correlation Pattern Matching

• When NOT to use correlation-based pattern matching: – Non-uniform lighting

– Occlusion more than 10%

– Scale changes

65

Page 66: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

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.

66

Page 67: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

GPM is Tolerant to…

Scale Changes

Non-uniform Lighting

Background Changes

Occlusion

67

Page 68: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

GPM – Feature-based

Image

Extract Curves

Template

Target Image

Extract Features

Match Features circles

parallel lines

68

Page 69: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Feature Comparison

Feature CPM GPM Template contains texture-like information Yes Template contains geometric information Yes Yes Find multiple match locations Yes Yes Rotation Yes Yes Scale Yes Occlusion Yes Matching under non-uniform lighting Yes Sub-pixel match locations Yes Yes

69

Page 70: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

LOCATING PARTS: COORDINATE SYSTEMS

Page 71: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Region of Interest (ROI) • Region of Interest (ROI)

– a.k.a. Search Area – A portion of the image upon which an

image processing step may be performed.

– The object under inspection must always appear inside the defined ROI in order to extract measurements from that ROI.

71

• ROIs need to be repositioned when the location of the part varies

Page 72: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Coordinate Systems • Defined by a reference point (origin) and angle within the image, or by the

lines that make up its axes • Allows you to define search areas that can move around the image with

the object you are inspecting • Usually based on a characteristic feature of the object under inspection

– Use pattern match, edge detection or geometry tools to locate features – Use features to establish coordinate system

72

Page 73: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Coordinate Systems – Set Up

1) Define an origin – Locate an easy-to-find feature in

your reference image. Feature must be stable from image to image.

– Set a coordinate system based on its location and orientation

2) Set up measurement ROIs in reference to the new origin – Acquire a new image – Locate reference point – Reposition measurement ROIs

73

Page 74: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Class Organization

Enhance • Filter

noise or unwanted features

• Remove distortion

• Calibrate images

Check • Measure

intensity • Create

particles • Analyze

particles

Locate • Match

patterns • Match

geometry • Set-up

coordinate systems

Identify • Read text

(OCR) • Read 1D

barcodes • Read 2D

codes

Measure • Detect

edges • Measure

distance • Calculate

geometry

Page 75: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Edge Detection Overview • Process of detecting transitions in an image • One of the most commonly used machine vision tools • Attractive because:

– Simple to understand and use – Localized processing – fast – Applicable to many applications

Tolerant to illumination changes

Different Edges

Page 76: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

1D Edge Detection Detect edge points along a line basic operation: 1) Get pixel values along the line 2) Compute gradient information 3) Find peaks and valleys (edge

locations) based on contrast, width, steepness….

4) Select edge(s) based on: – Order: first, last, first & last – Polarity: rising, falling – Score: best edge

Grad

ient

Val

ue

Pixe

l Val

ue

Position Along Line (pixels)

Position Along Line (pixels)

76

Page 77: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Subpixel Accuracy

Subpixel location of edge can be computed using parabolic interpolation

Position Along Line (pixels)

Grad

ient

Val

ue

Subpixel Location

Parabolic Fit

Parabolic interpolation

77

Page 78: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Edge Detector Tools

• Several high level edge tools are build on the single edge detectors

• Rake: – Used to find multiple edges and fit a

shape through them • Configurable search directions,

filtering options and sub-sampling ratios.

78

Page 79: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Straight Edge (Line) Detection • Detect straight lines in an image

– Extension of 1D edge detection • Straight edge detection options:

– Rake-based – Projection-based – Hough transform-based

79 Projection-based find straight edge Locating multiple straight edges

Rake-based find straight edge

Page 80: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Edge Detection Applications • Detect

Features • Alignment • Gauging • Inspection

80

Page 81: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Application: Inspecting Parts

81

Locating part using find straight edge Check for remnant plastic using intensity measurement

Check tips using pattern matching Check liquid level using find straight edge

81

Page 82: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

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

82

Page 83: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Class Organization

Enhance • Filter

noise or unwanted features

• Remove distortion

• Calibrate images

Check • Measure

intensity • Create

particles • Analyze

particles

Locate • Match

patterns • Match

geometry • Set-up

coordinate systems

Identify • Read text

(OCR) • Read 1D

barcodes • Read 2D

codes

Measure • Detect

edges • Measure

distance • Calculate

geometry

Page 84: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Identify

• 1D and 2D Codes • Marking methods • Reading • Examples

84

Page 85: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

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

Code 3 of 9 Code 128 EAN 13

85

Page 86: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

2D Codes • Usually not an index into a database • Camera-based vision systems are preferred reading

method • High data capacity in small footprint

Data Matrix QR Code

PDF 417

86

Page 87: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

1D vs. 2D 1D Codes 2D Codes Low data capacity High data capacity Index into large database Self contained data Large footprint Small footprint Redundancy in Y dimension Error correction capability Readable by laser scanner Requires camera based reader Requires as much as 80% contrast Can be read in low contrast

87

Page 88: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Optical Character Recognition (OCR)

88

Page 89: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

OCR/OCV

OCR/OCV: Optical Character Recognition/Verification: • Reads or verifies (printed) characters Typical steps: • Region of Interest around lines of text • Threshold • Character Segmentation • Compare to Library (classification) • Character is learned or recognized Optical Character Verification (OCV): • Compare character recognized against

golden reference

89

Page 90: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Class Organization

Enhance • Filter

noise or unwanted features

• Remove distortion

• Calibrate images

Check • Measure

intensity • Create

particles • Analyze

particles

Locate • Match

patterns • Match

geometry • Set-up

coordinate systems

Identify • Read text

(OCR) • Read 1D

barcodes • Read 2D

codes

Measure • Detect

edges • Measure

distance • Calculate

geometry

Page 91: Image Processing Fundamentals - Vision Online Pattern Matching •Gauging •Barcode •Particle Analysis 17 Enhancement Techniques • Spatial Domain: pixel-wise operations – Brightness,

Contact Information

Nicolas Vazquez Principal Software Engineer

National Instruments 11500 N. Mopac Expwy Austin, Texas 78759 USA

Phone: +1 512-683-8494 Email: [email protected]

www.ni.com