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> A:=ReadImageFile("cha.png",500);;
gap> ContractMatrix(A);
true
gap> C:=MatrixToChainComplex(A);
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> A:=ReadImageFile("bw_image.bmp",500);;
gap>  BettiNumbersOfMatrix(A);StringTime(time);
[ 3, 20 ]
" 0:00:01.223"
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> A:=ReadImageFile("digital_photo.jpg",400);;
gap> for i in [1..15] do
> Print(BettiNumbersOfMatrix(A),"\n");
> A:=ThickenedMatrix(A);;
> 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.  (Further eliminations could be made by inverting individual path-components of the picture.)
gap> A:=ReadImageFile("digital_photo.jpg",400);;
gap> for i in [1..8] do
> A:=ThickenedMatrix(A);
> od;
gap> A1:=ReadImageFile("space1.jpg",400);;
gap> A2:=ReadImageFile("space2.jpg",400);;
gap> A3:=ReadImageFile("space3.jpg",400);;
gap> A4:=ReadImageFile("space4.jpg",400);;
gap> A5:=ReadImageFile("space5.jpg",400);;

gap> BettiNumbersOfMatrix(ComplementedMatrix(A));
[ 3, 2 ]
gap> BettiNumbersOfMatrix(ComplementedMatrix(A1));
[ 3, 2 ]
gap> BettiNumbersOfMatrix(ComplementedMatrix(A2));
[ 4, 3 ]
gap> BettiNumbersOfMatrix(ComplementedMatrix(A3));
[ 4, 2 ]
gap> BettiNumbersOfMatrix(ComplementedMatrix(A4));
[ 3, 2 ]
gap> BettiNumbersOfMatrix(ComplementedMatrix(A5));
[ 4, 3 ]
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> A:=ReadImageFile("sample_from_circle.gif",400);;
gap> A:=ComplementedMatrix(A);; ##These commands should reduce noise.
gap> A:=ThickenedMatrix(A);;          ##
gap> A:=ComplementedMatrix(A);; ##
gap> for i in [1..50] do
> Print(BettiNumbersOfMatrix(A),"\n");
> A:=ThickenedMatrix(A);;
> 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 ContractMatrix(A) provides a method for finding Y.

The following commands illustrate this.
gap> A:=ReadImageFile("example.eps",400);;
gap> ViewMatrix(A); #A represents the following space X.



gap> ContractMatrix(A);;
gap> ViewMatrix(A); #The modified version of A represents the following homotopy retract Y.


The method for finding a homotopy retract Y can be used to find the boundary of a space X. (We change the homotopy type of X by puncturing each path-component; the boundary of X is almost a homotopy retract of the punctured space.) The following commands illustrate this.
gap> A:=ReadImageFile("example.eps",400);;
gap> B:=BoundaryOfMatrix(A);; #This represents the boundary of X.
gap> ViewMatrix(B);



Previous Page
Contents
Next page