Presentation is loading. Please wait.

Presentation is loading. Please wait.

Connected Components Fun with graphs, searching, and queues.

Similar presentations


Presentation on theme: "Connected Components Fun with graphs, searching, and queues."— Presentation transcript:

1 Connected Components Fun with graphs, searching, and queues

2 Getting rid of outliers part 2! So we want to get rid of outliers. Or do we? If all we’re looking for is one big object, we can disregard all the smaller bits that show up on the image.

3 So we want to find the blobs! We want to further divide the image into blobs. A blob is one connected piece of the thresholded image. We call this a connected component.

4 4-way vs. 8-way How do we decide if two pixels are connected? We can either consider diagonals connected (8-way) or disconnected (4- way).

5 How many of each? How many 4- way connected blobs are there? 8-way?

6 So, how do we use this? We can label each blob, or connected component, with a number.

7 Finding the blobs To find the blob a pixel belongs to, we need to search. We need to find the neighbors, then the neighbors’ neighbors, then the neighbors’ neighbors’ neighbors…

8 Thinking like a graph When we think of neighbors, we’re thinking of graphs. A graph is a mathematical object made with nodes and edges that connect two nodes. Nodes represent objects, edges represent relationships.

9 Graph coloring – vertex coloring “Color” the nodes in a graph such that no two adjacent nodes are the same color. This can be applied to a variety of problems!

10 Scheduling Each event is a node. Each edge connects two nodes that are scheduled at the same time. How to find a schedule with no conflicts? Color the graph!

11 Scheduling

12

13

14 What’s special about a schedule graph? There are 3 connected components in the example. Each connected component is a clique – a complete graph! Every node in a clique must be connected to every other node.

15 Sudoku A sudoku puzzle is simply a graph coloring problem! Each square is a node. Each edge connects two nodes that cannot be the same number. Color the graph in 9 colors!

16 Graphs are useful! Graph theory is at the root of the most interesting and often unsolved problems in mathematics. For example…

17 The four-color problem Divide an area into regions. Each region can be colored with maximum four colors such that no two adjacent regions are the same color. Graph coloring solves the FIVE- color problem. Four colors are slightly more difficult…

18 The Seven Bridges of Konigsberg Famous problem by Euler: Can you cross all seven bridges in Konigsberg without crossing one twice? Graphed: Eulerian cycle! Visit each edge once.

19 The traveling salesman The traveling salesman problem asks for the route that takes the shortest distance to visit every city. Translated to graphs: Hamiltonian cycle! Visit each node once. But we must find shortest such cycle! Edges in this graph now have a DISTANCE associated with it.

20 But how does that help us? Our picture can be thought of as a graph! Each pixel is a node. Adjacent pixels are connected by an edge. We need to search this graph! To do so, we need to understand a data structure.

21 Queues A queue is a data structure: it stores data! We can put data in and take it out. Queues are FIFO: First In First Out It’s like waiting in line: The person who gets in line first gets OUT of line first as well.

22 Implementing a queue Our data structure will need to do a few things: Add an element to the queue. Take an element from the queue. Calculate the size of the queue.

23 Linked lists These functions are best done using a linked list. A linked list is another example of a data structure: It stores data! Each piece of data in a linked list is connected to the piece of data after it, and maybe before.

24 Implementing a queue To add data to the queue, we append the data to the back of the linked list. To remove data from the queue, we remove the data from the front of the linked list. To calculate the size of our queue, we iterate through each piece of data in the linked list to find out how long it is.

25 Breadth First Search (BFS) We can use the queue to help us conduct a breadth first search. BFS searches the closest neighbors to the starting point first, then spreads out. A queue makes this possible.

26 Our BFS algorithm 1. Add a pixel to the queue. 2. Take a pixel from the queue and label it with a blob number. 3. Add all thresholded neighbors of the pixel to the queue. 4. Repeat steps 2-3 until no neighbors are left. 5. We have labeled a blob!

27 Finding the biggest blob We need to find ALL the blobs in our thresholded image. If our threshold is any good, the biggest one is the one we want. This lets us ignore EVERYTHING else!


Download ppt "Connected Components Fun with graphs, searching, and queues."

Similar presentations


Ads by Google