Top Banner
Quad Trees Region data vs. point data. Roads and rivers in a country/state. Which rivers flow through Florida? Which roads cross a river? Network firewalls. (source prefix, destination prefix, action) (01*, 110*, drop packet) sour ce des t 8 15 2 4 2 7
33

Quad Trees Region data vs. point data. Roads and rivers in a country/state. Which rivers flow through Florida? Which roads cross a river? Network firewalls.

Dec 18, 2015

Download

Documents

Brittany Dawson
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Quad Trees• Region data vs. point data.

• Roads and rivers in a country/state. Which rivers flow through Florida? Which roads cross a river?

• Network firewalls. (source prefix, destination prefix, action) (01*, 110*, drop packet)

source

dest8 15

24

27

Page 2: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Quad Trees

• Binary images. Image region is divided into cells called pixels. Each pixel is either black (0, background) or white

(1).

Page 3: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Example Binary Image

1111 1 1 1

1111

11

Remaining entries are 0.

Page 4: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Image Operations

• Rotation.

Rotate 90 degrees clockwise.

Page 5: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Scaling

• Expansion. Each pixel is replaced by a 2k x 2k window of

pixels of the same intensity.

• Shrinking. Each 2k x 2k window is replaced by a pixel

whose intensity is some function of that of the window pixel intensities.

Page 6: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Shrinking Example

• k = 1.

• >= 2 white pixels in 21 x 21 window => white pixel.

Page 7: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Union & Intersection

• Image1 = roads.

• Image2 = rivers.

• Union(Image1, Image2) = roads and rivers.

• Intersection(Image1,Image2) = places where a road crosses a river => bridge or tunnel.

Page 8: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Image Representation

• n x n matrix. (n2) space. (n2) time for rotation, scaling, union, intersection,

and so on.

• Quad tree. O(n2) space. O(n2) time for rotation, scaling, union, intersection,

and so on. For some images, the space and time could be as

little as O(1) (e.g., all white or all black images).

Page 9: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Quad Tree

• Degree 4 tree (each node has up to 4 children).

• Each node represents a portion of the image.

• Root node represents entire 2k x 2k image.

• The children of a node that represents a 2q x 2q region represent its 4 2q-1 x 2q-1 subregions.

Page 10: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Quad Tree

• Each node has one of the colors white, black, gray. White (black) => all pixels in node’s region are

white (black). Gray => at least one black and at least one white.

• White and black nodes have no children.

• Gray nodes have 4 children each.

Page 11: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Quad Tree Example

NW SW

NW

SW SE

NE

NE SE

Page 12: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Quad Tree Example

NW

SW SE

NE

Page 13: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Quad Tree Example

NW

SW SE

NE

Page 14: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Quad Tree Example

NW

SW SE

NE

Page 15: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Oct Tree

• Extension of quad tree to the representation of 3-d images.

• Degree 8 tree (each node has up to 8 children).

• The children of a node that represents a 2q x 2q x 2q region represent its 8 2q-1 x 2q-1 x 2q-1 subregions.

Page 16: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

From Matrix To Quad Tree

• 2k x 2k binary matrix.• If k = 0, return a single-node quad tree.

Root is white if pixel is 1. Root is black if pixel is 0.

Page 17: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

From Matrix To Quad Tree

• If k > 0, recursively construct quad trees for the four quadrants.

NW

SW SE

NE

Page 18: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

From Matrix To Quad Tree

• If the 4 quad tree roots are all black (white), return a single node quad tree with a black (white) root.

• Otherwise, return a quad tree with a gray root whose subtrees are the quadrant quad trees.

NW

SW SE

NE

Page 19: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Complexity

• Let t(k) be the time to construct the quad tree of a 2k x 2k binary image (matrix).

• t(0) = c, where c is some constant.

• t(k) = 4t(k–1) + d, where d is some constant and k > 1.

• t(k) = (4k) = (#pixels in matrix).

Page 20: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

From Quad Tree To Matrix

• Run divide-and-conquer algorithm for matrix to quad tree transformation backwards.

• t(k) = (4k) = (#pixels in matrix).

Page 21: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Clockwise Rotation By 90 DegreesNENW

NWSW

Page 22: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Clockwise Rotation By 90 DegreesNENW

NWSW

Page 23: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Recursive Algorithm

• If root is a leaf, return.• Rotate the children of the root.

(NW, NE, SE, SW) (SW, NW, NE, SE)

• Recursively perform the rotation in the subtrees of the root.

• Complexity is (size of quad tree). Quad tree size = # nodes.

• Quad tree size is usually substantially less than matrix size.

Page 24: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Other Rotations

• Clockwise rotations by 180 and 270 degrees are similar.

• Counterclockwise rotations by 90, 180, and 270 degrees are similar.

• Rotation by 360 degrees is null.

Page 25: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Shrinking

• k = 1.

• >= 2 white pixels in 21 x 21 window => white pixel.

NW

SW SE

NE

Page 26: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Shrinking

• k = 1.

• >= 2 white pixels in 21 x 21 window => white pixel.

NW

SW SE

NE

Page 27: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Shrinking

• k = 1.

• >= 2 white pixels in 21 x 21 window => white pixel.

NW

SW SE

NE

Page 28: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Shrinking

• k = 1.

• >= 2 white pixels in 21 x 21 window => white pixel.

NW

SW SE

NE

Page 29: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Algorithm To Shrink (k = 1)• Root represents a 1 x 1 region => return.

• Root represents a 2 x 2 region. Root is a leaf => return. Color the root white if it has >= 2 white children. Otherwise color the root black. Make root a leaf and return.

• Root represents a 2k x 2k, k > 1, region. Shrink subtrees (if any) of root. Recolor root if all subtrees now have same color.

• Complexity is (size of quad tree).

Page 30: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Union

• Rules. Do a pairwise union of corresponding pixels in

the two images. Union is white iff at least one pixel of the pair

is white.

Page 31: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Recursive Union(A,B)

• root(A) (root(B)) is white => return A (B).• root(A) (root(B)) is black => return B (A).• Both have a gray root.

Pairwise union the subtrees of A and B. If all four of the returned subtrees have a white root,

return a single node tree with a white root. Otherwise return a tree with a gray root and the four

returned subtrees as its subtrees.

• Complexity is O(min{|A|, |B|}).

A B

Page 32: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Intersection

• Rules. Do a pairwise intersection of corresponding

pixels in the two images. Intersection is white iff both pixels of the pair

are white.

Page 33: Quad Trees Region data vs. point data. Roads and rivers in a country/state.  Which rivers flow through Florida?  Which roads cross a river? Network firewalls.

Recursive Intersection(A,B)

• root(A) (root(B)) is black => return A (B).• root(A) (root(B)) is white => return B (A).• Both have a gray root.

Pairwise intersect the subtrees of A and B. If all four of the returned subtrees have a black root,

return a single node tree with a black root. Otherwise return a tree with a gray root and the four

returned subtrees as its subtrees.

• Complexity is O(min{|A|, |B|}).

A B