Post on 05-Apr-2018
transcript
7/31/2019 Binary Image
1/91
Binary ImageBinary ImageProcessingProcessing
By:By:AminAmin KhajehKhajeh DjahromiDjahromi
Department of Electrical EngineeringUniversity of Texas at Arlington
7/31/2019 Binary Image
2/91
RoadmapRoadmap
Binary Image ProcessingBinary Image Processing
ThresholdingThresholding
Geometric PropertiesGeometric Properties
RunRun--Length EncodingLength Encoding
Binary AlgorithmsBinary Algorithms
Morphological OperatorsMorphological OperatorsApplicationsApplications
7/31/2019 Binary Image
3/91
What is Binary Image?What is Binary Image?
Binary images are images whose pixelsBinary images are images whose pixels
have only two possible intensity values.have only two possible intensity values.
Gray Level ImageBinary Image
7/31/2019 Binary Image
4/91
Why do we use binary images?Why do we use binary images?
Smaller memory requirementsSmaller memory requirements
Faster execution timeFaster execution time
Many techniques developed for theseMany techniques developed for these
systems are also applicable to visionsystems are also applicable to visionsystems which use gray scale imagessystems which use gray scale images
Less expensiveLess expensive
7/31/2019 Binary Image
5/91
Disadvantages of using binaryDisadvantages of using binary
imagesimages Limited applicationLimited application
Can not be extended to 3DCan not be extended to 3D
Losing internal details of objects (i.e. inLosing internal details of objects (i.e. in
inspection tasks)inspection tasks) difficult to control the contrast between thedifficult to control the contrast between the
background and the objects (i.e. inbackground and the objects (i.e. inmaterial handling and assembly tasks)material handling and assembly tasks)
7/31/2019 Binary Image
6/91
Some aspects of Binary VisionSome aspects of Binary Vision
SystemsSystems Formation of binary images :Formation of binary images : Binary isBinary is
obtained byobtained by thresholdingthresholding the gray scalethe gray scaleimage. Many cameras are designed toimage. Many cameras are designed to
performperform thresholdingthresholding in hardware.in hardware.
Geometric Properties:Geometric Properties: Size, Position,Size, Position,
Orientation and Projection.Orientation and Projection.
Topological PropertiesTopological Properties
Object recognition in binary imagesObject recognition in binary images
7/31/2019 Binary Image
7/91
SegmentationSegmentation
Segmentation:Segmentation: The partitioning of anThe partitioning of an
image into regions is called segmentationimage into regions is called segmentation
7/31/2019 Binary Image
8/91
ThresholdingThresholding
ThresholdingThresholding:: Is a method to convert aIs a method to convert a
Gray Scale Image into a Binary Image, soGray Scale Image into a Binary Image, sothat objects of interest are separated fromthat objects of interest are separated from
the background.the background.
7/31/2019 Binary Image
9/91
Example ofExample ofThresholdingThresholding
OriginalBinary (Threshold =140)
7/31/2019 Binary Image
10/91
Importance of objectImportance of object--backgroundbackground
separationseparationForForthresholdingthresholding to be effective in objectto be effective in object--
background separation, it is necessarybackground separation, it is necessarythat the objects and background havethat the objects and background have
sufficient contrast and that we know thesufficient contrast and that we know the
intensity levels of either the objects or theintensity levels of either the objects or the
background. In a fixedbackground. In a fixed thresholdingthresholding
scheme these intensity characteristicsscheme these intensity characteristicsdetermine the value of threshold.determine the value of threshold.
7/31/2019 Binary Image
11/91
Some Types ofSome Types ofThresholdingThresholding
FixedFixed ThresholdingThresholding
HistogramHistogram--derived Thresholdsderived Thresholds
IsodataIsodata algorithmalgorithm
Background Symmetry algorithmBackground Symmetry algorithm Triangular algorithmTriangular algorithm
7/31/2019 Binary Image
12/91
Geometric propertiesGeometric properties
SizeSize
PositionPosition
OrientationOrientation
ProjectionProjection
7/31/2019 Binary Image
13/91
SizeSize
SizeSize:: summation of allsummation of allpixel valuespixel values or theor the
number of pixels of thenumber of pixels of the
object.object.
00 00 00 0000 11 11 00
00 11 11 00
00 00 00 00
Size = 4
7/31/2019 Binary Image
14/91
PositionPosition:: The center of the area of the object. In order toThe center of the area of the object. In order tocalculate the position of the object we need to calculate the ficalculate the position of the object we need to calculate the firstrst--
order moments.order moments.
OrientationOrientation:: The way an object is situated in the image. ForThe way an object is situated in the image. Forsome shapes (such as circle), orientation is not unique and tosome shapes (such as circle), orientation is not unique and todefine unique orientation an object must be elongated.define unique orientation an object must be elongated.
ProjectionProjection::
1.1. Horizontal projectionHorizontal projection2.2. Vertical projectionVertical projection
3.3. Diagonal projectionDiagonal projection
7/31/2019 Binary Image
15/91
RunRun--length Encoding (RLE)length Encoding (RLE)
Compact representation of a binary imageCompact representation of a binary image
Used for image transmissionUsed for image transmission Some properties, such as the area,Some properties, such as the area,
projection of the objects, may be directlyprojection of the objects, may be directlycomputed from their runcomputed from their run--length codes.length codes.
Greater compression achieved for longerGreater compression achieved for longerand more frequent runsand more frequent runs
Widely used for binary images.Widely used for binary images.
7/31/2019 Binary Image
16/91
General example for RLEGeneral example for RLE
AAAAABBBBBAAAAABBBBB require 10 bytes to storerequire 10 bytes to store
Run Counts :Run Counts : 5 55 5 Run Value :Run Value : A BA B
RLE code,RLE code, 5A5B5A5B RLE require only 4 bytesRLE require only 4 bytes
Compression ratio : 10/4=2.5Compression ratio : 10/4=2.5
7/31/2019 Binary Image
17/91
Another example of RLEAnother example of RLE
Input :Input : DDDDBBBBGVVVVVVDDDDBBBBGVVVVVV
RLE codes:RLE codes: 4D4B1G6V4D4B1G6V RLE Packet : 8 bytesRLE Packet : 8 bytes
Compression ratio : 15/8Compression ratio : 15/8
7/31/2019 Binary Image
18/91
Two approaches for RLETwo approaches for RLE
1.1. Using start position and length of 1s forUsing start position and length of 1s for
each row.each row.
2.2. Using length of runs, starting with theUsing length of runs, starting with thelength of the 1 run for each row.length of the 1 run for each row.
7/31/2019 Binary Image
19/91
Example for approach 1Example for approach 1
11 11 11 11 00 00 00 11 11 11 11 11 11 11 00 00 0000 00 00 11 11 11 11 11 00 00 00 00 00 00 00 11 11
Start position and length of 1 runs: (1,4) (8,7)
(4,5) (16,2)
7/31/2019 Binary Image
20/91
7/31/2019 Binary Image
21/91
Binary AlgorithmsBinary Algorithms
Before discussing Binary Algorithms, we first need to defineBefore discussing Binary Algorithms, we first need to definesome related terms.some related terms.
NeighborsNeighbors PathPath
ForegroundForeground
BackgroundBackground
ConnectivityConnectivity
Connected ComponentsConnected Components
BoundaryBoundary
InteriorInterior
SurroundsSurrounds
7/31/2019 Binary Image
22/91
NeighborhoodNeighborhood
A pixel has a common boundary with fourA pixel has a common boundary with four
pixels and shares a corner with fourpixels and shares a corner with fouradditional pixels.additional pixels.
44--neighbors: Two pixels areneighbors: Two pixels are 44--neighborsneighborsififthey share a common boundary.they share a common boundary.
88--neighbors: Two pixels areneighbors: Two pixels are 88--neighborsneighborsifif
they share at least one corner.they share at least one corner.
E l fE l f 44 i hbi hb dd 88 i hbi hb
7/31/2019 Binary Image
23/91
Examples ofExamples of44--neighborsneighborsandand 88--neighborsneighbors
(a) 4-neighbors, (b) 8-neighbors
7/31/2019 Binary Image
24/91
PathPath
A path from the pixel at [A path from the pixel at [ii0,j00,j0 ] is a] is a
sequence of pixel indicessequence of pixel indices[[ii00,j,j00],[],[ii11,j,j11],],[[iinn,j,jnn] such that the pixel at] such that the pixel at[[iikk,j,jkk] is neighbor of the pixel at [] is neighbor of the pixel at [iik+1k+1,j,jk+1k+1] for] for
allall kkwithwith 00
7/31/2019 Binary Image
25/91
Examples of 4Examples of 4--path andpath and
88--pathpath
(a) 4-path (b) 8-path
F d B k d dF d B k d d
7/31/2019 Binary Image
26/91
Foreground, Background andForeground, Background and
HolesHoles Foreground: The set of all 1 pixels in anForeground: The set of all 1 pixels in an
image is called theimage is called the foregroundforegroundand isand isdenoted bydenoted by SS
Background: The set of all connectedBackground: The set of all connected
components of complement ofcomponents of complement ofSS thatthathave points on the border of an image ishave points on the border of an image iscalled the background.called the background.
All the other components of complementAll the other components of complementofofSS are calledare called holes.holes.
E l f f d dE l f f d d
7/31/2019 Binary Image
27/91
Example of foreground andExample of foreground and
backgroundbackgroundConsider the below picture:
11
11 11
11
If we consider 4-connectedness for both foreground and background, there are four
Objects that are 1 pixel in size and there is no hole.
But,if we use 8-connectedness, then there is one object and no hole.
So
to avoid this awkward situations, if we use 8-connectedness for foreground, then
4-connecteness should be used for background.
7/31/2019 Binary Image
28/91
ConnectivityConnectivity
A pixelA pixel pp S is said to beS is said to be connectedconnected toto
S if there is a path fromS if there is a path from pptoto qqconsisting entirely of pixels of S.consisting entirely of pixels of S.
For any three pixelsFor any three pixels p,qp,qand r in S, we have:and r in S, we have:
1.1. PixelPixel ppis connected tois connected to p (p (reflexivity).reflexivity).
2.2. IfIfppis connected tois connected to qq, then q is, then q is
connected to p (connected to p (commutativitycommutativity).).3.3. IfIfppis connected tois connected to qqandand qqis connectedis connected
toto rr, then, then ppis connected tois connected to rr(transitivity).(transitivity).
7/31/2019 Binary Image
29/91
Example of connectivityExample of connectivity
Two connected components based on 4-connectivity
7/31/2019 Binary Image
30/91
Boundary, Interior and surroundsBoundary, Interior and surrounds
Boundary: The boundary of S is the set ofBoundary: The boundary of S is the set of
pixels of S that have 4pixels of S that have 4--neighbors inneighbors in SbarSbar..The boundary is usually denoted by S` .The boundary is usually denoted by S` .
Interior: The interior is the set of pixels ofInterior: The interior is the set of pixels of
S that are not in itS that are not in its boundary. The interiors boundary. The interiorof S is (Sof S is (S--S`).S`).
Surrounds: T surrounds region S, if any 4Surrounds: T surrounds region S, if any 4--path from any points of S to the border ofpath from any points of S to the border ofpicture must intersect T.picture must intersect T.
Example of Boundary Interior andExample of Boundary Interior and
7/31/2019 Binary Image
31/91
Example of Boundary, Interior andExample of Boundary, Interior and
surroundssurrounds
Black: boundary pixels
Gray: interior pixelsWhite: surrounds pixels
Original image
7/31/2019 Binary Image
32/91
Components LabelingComponents Labeling
To find connected components in anTo find connected components in an
image. The points in a connectedimage. The points in a connectedcomponents form a region that representcomponents form a region that represent
an object.an object.
Require the characteristics of theRequire the characteristics of the
components (size, position, orientationcomponents (size, position, orientation
andand ))
7/31/2019 Binary Image
33/91
Example of Component LabelingExample of Component Labeling
Original image Its connected components
Two algorithm for ComponentTwo algorithm for Component
7/31/2019 Binary Image
34/91
Two algorithm for ComponentTwo algorithm for Component
LabelingLabeling11-- Recursive algorithmRecursive algorithm
Rarely used on generalRarely used on general--purpose computerspurpose computers Commonly used on parallel machinesCommonly used on parallel machines
22-- Sequential algorithmSequential algorithm
Usually require two passes over the imageUsually require two passes over the image
Works with only two rows of an image at a timeWorks with only two rows of an image at a time
so there is no need to bring the whole imageso there is no need to bring the whole imageinto memoryinto memory
7/31/2019 Binary Image
35/91
Recursive algorithmRecursive algorithm
1.1. Scan the image to find an unlabeled 1Scan the image to find an unlabeled 1
pixel and assign it a new label L.pixel and assign it a new label L.2.2. Recursively assign a label L to all itRecursively assign a label L to all its 1s 1
neighbors.neighbors.
3.3. Stop if there are no more unlabeled 1Stop if there are no more unlabeled 1
pixel.pixel.
4.4. Go to step 1.Go to step 1.
7/31/2019 Binary Image
36/91
Sequential algorithmSequential algorithm
11-- Scan the image left to right, top to bottomScan the image left to right, top to bottom
22-- If this pixel is oneIf this pixel is one(a) if only one of its upper and left neighbors has a label,
then copy the label
(b) If both have the same label, then copy the label.(c) If both have different labels, then copy the uppers
label and enter the labels in the equivalence table
as equivalent labels(d) Otherwise assign a new label to this pixel and enter
this label in the equivalence table.
7/31/2019 Binary Image
37/91
3- If there are more pixels to consider, then go tostep 2.
4- Find the lowest label for each equivalent set inthe equivalence table.
5- Scan the picture. Replace each label by thelowest label in its equivalent table.
7/31/2019 Binary Image
38/91
Example of Component LabelingExample of Component Labeling
S f
7/31/2019 Binary Image
39/91
Size filteringSize filtering
If we know that objects of interest are ofIf we know that objects of interest are of
size greater than Tsize greater than T0 ,0 , then we can use sizethen we can use sizefilter to remove noise after componentfilter to remove noise after component
labeling. In this case all components belowlabeling. In this case all components below
TT00 in size are removed by changing thein size are removed by changing thecorresponding pixels to 0.corresponding pixels to 0.
E l f i filt i
7/31/2019 Binary Image
40/91
Example of size filteringExample of size filtering
Original image ( noisy letter i ) size filtered image T=3
E l bE l b
7/31/2019 Binary Image
41/91
Euler numberEuler number
E (Euler No.) used as a feature of anE (Euler No.) used as a feature of an
object.object. E= CE= C HH
Where C = number of connectedWhere C = number of connectedcomponents (objects) and H = number ofcomponents (objects) and H = number of
Holes.Holes.
E is invariant to translation, rotation andE is invariant to translation, rotation and
scaling. (fixed feature of an object)scaling. (fixed feature of an object)
E l f E l bE l f E l b
7/31/2019 Binary Image
42/91
Example of Euler numberExample of Euler number
For this image:For this image:
C (number of objects)=?C (number of objects)=?H (number of holes) =?H (number of holes) =?
E=CE=C--H = ?H = ?
C=1 !!!C=1 !!!
H=3 !!!H=3 !!!
E=E= --22
Di tDi t
7/31/2019 Binary Image
43/91
Distance measureDistance measure
1.1. EuclideanEuclidean
2.2. CityCity--blockblock3.3. ChessboardChessboard
The cityThe city--block and chessboard measureblock and chessboard measureare preferred over Euclidean due to theirare preferred over Euclidean due to theirsimplicity of calculation.simplicity of calculation.
Euclidean distance is closest to theEuclidean distance is closest to thecontinue case, but it is computationallycontinue case, but it is computationallythe most expensive.the most expensive.
Di t t fDi t t f
7/31/2019 Binary Image
44/91
Distance transformDistance transform
Representing an image in terms ofRepresenting an image in terms of
distance.distance. It is useful in character recognition.It is useful in character recognition.
It can calculated by using a parallelIt can calculated by using a paralleliterative algorithmiterative algorithm
Distance MeasureDistance Measure
7/31/2019 Binary Image
45/91
s a ce easu e
--EuclideanEuclidean
The Euclidean distance is the straight lineThe Euclidean distance is the straight line
between two pixels.between two pixels.
Distance MeasureDistance Measure
7/31/2019 Binary Image
46/91
--CityblockCityblock
Measure the path between the pixels based on aMeasure the path between the pixels based on a
44--connected neighborhood.connected neighborhood.
Pixels whose edges touch are 1 unit apart.Pixels whose edges touch are 1 unit apart.
PixelsPixels diagnallydiagnally touching are 2 units apart.touching are 2 units apart.
Distance MeasureDistance Measure
7/31/2019 Binary Image
47/91
--ChessboardChessboard
Measure the path between the pixels based onMeasure the path between the pixels based on
an 8an 8--connected neighborhood.connected neighborhood.
Pixels whose edges or corners touch are 1 unitPixels whose edges or corners touch are 1 unit
apart.apart.
Medial Axis/Medial Axis/ SkeletonizationSkeletonization
7/31/2019 Binary Image
48/91
Medial Axis/Medial Axis/ SkeletonizationSkeletonization
Used to reduce foreground regions in a binary
image to a skeletal remnant that largely
preserves the extent and connectivity of the
original region while throwing away most of the
original foreground pixels. Methods of skeletonization:
Thinning
Calculate distance transformof the image -theskeleton then lies along the singularities(i.e. creasesor curvature discontinuities) in the distance transform.
ExampleExample
7/31/2019 Binary Image
49/91
ExampleExample
Skeletonization
ThinningThinning
7/31/2019 Binary Image
50/91
ThinningThinning
Thinning is an image processing operationThinning is an image processing operation
in which binaryin which binary--valued image regions arevalued image regions arereduced to lines that approximate theirreduced to lines that approximate their
center lines.center lines.
Also called asAlso called as skeletonskeleton ororcorecore
Reduce image components to theirReduce image components to their
essential informationessential information
Thinning requirementsThinning requirements
7/31/2019 Binary Image
51/91
Thinning requirementsThinning requirements
1.1. Connected image regions must thin toConnected image regions must thin toconnected line structures.connected line structures.
2.2. The thinned result should be minimally 8The thinned result should be minimally 8--connected.connected.
3.3. ApproximateApproximate endlineendline location should belocation should bemaintained.maintained.
4.4. The thinning results should approximate theThe thinning results should approximate the
medial lines.medial lines.5.5. Short branches caused by thinning should beShort branches caused by thinning should be
minimized.minimized.
Example of ThinningExample of Thinning
7/31/2019 Binary Image
52/91
Example of ThinningExample of Thinning
Threshold = 60
Expanding and shrinkingExpanding and shrinking
7/31/2019 Binary Image
53/91
Expanding and shrinkingExpanding and shrinking
Expanding : Change a pixel from 0 to 1 ifExpanding : Change a pixel from 0 to 1 if
any neighbors of the pixel are 1.any neighbors of the pixel are 1. Shrinking : Change a pixel from 1 to 0 ifShrinking : Change a pixel from 1 to 0 if
any neighbors of the pixel are 0.any neighbors of the pixel are 0.
According to the above definition,According to the above definition,
Shrinking may be consider as expandingShrinking may be consider as expanding
the background.the background.
Properties of Shrinking andProperties of Shrinking and
7/31/2019 Binary Image
54/91
ExpandingExpanding Expanding followed by Shrinking can beExpanding followed by Shrinking can be
used for filling undesirable holes.used for filling undesirable holes. Shrinking followed by Expanding can beShrinking followed by Expanding can be
used for removing isolated noise pixels.used for removing isolated noise pixels.
Expanding and Shrinking can be used toExpanding and Shrinking can be used to
determine isolated components anddetermine isolated components and
clusters.clusters.
Example of Shrinking andExample of Shrinking and
7/31/2019 Binary Image
55/91
ExpandingExpanding
An example of expanding and shrinking operations on the letter s
Left: the original image Middle: Expanded image Right: Shrunken
7/31/2019 Binary Image
56/91
7/31/2019 Binary Image
57/91
7/31/2019 Binary Image
58/91
7/31/2019 Binary Image
59/91
7/31/2019 Binary Image
60/91
7/31/2019 Binary Image
61/91
7/31/2019 Binary Image
62/91
7/31/2019 Binary Image
63/91
7/31/2019 Binary Image
64/91
7/31/2019 Binary Image
65/91
7/31/2019 Binary Image
66/91
7/31/2019 Binary Image
67/91
7/31/2019 Binary Image
68/91
7/31/2019 Binary Image
69/91
7/31/2019 Binary Image
70/91
7/31/2019 Binary Image
71/91
7/31/2019 Binary Image
72/91
7/31/2019 Binary Image
73/91
7/31/2019 Binary Image
74/91
7/31/2019 Binary Image
75/91
7/31/2019 Binary Image
76/91
7/31/2019 Binary Image
77/91
7/31/2019 Binary Image
78/91
7/31/2019 Binary Image
79/91
7/31/2019 Binary Image
80/91
7/31/2019 Binary Image
81/91
7/31/2019 Binary Image
82/91
7/31/2019 Binary Image
83/91
7/31/2019 Binary Image
84/91
7/31/2019 Binary Image
85/91
7/31/2019 Binary Image
86/91
7/31/2019 Binary Image
87/91
7/31/2019 Binary Image
88/91
7/31/2019 Binary Image
89/91
References (books)References (books)
7/31/2019 Binary Image
90/91
Machine VisionMachine Vision ((RameshRamesh Jain,Jain, RangacharRangacharKasturiKasturi, Brian G., Brian G.SchunckSchunck))
Automated Visual InspectionAutomated Visual Inspection (B. G. Batchelor, D. A.(B. G. Batchelor, D. A.Hill, and D. C. Hodgson )Hill, and D. C. Hodgson )
Intelligent Image Processing in PrologIntelligent Image Processing in Prolog (B. G.(B. G.Batchelor )Batchelor )
References (Web)References (Web)
7/31/2019 Binary Image
91/91
http://bruce.cs.cf.ac.uk/bruce/Machine_vision_tutorial/Binhttp://bruce.cs.cf.ac.uk/bruce/Machine_vision_tutorial/Bin
ary_image_processing.htmlary_image_processing.html
University of North Dakota, Department of ComputerScience, computer vision website
http://www.machinevisiononline.org/public/articles/archiv
edetails.cfm?id=1396 Computer Engineering Department, Ko University
(course website)(course website)
http://bruce.cs.cf.ac.uk/bruce/Machine_vision_tutorial/Binary_image_processing.htmlhttp://bruce.cs.cf.ac.uk/bruce/Machine_vision_tutorial/Binary_image_processing.htmlhttp://bruce.cs.cf.ac.uk/bruce/Machine_vision_tutorial/Binary_image_processing.htmlhttp://bruce.cs.cf.ac.uk/bruce/Machine_vision_tutorial/Binary_image_processing.htmlhttp://www.machinevisiononline.org/public/articles/archivedetails.cfm?id=1396http://www.machinevisiononline.org/public/articles/archivedetails.cfm?id=1396http://eng.ku.edu.tr/academic/computer/computer.htmlhttp://www.ku.edu.tr/http://www.ku.edu.tr/http://eng.ku.edu.tr/academic/computer/computer.htmlhttp://www.machinevisiononline.org/public/articles/archivedetails.cfm?id=1396http://www.machinevisiononline.org/public/articles/archivedetails.cfm?id=1396http://bruce.cs.cf.ac.uk/bruce/Machine_vision_tutorial/Binary_image_processing.htmlhttp://bruce.cs.cf.ac.uk/bruce/Machine_vision_tutorial/Binary_image_processing.html