Topological Analysis of Patterns