Previous | About HAP: Topological Data Analysis | next
An image such as the CHA logo can be viewed as a 2-dimensional (blue) space with white holes. The following commands show that this space has two connected components (i.e. betti number b0=2) and three 1-dimensional holes (i.e. betti number b1=3).
gap> T:=ReadImageAsTopologicalSpace("cha.png",500);; Topological space of dimension 2. gap> ContractTopologicalSpace(T); gap> C:=SingularChainComplex(T); Chain complex of length 2 in characteristic 0 . gap> Homology(C,0); [ 0, 0 ] gap> Homology(C,1); [ 0, 0, 0 ]
General homology algorithms are not the most efficient way to compute betti numbers of image spaces as they take no advantage of the special features of such spaces. The function BettiNumbersOfMatrix(A) is a more efficient function. For example, this function can be used to show that the following image (borrowed from the CHOMP web pages!) has betti numbers b0=3 and b1=20.
gap> T:=ReadImageAsTopologicalSpace("bw_image.bmp",500);; gap> BettiNumbers(T,0); 3 gap> BettiNumbers(T,1); 20
The idea behind Topological Data Analysis is that one should be able to gain a qualitative understanding of difficult data from its homological properties. For example, the following commands investigate a digital photograph by calculating the betti numbers of successive thickenings of the image. The thickenings are intended to reduce the "noise" in the image and to realize the image's "true" betti numbers. Without actually viewing the photograph we can detect that there are probably three connected components and three 1-dimensional holes in it.
gap> T:=ReadImageAsTopologicalSpace("digital_photo.jpg",400);; gap> for i in [1..15] do > Print(BettiNumbers(T),"\n"); > T:=ThickenedTopologicalSpace(T);; > od; [ 206, 5070 ] [ 11, 10 ] [ 4, 4 ] [ 3, 3 ] [ 3, 3 ] [ 3, 4 ] [ 3, 3 ] [ 3, 3 ] [ 3, 3 ] [ 3, 3 ] [ 3, 3 ] [ 3, 3 ] [ 3, 3 ] [ 3, 3 ] [ 3, 3 ]
There are quite a number of different "ambient isotopy types" of black/white images with betti numbers b0=3, b1=3. A few of these are: Space 1: Space 2: Space 3: Space 4: Space 5: By considering the betti numbers of the "inverted spaces" obtained by inverting black and white, we can eliminate a few of these as possible ambient isotopy types for the digital photograph. For example, the following commands show that the photograph is not ambient isotopic to spaces 2, 3 or 5.
gap> T:=ReadImageAsTopologicalSpace("digital_photo.jpg",400);; gap> for i in [1..8] do > T:=ThickenedMatrix(T); > od; gap> T1:=ReadImageAsTopologicalSpace("space1.jpg",400);; gap> T2:=ReadImageAsTopologicalSpace("space2.jpg",400);; gap> T3:=ReadImageAsTopologicalSpace("space3.jpg",400);; gap> T4:=ReadImageAsTopologicalSpace("space4.jpg",400);; gap> T5:=ReadImageAsTopologicalSpace("space5.jpg",400);; gap> BettiNumbers(ComplementTopologicalSpace(T)); [ 3, 2 ] gap> BettiNumbers(ComplementTopologicalSpace(T1)); [ 3, 2 ] gap> BettiNumbers(ComplementTopologicalSpace(T2)); [ 4, 3 ] gap> BettiNumbers(ComplementTopologicalSpace(T3)); [ 4, 2 ] gap> BettiNumbers(ComplementTopologicalSpace(T4)); [ 3, 2 ] gap> BettiNumbers(ComplementTopologicalSpace(T5)); [ 4, 3 ]
Further distinctions can be made between Spaces 1-5 by considering individual path components. For example, the following additional commands show that Spaces 1 and 4 are not ambient isotopic.
gap> T1:=ReadImageAsTopologicalSpace("space1.jpg",400);; gap> BettiNumbers(T1,0); 3 gap> BettiNumbers(PathComponent(T1,1)); [ 1, 3 ] gap> BettiNumbers(PathComponent(T1,2)); [ 1, 0 ] gap> BettiNumbers(PathComponent(T1,3)); [ 1, 0 ] gap> T4:=ReadImageAsTopologicalSpace("space4.jpg",400);; gap> BettiNumbers(PathComponent(T4,1)); [ 1, 2 ] gap> BettiNumbers(PathComponent(T4,2)); [ 1, 1 ] gap> BettiNumbers(PathComponent(T4,3)); [ 1, 0 ]
The 2-dimensional data cloud seems to be sampled from a connected space with a 1-dimensional hole. The following computations agree with this observation.
gap> T:=ReadImageAsTopologicalSpace("sample_from_circle.gif",400);; gap> T:=ComplementTopologicalSpace(T);; ##These commands should reduce noise. gap> T:=ThickenedTopologicalSpace(T);; ## gap> T:=ComplementTopologicalSpace(T);; ## gap> for i in [1..50] do > Print(BettiNumbers(T),"\n"); > T:=ThickenedTopologicalSpace(T);; > od; [ 924, 0 ] [ 602, 29 ] [ 174, 153 ] [ 75, 181 ] [ 30, 107 ] [ 18, 44 ] [ 13, 31 ] [ 9, 18 ] [ 6, 10 ] [ 4, 5 ] [ 4, 3 ] [ 2, 3 ] [ 1, 1 ] [ 1, 1 ] [ 1, 2 ] [ 1, 1 ] [ 1, 1 ] [ 1, 1 ] [ 1, 1 ] [ 1, 1 ] [ 1, 1 ] [ 1, 1 ] [ 1, 1 ] [ 1, 1 ] [ 1, 1 ] [ 1, 1 ] [ 1, 1 ] [ 1, 1 ] [ 1, 1 ] [ 1, 1 ] [ 1, 1 ] [ 1, 1 ] [ 1, 1 ] [ 1, 1 ] [ 1, 1 ] [ 1, 1 ] [ 1, 0 ] [ 1, 0 ] [ 1, 0 ] [ 1, 0 ] [ 1, 0 ] [ 1, 0 ] [ 1, 0 ] [ 1, 0 ] [ 1, 0 ] [ 1, 0 ] [ 1, 0 ] [ 1, 0 ] [ 1, 0 ] [ 1, 0 ]
One approach to calculating the homology of a space X is to simplify the calculation by finding a smaller homotopy equivalent subspace Y and then to calculate the homology of Y. The command ContractTopologicalSpace(X) provides a method for finding Y. The following commands illustrate this.
gap> T:=ReadImageAsTopologicalSpace("example.eps",400);; gap> ViewTopologicalSpace(T); #T is the following space. gap> ContractTopologicalSpace(T);; gap> ViewTopologicalSpace(T); #Now T is reduced to the following homotopy.
The following commands find the boundary of the space T.
gap> T:=ReadImageAsTopologicalSpace("example.eps",400);; gap> B:=BoundaryTopologicalSpace(T);; gap> ViewTopologicalSpace(B);
A "feature" of a shape could be defined as a singularity in the boundary of the shape (i.e. a point where the boundary is not differentiable). According to this definition the following shapes have respectively 6, 10 and 0 features. The number of features of each of these shapes can be computed using the following commands.
gap> T:=ReadImageAsTopologicalSpace("shape1.jpg",400);; gap> S:=BoundarySingularities(T);; gap> BettiNumbers(S,0); 6 gap> T:=ReadImageAsTopologicalSpace("shape2.jpg",400);; gap> S:=BoundarySingularities(T);; gap> BettiNumbers(S,0); 10 gap> T:=ReadImageAsTopologicalSpace("shape3.jpg",400);; gap> S:=BoundarySingularities(T);; gap> BettiNumbers(S,0); 0
The hope is that Topological Data Analysis can be used to analyze images such as the following Computed Tomography scan. Increasing the threshold in steps of 10, and computing the betti numbers each time, produces the following results.
gap> for n in [1..70] do > T:=ReadImageAsTopologicalSpace("ctprostate.jpg",n*10);; > Print(BettiNumbers(T),"\n"); > od; [ 1, 0 ] [ 1, 2 ] [ 7, 0 ] [ 5, 0 ] [ 10, 0 ] [ 9, 1 ] [ 21, 1 ] [ 122, 0 ] [ 835, 7 ] [ 136, 383 ] [ 110, 169 ] [ 20, 95 ] [ 6, 20 ] [ 5, 2 ] [ 5, 1 ] [ 6, 0 ] [ 5, 0 ] [ 6, 1 ] [ 6, 0 ] [ 5, 1 ] [ 5, 6 ] [ 4, 5 ] [ 4, 11 ] [ 5, 7 ] [ 4, 3 ] [ 5, 3 ] [ 6, 3 ] [ 5, 5 ] [ 2, 8 ] [ 3, 10 ] [ 4, 23 ] [ 5, 60 ] [ 5, 102 ] [ 18, 117 ] [ 193, 129 ] [ 419, 115 ] [ 111, 342 ] [ 95, 207 ] [ 114, 201 ] [ 270, 208 ] [ 169, 306 ] [ 35, 558 ] [ 30, 134 ] [ 38, 82 ] [ 23, 44 ] [ 11, 32 ] [ 16, 22 ] [ 10, 20 ] [ 6, 16 ] [ 7, 13 ] [ 5, 17 ] [ 4, 14 ] [ 3, 23 ] [ 2, 25 ] [ 2, 21 ] [ 2, 17 ] [ 4, 16 ] [ 1, 18 ] [ 1, 20 ] [ 1, 26 ] [ 1, 25 ] [ 1, 26 ] [ 1, 23 ] [ 1, 21 ] [ 1, 22 ] [ 1, 25 ] [ 1, 25 ] [ 1, 23 ] [ 1, 23 ] [ 1, 26 ]
The above suggests that the CT image is interesting in the threshold range [340,390]. We can view it using this threshold.
gap> T:=ReadImageAsTopologicalSpace(A,[340,390]);; gap> ViewTopologicalSpace(BoundaryTopologicalSpace(T));
Previous Page | Contents | Next page