SCALED PATTERN MATCHING
A.Amir Bar-Ilan Univ. & Georgia TechA.Butman Holon CollegeM.Lewenstein Bar-Ilan Univ. E.Porat Bar-Ilan Univ.
SEARCHING FOR TEMPLATES IN AERIAL PHOTOGRAPHS
TEMPLATE
INPUT
TASK: Search for all locations where the templateappears in the image.
AERIAL PHOTO
Theoretically, need to consider: Noise Occlusion Scaling (size) Rotation (orientation)
We are interested inasymptotically efficient algorithms
in pixel space.
local errors
MODEL Low Level (pixel level) avoid costly
preprocessing
Asymptotically efficient solutions.
Serial, exact algorithms.
TYPES OF APPROXIMATIONS
Local Errors: Level of detailOcclusionNoise
Results:
)log( 2 mnO mismatches
)( 22knO edit distance, k errors,rectangular patterns
)loglog( 2 kkmmknO edit distance, k errors,half-rectangular patterns
AL-88
AF-95
TYPES OF APPROXIMATIONS
Orientation
Results:
)( 52mnO
)( 32mnO
FU-98
ACL-98
EVEN WITHOUT ERRORS AND ROTATIONS…
DIGITIZING NEWSPAPER STORIESIDEA: Keep dictionary of fonts
Search for appearances in all size.
PROBLEM
INHERENTLY INEXACTWhat if appearance is 1½ times
bigger ?What is ½ a pixel ?SOLUTIONS UNTIL NOW:
NATURAL SCALES
Consider only discrete scales
How does one model for real scales?
T[7,7]
T[5,4]
T[3,3]T[3,2]T[3,1]
T[2,3]T[2,2]T[2,1]
T[1,3]T[1,2]T[1,1]1
2
3
4
5
6
7
1 2 3 4 5 6 7
Step 1: Define grid & pixel centers.
Example: Unit pixel array for a 77array.
Scaled
To 1⅓
Step 2: Define scaling. Example: 33 array.
ScaledTo 1⅓
Remark: We only scale “up”
Reasons: Avoid conceptual problems of loss
of resolution. From “far enough” away
everything looks the same.
Let P be a mm pattern and T an nn text.
How many different scaled patterns of P are there?
In fact, can there be two different scaled patterns of P of size kk?
5×5
Example :
Scaled
by 1.1 to 6x6
4 x 1.1 = 4.4
4 x 1.125 = 4.5
Scaled
by 1.125 to 6x6
3 x 1.17 = 3.51
Scaled
by 1.17 to 6x6
2 x 1.25 = 2.5
Scaled
by 1.25 to 6x6
Let P be a mm pattern and T an nn text.
How many different scaled patterns of P are there?
Claim
There are ≤ nm different scaled patterns representing all the occurrences of P.
mm, (m+1)(m+1), … , nn
n-m different possible sizes
…
Each one has at most m possible matrices representing it
Proof:
Each one has at most m possible matrices representing it
Proof:
Why?
Distance = 1
…
…
… …
Pattern P scaled to size k×k,
…
…
… …
)k)×(½-k(½-
…
…… …
)k)×(½+k(½+
1
Therefore
There are ≤ nm different scaled patterns representing all the occurrences of P.
Algorithm outline for 2-D scaled matching
Straightforward Idea Construct dictionary of O(nm)
possible scaled occurrences of P.
Use 2-dimensional dictionary matching algorithm to scan the text in linear time and find all occurrences.
Space and Time Analysis
mm, (m+1)(m+1), … , nn
Dictionary size O(n3m)
…
Each one has at most m possible matrices representing it
Solution
Our idea is to keep the dictionary in compressed form.
The compression we use is run-length of the rows.
Run-length
aabcccbba2b1c3b2
ABC
DEF
GHI
AABBBCC
AABBBCC
DDEEEFF
DDEEEFF
DDEEEFF
GGHHHII
GGHHHII
ScaledTo 2⅓
The compressed dictionary
AABBBCC
AABBBCC
DDEEEFF
DDEEEFF
DDEEEFF
GGHHHII
GGHHHII
Compressedform
A2B3C22
D2E3F23
G2H3I22
#of repetitions of row
A2B3C22
D2E3F23
G2H3I22
#of repetitions of row
Size of Array: mxm# of diff. scaled patterns: (n-m) x m
Dictionary size: O(nm3)
The Idea behind the text searching
For every text location [i,j], we assume that there is a pattern scaled occurrence beginning at that location.
Subsequently, we establish the number of times this row repeats in the text.
This allows us to an appropriately scaled pattern row from the dictionary.
Example for text searching
c100ba
c100ba
.
.
.
c100ba
.
.
.
.
.
.
102
2
1
.
.
.
P:
d150cb10
c150ba10
c150ba10
…c150ba10
.
.
.
.
.
.
.
.
.
.
.
.
…
…
…
.
.
.
.
.
.
.
.
.
.
.
.
1
2
133
132
.
.
.
.
.
.
T:
…c150ba101
aaaaaaaaaa
Look in the text location [1,10]
c100ba
c100ba
.
.
.
c100ba
.
.
.
.
.
.
102
2
1
.
.
.
P:
d150cb10
c150ba10
c150ba10
…c150ba10
.
.
.
.
.
.
.
.
.
.
.
.
…
…
…
.
.
.
.
.
.
.
.
.
.
.
.
1
2
133
132
.
.
.
.
.
.
T:
c100ba
c100ba
.
.
.
c100ba
.
.
.
.
.
.
102
2
1
.
.
.
P:
d150cb10
c150ba10
c150ba10
…c150ba10
.
.
.
.
.
.
.
.
.
.
.
.
…
…
…
.
.
.
.
.
.
.
.
.
.
.
.
1
2
133
132
.
.
.
.
.
.
T:
…c150ba101
…c150ba101
aaaaaaaaaab
…c150ba101
aaaaaaaaaabccccccccccccccc…
Look in the text location [1,10]
c100ba
c100ba
.
.
.
c100ba
.
.
.
.
.
.
102
2
1
.
.
.
P:
d150cb10
c150ba10
c150ba10
…c150ba10
.
.
.
.
.
.
.
.
.
.
.
.
…
…
…
.
.
.
.
.
.
.
.
.
.
.
.
1
2
133
132
.
.
.
.
.
.
T:
22
2½2½
c100ba
c100ba
.
.
.
c100ba
.
.
.
.
.
.
102
2
1
.
.
.
P:
d150cb10
c150ba10
c150ba10
…c150ba10
.
.
.
.
.
.
.
.
.
.
.
.
…
…
…
.
.
.
.
.
.
.
.
.
.
.
.
1
2
133
132
.
.
.
.
.
.
T:
A scale
range of
[ 1,1¼(
c100ba
c100ba
.
.
.
c100ba
.
.
.
.
.
.
102
2
1
.
.
.
P:
d150cb10
c150ba10
c150ba10
…c150ba10
.
.
.
.
.
.
.
.
.
.
.
.
…
…
…
.
.
.
.
.
.
.
.
.
.
.
.
1
2
133
132
.
.
.
.
.
.
T:Last symbol may repeat in the text more time than the scaled pattern need.
What about the number of times the first subrow repeats?
c100ba
c100ba
.
.
.
c100ba
.
.
.
.
.
.
102
2
1
.
.
.
P:
d150cb10
c150ba10
c150ba10
…c150ba10
.
.
.
.
.
.
.
.
.
.
.
.
…
…
…
.
.
.
.
.
.
.
.
.
.
.
.
1
2
133
132
.
.
.
.
.
.
T:
The range of [1,1¼) is valid since 102ⅹ1¼=128<132.
c100ba
c100ba
.
.
.
c100ba
.
.
.
.
.
.
102
2
1
.
.
.
P:
d150cb10
c150ba10
c150ba10
…c150ba10
.
.
.
.
.
.
.
.
.
.
.
.
…
…
…
.
.
.
.
.
.
.
.
.
.
.
.
1
2
133
132
.
.
.
.
.
.
T:
c100ba
c100ba
.
.
.
c100ba
.
.
.
.
.
.
102
2
1
.
.
.
P:
d150cb10
c150ba10
c150ba10
…c150ba10
.
.
.
.
.
.
.
.
.
.
.
.
…
…
…
.
.
.
.
.
.
.
.
.
.
.
.
1
2
133
132
.
.
.
.
.
.
T:
Look in the text location [1,9]
c100ba
c100ba
.
.
.
c100ba
.
.
.
.
.
.
102
2
1
.
.
.
P:
d150cb10
c150ba10
c150ba10
…c150ba10
.
.
.
.
.
.
.
.
.
.
.
.
…
…
…
.
.
.
.
.
.
.
.
.
.
.
.
1
2
133
132
.
.
.
.
.
.
T:
2½2½
3½3½
c100ba
c100ba
.
.
.
c100ba
.
.
.
.
.
.
102
2
1
.
.
.
P:
d150cb10
c150ba10
c150ba10
…c150ba10
.
.
.
.
.
.
.
.
.
.
.
.
…
…
…
.
.
.
.
.
.
.
.
.
.
.
.
1
2
133
132
.
.
.
.
.
.
T:
A scale
range of
[ 1,¼1¾(
c100ba
c100ba
.
.
.
c100ba
.
.
.
.
.
.
102
2
1
.
.
.
P:
d150cb10
c150ba10
c150ba10
…c150ba10
.
.
.
.
.
.
.
.
.
.
.
.
…
…
…
.
.
.
.
.
.
.
.
.
.
.
.
1
2
133
132
.
.
.
.
.
.
T:
1¾
Too large,it requires the c
to repeat 175 times.c
c150
c100ba
c100ba
.
.
.
c100ba
.
.
.
.
.
.
102
2
1
.
.
.
P:
d150cb10
c150ba10
c150ba10
…c150ba10
.
.
.
.
.
.
.
.
.
.
.
.
…
…
…
.
.
.
.
.
.
.
.
.
.
.
.
1
2
133
132
.
.
.
.
.
.
T:The range is reduced to
[1,¼1 ( 204101
c100ba
c100ba
.
.
.
c100ba
.
.
.
.
.
.
102
2
1
.
.
.
P:
d150cb10
c150ba10
c150ba10
…c150ba10
.
.
.
.
.
.
.
.
.
.
.
.
…
…
…
.
.
.
.
.
.
.
.
.
.
.
.
1
2
133
132
.
.
.
.
.
.
T:
152
[1,¼1( This is still to large for the vertical scale.
204101
c100ba
c100ba
.
.
.
c100ba
.
.
.
.
.
.
102
2
1
.
.
.
P:
d150cb10
c150ba10
c150ba10
…c150ba10
.
.
.
.
.
.
.
.
.
.
.
.
…
…
…
.
.
.
.
.
.
.
.
.
.
.
.
1
2
133
132
.
.
.
.
.
.
T:
The maximum scale valid for both horizontal and vertical scales produces the pattern whose first row is a2bc129 and which repeats 132 times.
c100ba
c100ba
.
.
.
c100ba
.
.
.
.
.
.
102
2
1
.
.
.
P:
d150cb10
c150ba10
c150ba10
…c150ba10
.
.
.
.
.
.
.
.
.
.
.
.
…
…
…
.
.
.
.
.
.
.
.
.
.
.
.
1
2
133
132
.
.
.
.
.
.
T:The range is reduced to
[1,¼1 ( 20457
OPEN PROBLEM:
Give algorithm linear in run-length compressed text and pattern.
END