a tutorial on ip 1

25
Copyright © Robotix Team, IIT Copyright © Robotix Team, IIT Kharagpur Kharagpur February 1st – 4th ,2007

Upload: anirudhadapa

Post on 28-Dec-2015

12 views

Category:

Documents


3 download

DESCRIPTION

Robotix tutorial

TRANSCRIPT

Page 1: A Tutorial on IP 1

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

February 1st – 4th ,2007

Page 2: A Tutorial on IP 1

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

What is Image ProcessingWhat is Image Processing Image Processing is a tool for analyzing image Image Processing is a tool for analyzing image

data in all areas of natural science.data in all areas of natural science. It is concerned with extracting data from real-It is concerned with extracting data from real-

world images.world images. Differences from computer graphics is that Differences from computer graphics is that

computer graphics makes extensive use of computer graphics makes extensive use of primitives like lines, triangles & points. However primitives like lines, triangles & points. However no such primitives exist in a real world images.no such primitives exist in a real world images.

Page 3: A Tutorial on IP 1

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Typical Applications of IPTypical Applications of IP

Automated visual inspection system. Checking of Automated visual inspection system. Checking of objects for defects visually.objects for defects visually.

Satellite Image Processing.Satellite Image Processing. Classification (OCR), identification (Handwriting, Classification (OCR), identification (Handwriting,

finger prints) etc.finger prints) etc.

Page 4: A Tutorial on IP 1

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Components of IP systemComponents of IP system

Camera, Scanner, other image acquisition Camera, Scanner, other image acquisition software.software.

PC or workstation or DSP kit.PC or workstation or DSP kit. Software to run on the hardware platform.Software to run on the hardware platform. To process an image, a representation or model is To process an image, a representation or model is

necessary.necessary. An image is a spatial distribution of irradiance in An image is a spatial distribution of irradiance in

a plane.a plane.

Page 5: A Tutorial on IP 1

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Possible representation of ImagesPossible representation of Images

MatrixMatrix QuadtreesQuadtrees ChainsChains PyramidPyramid

Of the four, matrix is the most general. The other Of the four, matrix is the most general. The other three are used for special purposes. All these three are used for special purposes. All these representations must provide for spatial representations must provide for spatial relationships.relationships.

Page 6: A Tutorial on IP 1

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Matrix Representation Matrix Representation Computers cannot handle continuous images but Computers cannot handle continuous images but

only arrays of digital numbers.only arrays of digital numbers. So images are represented as 2-D arrays of points So images are represented as 2-D arrays of points

(2-D matrix)(2-D matrix) A point on this 2-D grid (corresponding to the A point on this 2-D grid (corresponding to the

image matrix element) is called PIXEL (picture image matrix element) is called PIXEL (picture element)element)

It represents the average irradiance over the area It represents the average irradiance over the area of the pixel.of the pixel.

Page 7: A Tutorial on IP 1

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Types of ImagesTypes of Images

Color Images :Color Images :

Each pixel value has three components. Red, Each pixel value has three components. Red, Green, Blue. Each component can take a value of Green, Blue. Each component can take a value of 0-255. In computer memory it is stored as a 32 0-255. In computer memory it is stored as a 32 bit value with bits 0-7 storing Blue, 8-15 storing bit value with bits 0-7 storing Blue, 8-15 storing Green, 16-23 storing Red, 24-31 storing alpha or Green, 16-23 storing Red, 24-31 storing alpha or left blank.left blank.

Page 8: A Tutorial on IP 1

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Types of Images(contd..1)Types of Images(contd..1)

Grey Scale Images :Grey Scale Images :

Each Pixel value has only one component, Each Pixel value has only one component, Grayscale value. This represents the brightness Grayscale value. This represents the brightness on a 0-255 scale. It is also stored in memory as on a 0-255 scale. It is also stored in memory as 32 bit with 32 bit with

R=G=B. But for our purposes we can use a R=G=B. But for our purposes we can use a single uchar and convert it to ulong on the fly.single uchar and convert it to ulong on the fly.

Page 9: A Tutorial on IP 1

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Types of Images(contd..2)Types of Images(contd..2)

Binary Images :Binary Images :

Each pixel can take one of the two values 0 and 1. Each pixel can take one of the two values 0 and 1. so a pixel is either ON or OFF. Images which are so a pixel is either ON or OFF. Images which are easiest to work witheasiest to work with

We recommend using these Images.We recommend using these Images.

Page 10: A Tutorial on IP 1

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Concept of NeighbourhoodsConcept of Neighbourhoods

A Neighbourhood N of a pixel is a subset of the A Neighbourhood N of a pixel is a subset of the image which satisfies some distance relation with image which satisfies some distance relation with the pixel.the pixel.

Euclidean distanceEuclidean distance

LLeuclideaneuclidean = = √(x√(x11-y-y11))22+(x+(x22-y-y22))22

City Block distanceCity Block distance

LLcity city = |(x= |(x11-y-y11)|+|(x)|+|(x22-y-y22)|)|

Chess board distanceChess board distance

LLchessboardchessboard = min (|x = min (|x11-y-y11|, |x|, |x22-y-y22|)|)

Page 11: A Tutorial on IP 1

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Concept of Neighbourhoods(contd…)Concept of Neighbourhoods(contd…)

Von Neumann NeighbourhoodVon Neumann Neighbourhood

Nvon(x) = { y : Lcity (y,x) =1)Nvon(x) = { y : Lcity (y,x) =1) Moore NeighbourhoodMoore Neighbourhood

Nmoore(x) = {y : Lchess(y,x) =1 )Nmoore(x) = {y : Lchess(y,x) =1 )

Page 12: A Tutorial on IP 1

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Image PreprocessingImage Preprocessing

First step in most IP applications.First step in most IP applications. Used to remove noise in the input imageUsed to remove noise in the input image Examples are median filtering, averaging, Examples are median filtering, averaging,

contrast enhancement etc.contrast enhancement etc.

Page 13: A Tutorial on IP 1

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Image Preprocessing(contd…)Image Preprocessing(contd…) Median FilteringMedian Filtering F is an image.F is an image. F’ is an blank image.F’ is an blank image.

F’(x) = Median {F(y)| y F’(x) = Median {F(y)| y € N(x) }€ N(x) } x=(x1,x2) , y= (y1,y2)x=(x1,x2) , y= (y1,y2)F’(x) = Median(F(x,y+1),F(x,y-1),F(x-1,y),F(x,y-1))F’(x) = Median(F(x,y+1),F(x,y-1),F(x-1,y),F(x,y-1)) Mean FilteringMean Filtering F’(x) = Mean {F(y)| y F’(x) = Mean {F(y)| y € N(x) }€ N(x) }

F’(x) = ¼ (F(x,y+1),F(x,y-1),F(x-1,y),F(x,y-1))F’(x) = ¼ (F(x,y+1),F(x,y-1),F(x-1,y),F(x,y-1))

Page 14: A Tutorial on IP 1

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Image Preprocessing(contd…)Image Preprocessing(contd…)

Edge DetectionEdge Detection

Almost all edge detection algorithms are based on Almost all edge detection algorithms are based on some form of differentiation.some form of differentiation.

Simplest Algorithm:Simplest Algorithm:F(xF(x11,x,x22) = F(x) = F(x11+1,x+1,x22) – F(x) – F(x11,x,x22) ) Horizontal GradientHorizontal Gradient

Page 15: A Tutorial on IP 1

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Image Preprocessing(contd…)Image Preprocessing(contd…)

F(xF(x11,x,x22) = F(x) = F(x11,x,x22+1) – F(x+1) – F(x11,x,x22) ) Vertical GradientVertical Gradient

F(xF(x11,x,x22) = |F(x) = |F(x11+1,x+1,x22) –F(x) –F(x11,x,x22)|+)|+

|F(x|F(x11,x,x22+1) – F(x+1) – F(x11,x,x22)|)| Other Possible algorithms: Sobel, canny, Frei-Chen, Other Possible algorithms: Sobel, canny, Frei-Chen,

Crack, Roberts, Prewitt etc.Crack, Roberts, Prewitt etc.

Page 16: A Tutorial on IP 1

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Segmentation:Segmentation:

The process of checking each individual pixel to The process of checking each individual pixel to see whether it belongs to an object of interest or see whether it belongs to an object of interest or not.not.

After segmentation, it is known which pixel After segmentation, it is known which pixel belongs to which object.belongs to which object.

The next step is image analysis & recognition, The next step is image analysis & recognition, using the shape of the image. using the shape of the image.

Page 17: A Tutorial on IP 1

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Segmentation(contd…)Segmentation(contd…) Simplest Segmentation: Pixel BasedSimplest Segmentation: Pixel Based

if (F(x)>T)if (F(x)>T)

F’(x)=1 else F’(x)=1 else

F’(x)=0.F’(x)=0.

Where F(x) is a gray scale image and F’(x) is a Where F(x) is a gray scale image and F’(x) is a binary image of same dimensions. binary image of same dimensions.

Page 18: A Tutorial on IP 1

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Segmentation(contd…)Segmentation(contd…) Connected Components segmentation.Connected Components segmentation. Let a be a binary image of mxn.Let a be a binary image of mxn. Let b, c, d be normal real valued images.Let b, c, d be normal real valued images. Algo: Let d (i, j) = i*n+j 0 Algo: Let d (i, j) = i*n+j 0 ≤ ≤ I I ≤≤ m-1, 0 m-1, 0 ≤≤ j j ≤≤ n n Let b=0Let b=0 c=d.ac=d.a While b!=cWhile b!=c b=cb=c

c=(bc=(b^̂N).aN).a endend

Page 19: A Tutorial on IP 1

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Segmentation(contd…)Segmentation(contd…) Selecting the thresholdSelecting the threshold Usually selected interactively.Usually selected interactively. If is the mean & If is the mean & σσ is the variance of all the pixel is the variance of all the pixel

values.values. Then Then μμ +k +kσσ (1 (1≤≤k k ≤≤ 3) gives good results. Where 3) gives good results. Where

the background is much larger than the object.the background is much larger than the object. Other methods of dynamic thresholding exist.Other methods of dynamic thresholding exist.

Page 20: A Tutorial on IP 1

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

MorphologyMorphology

Operations on the size and shape of the object.Operations on the size and shape of the object. Performed on binary imagesPerformed on binary images

Page 21: A Tutorial on IP 1

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Basic OperationsBasic Operations

ErosionErosion G-M ={ p: MG-M ={ p: Mpp c= G } c= G } G: Set of all pixels of the matrix which are non G: Set of all pixels of the matrix which are non

zero.zero. MMpp : Neighbourhood operator centered at point P : Neighbourhood operator centered at point P

(here called a structuring element) (here called a structuring element)

Page 22: A Tutorial on IP 1

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Basic Operations(contd…)Basic Operations(contd…)

DilationDilation G+M ={ p: MG+M ={ p: Mpp∩G ≠ ∩G ≠ ΦΦ } } Elementary operators from which other more Elementary operators from which other more

complex operators can be built.complex operators can be built. Although they belong to the family of the image Although they belong to the family of the image

analysis operators, it can also be used as low analysis operators, it can also be used as low operator to remove noise.operator to remove noise.

Page 23: A Tutorial on IP 1

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Basic Operations(contd…)Basic Operations(contd…)

Composite Morphological OperatorsComposite Morphological Operators Opening Opening

G G °° M = (G – M ) + M M = (G – M ) + M

Closing Closing

G G •• M = (G + M) – M M = (G + M) – M Salt and Pepper Noise RemovalSalt and Pepper Noise Removal

(G (G °° M) M) •• M. M.

Page 24: A Tutorial on IP 1

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Opening removes all objects which at no point Opening removes all objects which at no point completely enclose the structure element, but it completely enclose the structure element, but it does not shrink the objects which are larger than does not shrink the objects which are larger than the dia of the structuring element.the dia of the structuring element.

Ideal for removing thin lines.Ideal for removing thin lines. Closing operator closes small holes and cracks Closing operator closes small holes and cracks

without general enlargement.without general enlargement.

Basic Operations(contd…)Basic Operations(contd…)

Page 25: A Tutorial on IP 1

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Thank you…Thank you…